|
| 1 | +Fundamentals |
| 2 | +============ |
| 3 | + |
| 4 | +.. currentmodule:: polygon |
| 5 | + |
| 6 | +The Fundamentals API provides access to comprehensive financial data for public companies through 6 specialized endpoints. This modern API replaces the deprecated ``VXClient`` with focused, high-performance endpoints for specific data types. |
| 7 | + |
| 8 | +.. note:: |
| 9 | + **🚨 Migration Notice**: The old ``client.vx.list_stock_financials()`` method is deprecated. |
| 10 | + Use the new dedicated endpoints listed below for better performance and cleaner data access. |
| 11 | + |
| 12 | +Quick Start |
| 13 | +----------- |
| 14 | + |
| 15 | +.. code-block:: python |
| 16 | +
|
| 17 | + from polygon import RESTClient |
| 18 | + |
| 19 | + client = RESTClient(api_key="your_api_key") |
| 20 | + |
| 21 | + # Get balance sheets - clean and direct! |
| 22 | + balance_sheets = client.list_balance_sheets(tickers="AAPL", timeframe="quarterly", limit=5) |
| 23 | + for sheet in balance_sheets: |
| 24 | + print(f"Period: {sheet.period_end}, Assets: ${sheet.total_assets:,.0f}") |
| 25 | +
|
| 26 | +Available Endpoints |
| 27 | +------------------- |
| 28 | + |
| 29 | +The fundamentals API consists of 6 specialized endpoints: |
| 30 | + |
| 31 | +1. **Balance Sheets** - :meth:`RESTClient.list_balance_sheets` |
| 32 | +2. **Cash Flow Statements** - :meth:`RESTClient.list_cash_flow_statements` |
| 33 | +3. **Income Statements** - :meth:`RESTClient.list_income_statements` |
| 34 | +4. **Financial Ratios** - :meth:`RESTClient.list_financial_ratios` |
| 35 | +5. **Short Interest** - :meth:`RESTClient.list_short_interest` |
| 36 | +6. **Short Volume** - :meth:`RESTClient.list_short_volume` |
| 37 | + |
| 38 | +Balance Sheets |
| 39 | +-------------- |
| 40 | + |
| 41 | +.. automethod:: RESTClient.list_balance_sheets |
| 42 | + |
| 43 | +**Example:** |
| 44 | + |
| 45 | +.. code-block:: python |
| 46 | +
|
| 47 | + # Get quarterly balance sheets for Apple from 2023 onwards |
| 48 | + balance_sheets = client.list_balance_sheets( |
| 49 | + tickers="AAPL", |
| 50 | + timeframe="quarterly", |
| 51 | + period_end_gte="2023-01-01", |
| 52 | + limit=8 |
| 53 | + ) |
| 54 | + |
| 55 | + for sheet in balance_sheets: |
| 56 | + print(f"Q{sheet.fiscal_quarter} {sheet.fiscal_year}: ${sheet.total_assets:,.0f} total assets") |
| 57 | +
|
| 58 | +Cash Flow Statements |
| 59 | +-------------------- |
| 60 | + |
| 61 | +.. automethod:: RESTClient.list_cash_flow_statements |
| 62 | + |
| 63 | +**Example:** |
| 64 | + |
| 65 | +.. code-block:: python |
| 66 | +
|
| 67 | + # Get annual cash flow statements for multiple companies |
| 68 | + cash_flows = client.list_cash_flow_statements( |
| 69 | + tickers_any_of="AAPL,GOOGL,MSFT", |
| 70 | + timeframe="annual", |
| 71 | + limit=10 |
| 72 | + ) |
| 73 | + |
| 74 | + for cf in cash_flows: |
| 75 | + if cf.net_cash_flow_from_operating_activities: |
| 76 | + print(f"{cf.tickers[0]} {cf.fiscal_year}: Operating CF = ${cf.net_cash_flow_from_operating_activities:,.0f}") |
| 77 | +
|
| 78 | +Income Statements |
| 79 | +----------------- |
| 80 | + |
| 81 | +.. automethod:: RESTClient.list_income_statements |
| 82 | + |
| 83 | +**Example:** |
| 84 | + |
| 85 | +.. code-block:: python |
| 86 | +
|
| 87 | + # Get income statements with revenue filtering |
| 88 | + income_statements = client.list_income_statements( |
| 89 | + tickers="TSLA", |
| 90 | + timeframe="quarterly", |
| 91 | + revenues_gt=10000000000, # Revenue > $10B |
| 92 | + limit=5 |
| 93 | + ) |
| 94 | + |
| 95 | + for stmt in income_statements: |
| 96 | + print(f"Q{stmt.fiscal_quarter} {stmt.fiscal_year}: Revenue ${stmt.revenues:,.0f}, Net Income ${stmt.net_income_loss:,.0f}") |
| 97 | +
|
| 98 | +Financial Ratios |
| 99 | +---------------- |
| 100 | + |
| 101 | +.. automethod:: RESTClient.list_financial_ratios |
| 102 | + |
| 103 | +**Example:** |
| 104 | + |
| 105 | +.. code-block:: python |
| 106 | +
|
| 107 | + # Find stocks with low P/E ratios and high market cap |
| 108 | + ratios = client.list_financial_ratios( |
| 109 | + price_to_earnings_lt=15, # P/E < 15 |
| 110 | + market_cap_gt=50000000000, # Market cap > $50B |
| 111 | + limit=20 |
| 112 | + ) |
| 113 | + |
| 114 | + for ratio in ratios: |
| 115 | + print(f"{ratio.ticker}: P/E = {ratio.price_to_earnings:.2f}, Market Cap = ${ratio.market_cap:,.0f}") |
| 116 | +
|
| 117 | +Short Interest |
| 118 | +-------------- |
| 119 | + |
| 120 | +.. automethod:: RESTClient.list_short_interest |
| 121 | + |
| 122 | +**Example:** |
| 123 | + |
| 124 | +.. code-block:: python |
| 125 | +
|
| 126 | + # Get short interest data with high days-to-cover |
| 127 | + short_interest = client.list_short_interest( |
| 128 | + ticker_any_of="GME,AMC,BBBY", |
| 129 | + days_to_cover_gt=5, # High short squeeze potential |
| 130 | + limit=10 |
| 131 | + ) |
| 132 | + |
| 133 | + for si in short_interest: |
| 134 | + print(f"{si.ticker} ({si.settlement_date}): {si.short_interest:,} shares, {si.days_to_cover:.1f} days to cover") |
| 135 | +
|
| 136 | +Short Volume |
| 137 | +------------ |
| 138 | + |
| 139 | +.. automethod:: RESTClient.list_short_volume |
| 140 | + |
| 141 | +**Example:** |
| 142 | + |
| 143 | +.. code-block:: python |
| 144 | +
|
| 145 | + # Analyze recent short volume patterns |
| 146 | + from datetime import date, timedelta |
| 147 | + |
| 148 | + recent_date = date.today() - timedelta(days=7) |
| 149 | + short_volume = client.list_short_volume( |
| 150 | + ticker="AAPL", |
| 151 | + date_gte=recent_date, |
| 152 | + short_volume_ratio_gt=0.4, # High short ratio |
| 153 | + limit=10 |
| 154 | + ) |
| 155 | + |
| 156 | + for sv in short_volume: |
| 157 | + print(f"{sv.date}: {sv.short_volume_ratio:.1%} short ratio ({sv.short_volume:,} of {sv.total_volume:,} shares)") |
| 158 | +
|
| 159 | +Filter Modifiers |
| 160 | +---------------- |
| 161 | + |
| 162 | +All fundamentals endpoints support advanced filtering with these modifiers: |
| 163 | + |
| 164 | +* ``.gt`` - Greater than |
| 165 | +* ``.gte`` - Greater than or equal to |
| 166 | +* ``.lt`` - Less than |
| 167 | +* ``.lte`` - Less than or equal to |
| 168 | +* ``.any_of`` - Equals any of (comma-separated values) |
| 169 | +* ``.all_of`` - Contains all of (comma-separated values, for arrays) |
| 170 | + |
| 171 | +**Examples:** |
| 172 | + |
| 173 | +.. code-block:: python |
| 174 | +
|
| 175 | + # Multiple filter examples |
| 176 | + |
| 177 | + # Date range filtering |
| 178 | + balance_sheets = client.list_balance_sheets( |
| 179 | + tickers="AAPL", |
| 180 | + period_end_gte="2023-01-01", |
| 181 | + period_end_lt="2024-01-01" |
| 182 | + ) |
| 183 | + |
| 184 | + # Multiple tickers with any_of |
| 185 | + ratios = client.list_financial_ratios( |
| 186 | + ticker_any_of="AAPL,GOOGL,MSFT,AMZN,TSLA" |
| 187 | + ) |
| 188 | + |
| 189 | + # Numeric range filtering |
| 190 | + high_growth = client.list_income_statements( |
| 191 | + revenues_gt=1000000000, # Revenue > $1B |
| 192 | + fiscal_year_gte=2022 # 2022 onwards |
| 193 | + ) |
| 194 | +
|
| 195 | +Migration from VXClient |
| 196 | +----------------------- |
| 197 | + |
| 198 | +If you're migrating from the old ``VXClient``, here's the mapping: |
| 199 | + |
| 200 | +.. list-table:: Migration Guide |
| 201 | + :widths: 50 50 |
| 202 | + :header-rows: 1 |
| 203 | + |
| 204 | + * - Old (Deprecated) |
| 205 | + - New (Recommended) |
| 206 | + * - ``client.vx.list_stock_financials()`` |
| 207 | + - Use 6 specific methods based on data needed |
| 208 | + * - Single complex endpoint |
| 209 | + - Dedicated optimized endpoints |
| 210 | + * - Mixed data types in response |
| 211 | + - Clean, focused response models |
| 212 | + |
| 213 | +**Before (Deprecated):** |
| 214 | + |
| 215 | +.. code-block:: python |
| 216 | +
|
| 217 | + # OLD - Shows deprecation warnings |
| 218 | + financials = client.vx.list_stock_financials(ticker="AAPL") |
| 219 | +
|
| 220 | +**After (Modern):** |
| 221 | + |
| 222 | +.. code-block:: python |
| 223 | +
|
| 224 | + # NEW - Clean, fast, and focused |
| 225 | + balance_sheets = client.list_balance_sheets(tickers="AAPL") |
| 226 | + income_statements = client.list_income_statements(tickers="AAPL") |
| 227 | + ratios = client.list_financial_ratios(ticker="AAPL") |
| 228 | +
|
| 229 | +Benefits of New API |
| 230 | +------------------- |
| 231 | + |
| 232 | +✅ **Performance**: Smaller, focused responses load faster |
| 233 | + |
| 234 | +✅ **Clarity**: Each endpoint returns exactly what you need |
| 235 | + |
| 236 | +✅ **Features**: Better filtering, TTM data support, cleaner models |
| 237 | + |
| 238 | +✅ **Type Safety**: Better IDE support and error catching |
| 239 | + |
| 240 | +✅ **Maintenance**: Easier to extend and maintain |
| 241 | + |
| 242 | +✅ **Documentation**: Comprehensive parameter documentation |
| 243 | + |
| 244 | +Error Handling |
| 245 | +-------------- |
| 246 | + |
| 247 | +All fundamentals methods use the same error handling patterns as other REST client methods: |
| 248 | + |
| 249 | +.. code-block:: python |
| 250 | +
|
| 251 | + try: |
| 252 | + balance_sheets = client.list_balance_sheets(tickers="INVALID") |
| 253 | + for sheet in balance_sheets: |
| 254 | + print(sheet) |
| 255 | + except Exception as e: |
| 256 | + print(f"Error: {e}") |
| 257 | +
|
| 258 | +For more examples, see the `examples/rest/fundamentals_example.py <https://github.com/polygon-io/client-python/blob/master/examples/rest/fundamentals_example.py>`_ file. |
0 commit comments