|
1688 | 1688 | ], |
1689 | 1689 | "source": [ |
1690 | 1690 | "rv_columns = [\n", |
1691 | | - " 'Ticker', \n", |
1692 | | - " 'Price', \n", |
1693 | | - " 'Number of Shares to Buy', \n", |
1694 | | - " 'Price-to-Earnings Ratio',\n", |
1695 | | - " 'PE Percentile',\n", |
1696 | | - " 'Price-to-Book Ratio',\n", |
1697 | | - " 'PB Percentile',\n", |
1698 | | - " 'EV/EBITDA',\n", |
1699 | | - " 'EV/EBITDA Percentile',\n", |
1700 | | - " 'EV/GP',\n", |
1701 | | - " 'EV/GP Percentile',\n", |
1702 | | - " 'RV Score'\n", |
1703 | | - " ]\n", |
| 1691 | + " 'Ticker',\n", |
| 1692 | + " 'Price',\n", |
| 1693 | + " 'Number of Shares to Buy', \n", |
| 1694 | + " 'Price-to-Earnings Ratio',\n", |
| 1695 | + " 'PE Percentile',\n", |
| 1696 | + " 'Price-to-Book Ratio',\n", |
| 1697 | + " 'PB Percentile',\n", |
| 1698 | + " 'Price-to-Sales Ratio',\n", |
| 1699 | + " 'PS Percentile',\n", |
| 1700 | + " 'EV/EBITDA',\n", |
| 1701 | + " 'EV/EBITDA Percentile',\n", |
| 1702 | + " 'EV/GP',\n", |
| 1703 | + " 'EV/GP Percentile',\n", |
| 1704 | + " 'RV Score'\n", |
| 1705 | + "]\n", |
1704 | 1706 | "\n", |
1705 | 1707 | "rv_dataframe = pd.DataFrame(columns = rv_columns)\n", |
1706 | 1708 | "\n", |
1707 | 1709 | "for symbol_string in symbol_strings:\n", |
1708 | | - "# print(symbol_strings)\n", |
1709 | | - " batch_api_call_url = f'https://sandbox.iexapis.com/stable/stock/market/batch/?types=advanced-stats,quote&symbols={symbol_string}&token={IEX_CLOUD_API_TOKEN}'\n", |
| 1710 | + " batch_api_call_url = f'https://sandbox.iexapis.com/stable/stock/market/batch?symbols={symbol_string}&types=quote,advanced-stats&token={IEX_CLOUD_API_TOKEN}'\n", |
1710 | 1711 | " data = requests.get(batch_api_call_url).json()\n", |
1711 | 1712 | " for symbol in symbol_string.split(','):\n", |
1712 | | - " \n", |
1713 | | - " pe_ratio = data[symbol]['quote']['peRatio']\n", |
1714 | | - " pb_ratio = data[symbol]['advanced-stats']['priceToBook']\n", |
1715 | | - " ps_ratio = data[symbol]['advanced-stats']['priceToSales']\n", |
1716 | | - " \n", |
1717 | 1713 | " enterprise_value = data[symbol]['advanced-stats']['enterpriseValue']\n", |
1718 | 1714 | " ebitda = data[symbol]['advanced-stats']['EBITDA']\n", |
1719 | 1715 | " gross_profit = data[symbol]['advanced-stats']['grossProfit']\n", |
|
1722 | 1718 | " ev_to_ebitda = enterprise_value/ebitda\n", |
1723 | 1719 | " except TypeError:\n", |
1724 | 1720 | " ev_to_ebitda = np.NaN\n", |
1725 | | - " \n", |
| 1721 | + " \n", |
1726 | 1722 | " try:\n", |
1727 | 1723 | " ev_to_gross_profit = enterprise_value/gross_profit\n", |
1728 | 1724 | " except TypeError:\n", |
1729 | 1725 | " ev_to_gross_profit = np.NaN\n", |
1730 | 1726 | " \n", |
1731 | 1727 | " rv_dataframe = rv_dataframe.append(\n", |
1732 | | - " pd.Series([\n", |
1733 | | - " symbol, \n", |
1734 | | - " data[symbol]['quote']['latestPrice'], \n", |
1735 | | - " 'N/A', \n", |
1736 | | - " pe_ratio,\n", |
1737 | | - " 'N/A',\n", |
1738 | | - " pb_ratio,\n", |
1739 | | - " 'N/A',\n", |
1740 | | - " ev_to_ebitda,\n", |
1741 | | - " 'N/A',\n", |
1742 | | - " ev_to_gross_profit,\n", |
1743 | | - " 'N/A',\n", |
1744 | | - " 'N/A'\n", |
1745 | | - " ], \n", |
1746 | | - " index = rv_columns), \n", |
1747 | | - " ignore_index = True)\n", |
1748 | | - " \n", |
1749 | | - "\n", |
1750 | | - "rv_dataframe" |
1751 | | - ] |
1752 | | - }, |
1753 | | - { |
1754 | | - "cell_type": "code", |
1755 | | - "execution_count": 13, |
1756 | | - "metadata": {}, |
1757 | | - "outputs": [ |
1758 | | - { |
1759 | | - "name": "stdout", |
1760 | | - "output_type": "stream", |
1761 | | - "text": [ |
1762 | | - "{'week52change': 0.290414, 'week52high': 169.51, 'week52low': 90.41, 'marketcap': 75861250162, 'employees': 10724, 'day200MovingAvg': 134.17, 'day50MovingAvg': 148.64, 'float': 479955020, 'avg10Volume': 1641586.3, 'avg30Volume': 1479579.2, 'ttmEPS': 3.499, 'ttmDividendRate': 0.77, 'companyName': 'Zoetis, Inc.', 'sharesOutstanding': 494883276, 'maxChangePercent': 3.3525, 'year5ChangePercent': 1.69, 'year2ChangePercent': 0.608, 'year1ChangePercent': 0.281583, 'ytdChangePercent': 0.189876, 'month6ChangePercent': 0.10241, 'month3ChangePercent': 0.297048, 'month1ChangePercent': 0.159224, 'day30ChangePercent': 0.165634, 'day5ChangePercent': -0.012817, 'nextDividendDate': None, 'dividendYield': 0.00489706569361443, 'nextEarningsDate': '2020-10-13', 'exDividendDate': '2020-07-01', 'peRatio': 49.1, 'beta': 0.9584403132945124, 'totalCash': 1974321215, 'currentDebt': 549171552, 'revenue': 6518431250, 'grossProfit': 4133660573, 'totalRevenue': 6300683466, 'EBITDA': 2502772553, 'revenuePerShare': 13.28, 'revenuePerEmployee': 618960.04, 'debtToEquity': 2.45, 'profitMargin': 0.2407740535828538, 'enterpriseValue': 81297632588, 'enterpriseValueToRevenue': 13.46, 'priceToSales': 12.6, 'priceToBook': 29.222282216073907, 'forwardPERatio': 46.68, 'pegRatio': -42.88, 'peHigh': 46.10321684721315, 'peLow': 25.052455887152025, 'week52highDate': '2020-07-31', 'week52lowDate': '2020-03-22', 'putCallRatio': 1.5877629858076678}\n" |
1763 | | - ] |
1764 | | - } |
1765 | | - ], |
1766 | | - "source": [ |
1767 | | - "print(data[symbol]['advanced-stats'])" |
| 1728 | + " pd.Series([\n", |
| 1729 | + " symbol,\n", |
| 1730 | + " data[symbol]['quote']['latestPrice'],\n", |
| 1731 | + " 'N/A',\n", |
| 1732 | + " data[symbol]['quote']['peRatio'],\n", |
| 1733 | + " 'N/A',\n", |
| 1734 | + " data[symbol]['advanced-stats']['priceToBook'],\n", |
| 1735 | + " 'N/A',\n", |
| 1736 | + " data[symbol]['advanced-stats']['priceToSales'],\n", |
| 1737 | + " 'N/A',\n", |
| 1738 | + " ev_to_ebitda,\n", |
| 1739 | + " 'N/A',\n", |
| 1740 | + " ev_to_gross_profit,\n", |
| 1741 | + " 'N/A',\n", |
| 1742 | + " 'N/A'\n", |
| 1743 | + " ],\n", |
| 1744 | + " index = rv_columns),\n", |
| 1745 | + " ignore_index = True\n", |
| 1746 | + " )" |
1768 | 1747 | ] |
1769 | 1748 | }, |
1770 | 1749 | { |
|
2852 | 2831 | "metadata": {}, |
2853 | 2832 | "outputs": [], |
2854 | 2833 | "source": [ |
2855 | | - "for column in ['Price-to-Earnings Ratio', 'EV/EBITDA', 'EV/GP']:\n", |
| 2834 | + "for column in ['Price-to-Earnings Ratio', 'Price-to-Book Ratio','Price-to-Sales Ratio', 'EV/EBITDA','EV/GP']:\n", |
2856 | 2835 | " rv_dataframe[column].fillna(rv_dataframe[column].mean(), inplace = True)" |
2857 | 2836 | ] |
2858 | 2837 | }, |
|
3257 | 3236 | "metrics = {\n", |
3258 | 3237 | " 'Price-to-Earnings Ratio': 'PE Percentile',\n", |
3259 | 3238 | " 'Price-to-Book Ratio':'PB Percentile',\n", |
| 3239 | + " 'Price-to-Sales Ratio': 'PS Percentile',\n", |
3260 | 3240 | " 'EV/EBITDA':'EV/EBITDA Percentile',\n", |
3261 | 3241 | " 'EV/GP':'EV/GP Percentile'\n", |
3262 | 3242 | "}\n", |
|
3572 | 3552 | "outputs": [], |
3573 | 3553 | "source": [ |
3574 | 3554 | "rv_dataframe.sort_values(by = 'RV Score', inplace = True)\n", |
3575 | | - "rv_dataframe = rv_dataframe[:51]\n", |
| 3555 | + "rv_dataframe = rv_dataframe[:50]\n", |
3576 | 3556 | "rv_dataframe.reset_index(drop = True, inplace = True)" |
3577 | 3557 | ] |
3578 | 3558 | }, |
|
4681 | 4661 | "metadata": {}, |
4682 | 4662 | "outputs": [], |
4683 | 4663 | "source": [ |
4684 | | - "column_formats = { \n", |
4685 | | - " 'A' : ['Ticker', string_template],\n", |
4686 | | - " 'B' : ['Price', dollar_template],\n", |
4687 | | - " 'C' : ['Number of Shares to Buy', integer_template],\n", |
4688 | | - " 'D' : ['Price-to-Earnings Ratio', float_template],\n", |
4689 | | - " 'E' : ['PE Percentile', percent_template],\n", |
4690 | | - " 'F' : ['Price-to-Book Ratio', float_template],\n", |
4691 | | - " 'G' : ['PB Percentile', percent_template],\n", |
4692 | | - " 'H' : ['EV/EBITDA', float_template],\n", |
4693 | | - " 'I' : ['EV/EBITDA Percentile', percent_template],\n", |
4694 | | - " 'J' : ['EV/GP', float_template],\n", |
4695 | | - " 'K' : ['EV/GP Percentile', percent_template],\n", |
4696 | | - " 'L' : ['RV Score', percent_template]\n", |
4697 | | - " }\n", |
| 4664 | + "column_formats = {\n", |
| 4665 | + " 'A': ['Ticker', string_template],\n", |
| 4666 | + " 'B': ['Price', dollar_template],\n", |
| 4667 | + " 'C': ['Number of Shares to Buy', integer_template],\n", |
| 4668 | + " 'D': ['Price-to-Earnings Ratio', float_template],\n", |
| 4669 | + " 'E': ['PE Percentile', percent_template],\n", |
| 4670 | + " 'F': ['Price-to-Book Ratio', float_template],\n", |
| 4671 | + " 'G': ['PB Percentile',percent_template],\n", |
| 4672 | + " 'H': ['Price-to-Sales Ratio', float_template],\n", |
| 4673 | + " 'I': ['PS Percentile', percent_template],\n", |
| 4674 | + " 'J': ['EV/EBITDA', float_template],\n", |
| 4675 | + " 'K': ['EV/EBITDA Percentile', percent_template],\n", |
| 4676 | + " 'L': ['EV/GP', float_template],\n", |
| 4677 | + " 'M': ['EV/GP Percentile', percent_template],\n", |
| 4678 | + " 'N': ['RV Score', percent_template]\n", |
| 4679 | + " }\n", |
4698 | 4680 | "\n", |
4699 | 4681 | "for column in column_formats.keys():\n", |
4700 | | - " writer.sheets['Value Strategy'].set_column(f'{column}:{column}', 20, column_formats[column][1])\n", |
4701 | | - " writer.sheets['Value Strategy'].write(f'{column}1', column_formats[column][0], string_template)" |
| 4682 | + " writer.sheets['Value Strategy'].set_column(f'{column}:{column}', 25, column_formats[column][1])\n", |
| 4683 | + " writer.sheets['Value Strategy'].write(f'{column}1', column_formats[column][0], column_formats[column][1])" |
4702 | 4684 | ] |
4703 | 4685 | }, |
4704 | 4686 | { |
|
0 commit comments