Enhanced DataFrame with financial data integration capabilities. Extends the pandas DataFrame with additional functionality for financial analysis, particularly for connecting with the Finance Toolkit using tickers obtained from the Finance Database.
| 168 | |
| 169 | |
| 170 | class FinanceFrame(pd.DataFrame): |
| 171 | """ |
| 172 | Enhanced DataFrame with financial data integration capabilities. |
| 173 | |
| 174 | Extends the pandas DataFrame with additional functionality for |
| 175 | financial analysis, particularly for connecting with the Finance |
| 176 | Toolkit using tickers obtained from the Finance Database. |
| 177 | """ |
| 178 | |
| 179 | def to_toolkit( |
| 180 | self, |
| 181 | api_key: str | None = None, |
| 182 | start_date: str | None = None, |
| 183 | end_date: str | None = None, |
| 184 | quarterly: bool = False, |
| 185 | use_cached_data: bool | str = False, |
| 186 | risk_free_rate: str = "10y", |
| 187 | benchmark_ticker: str | None = "SPY", |
| 188 | enforce_source: str | None = None, |
| 189 | convert_currency: bool | None = None, |
| 190 | intraday_period: str | None = None, |
| 191 | rounding: int | None = 4, |
| 192 | remove_invalid_tickers: bool = False, |
| 193 | sleep_timer: bool | None = None, |
| 194 | progress_bar: bool = True, |
| 195 | ): |
| 196 | """ |
| 197 | Convert the FinanceFrame to a Finance Toolkit object. |
| 198 | |
| 199 | Creates a Finance Toolkit object using the tickers in this DataFrame, |
| 200 | providing access to fundamental and historical data, ratios, metrics, |
| 201 | models, and technical indicators. |
| 202 | |
| 203 | Args: |
| 204 | api_key: API key from FinancialModelingPrep. |
| 205 | Obtain one at: https://www.jeroenbouma.com/fmp |
| 206 | start_date: Start date for data collection (YYYY-MM-DD). |
| 207 | Defaults to 10 years before current date. |
| 208 | end_date: End date for data collection (YYYY-MM-DD). |
| 209 | Defaults to current date. |
| 210 | quarterly: Whether to collect quarterly financial statements. |
| 211 | Defaults to False (yearly statements). |
| 212 | use_cached_data: Whether to use previously cached data. |
| 213 | Can be a boolean or a string path. Defaults to False. |
| 214 | risk_free_rate: Risk-free rate to use (13w, 5y, 10y, 30y). |
| 215 | Based on US Treasury Yields. Defaults to "10y". |
| 216 | benchmark_ticker: Ticker for benchmark comparisons. |
| 217 | Defaults to "SPY" (S&P 500). |
| 218 | historical_source: Source for historical data ("FinancialModelingPrep" |
| 219 | or "YahooFinance"). Defaults to FinancialModelingPrep. |
| 220 | convert_currency: Whether to convert financial statement currencies |
| 221 | to match historical data. Defaults to None (auto-determined). |
| 222 | intraday_period: Time period for intraday data (1min, 5min, 15min, |
| 223 | 30min, 1hour). Defaults to None. |
| 224 | rounding: Number of decimal places for results. Defaults to 4. |
| 225 | remove_invalid_tickers: Whether to remove invalid tickers. |
| 226 | Defaults to False. |
| 227 | sleep_timer: Whether to use a sleep timer when rate limit is reached. |