### Install documentation dependencies Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/documentation.md Installs the necessary Python packages for building the documentation. ```bash pip install -r requirements.txt pip install Sphinx==8.0.2 pydata-sphinx-theme==0.15.4 Jinja2==3.1.4 sphinx-copybutton==0.5.2 ``` -------------------------------- ### Serve documentation locally Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/documentation.md Starts a local web server to preview the generated HTML documentation. ```bash python -m http.server -d ./doc/_build/html ``` -------------------------------- ### Install yfinance from a specific branch Source: https://github.com/ranaroussi/yfinance/blob/main/CONTRIBUTING.md Use pip to install the library directly from the development branch on GitHub. ```bash pip install "git+https://github.com/ranaroussi/yfinance.git@dev" # <- dev branch ``` -------------------------------- ### Install yfinance Source: https://github.com/ranaroussi/yfinance/blob/main/README.md Install the yfinance library from PYPI using pip. This is the standard method for adding the package to your Python environment. ```bash $ pip install yfinance ``` -------------------------------- ### Install yfinance from a Git branch using PIP Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/running.md Use this command to install yfinance directly from a GitHub repository branch. Replace {user}/{repo} and {branch} with your specific details. ```bash pip install git+https://github.com/{user}/{repo}.git@{branch} ``` ```bash pip install git+https://github.com/ranaroussi/yfinance.git@feature/name ``` -------------------------------- ### Use Proxy Server for Data Downloads Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.ticker_tickers.md Provides examples of how to specify a proxy server when initializing a Ticker object or calling its methods to download data. ```python import yfinance as yf msft = yf.Ticker("MSFT") msft.history(..., proxy="PROXY_SERVER") msft.get_actions(proxy="PROXY_SERVER") msft.get_dividends(proxy="PROXY_SERVER") msft.get_splits(proxy="PROXY_SERVER") msft.get_capital_gains(proxy="PROXY_SERVER") msft.get_balance_sheet(proxy="PROXY_SERVER") msft.get_cashflow(proxy="PROXY_SERVER") msft.option_chain(..., proxy="PROXY_SERVER") ... ``` -------------------------------- ### Initialize Market Object and Access Data Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.market.md Instantiate a Market object for a specific region (e.g., EUROPE) and access its status and summary attributes. Ensure yfinance is installed and imported. ```python import yfinance as yf EUROPE = yf.Market("EUROPE") status = EUROPE.status summary = EUROPE.summary ``` -------------------------------- ### Add yfinance download location to Python path Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/running.md If installing yfinance from a local Git clone for a specific project, add the download location to your Python path. This ensures Python can find the installed module. ```python import sys sys.path.insert(0, “path/to/downloaded/yfinance”) ``` -------------------------------- ### Fix Dividend Data Too Small Source: https://github.com/ranaroussi/yfinance/wiki/Price-repair Presents an example where dividend values are extremely small, showing the original data and a corrected version with more typical values. ```text # ORIGINAL: Close Adj Close Adj Dividends 2022-02-03 00:00:00+00:00 0.7534 0.675197 0.8962 0.00001 2022-02-01 00:00:00+00:00 0.7844 0.702970 0.8962 0.00000 ``` ```text # REPAIRED: Close Adj Close Adj Dividends 2022-02-03 00:00:00+00:00 0.7534 0.675197 0.8962 0.001 2022-02-01 00:00:00+00:00 0.7844 0.702075 0.8950 0.000 ``` -------------------------------- ### Initialize Sector and Industry Objects Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.sector_industry.md Demonstrates how to instantiate Sector and Industry objects using specific keys and access their respective properties. ```python import yfinance as yf tech = yf.Sector('technology') software = yf.Industry('software-infrastructure') # Common information tech.key tech.name tech.symbol tech.ticker tech.overview tech.top_companies tech.research_reports # Sector information tech.top_etfs tech.top_mutual_funds tech.industries # Industry information software.sector_key software.sector_name software.top_performing_companies software.top_growth_companies ``` -------------------------------- ### Build documentation with Sphinx Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/documentation.md Generates the HTML documentation files from the source directory. ```bash sphinx-build -b html doc/source doc/_build/html ``` -------------------------------- ### Clone repository Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/code.md Initial step to obtain a local copy of the forked repository. ```bash git clone https://github.com/{user}/{repo}.git ``` -------------------------------- ### Run All Price Tests Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/testing.md Execute all unit tests located within the `tests.test_prices` module. Ensure you are in the project's root directory. ```bash python -m unittest tests.test_prices ``` -------------------------------- ### General Unit Test Command Structure Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/testing.md A general template for running unittest, allowing specification of the test file, class, and method. Replace placeholders with actual names. ```bash python -m unittest tests.{file}.{class}.{method} ``` -------------------------------- ### Accessing and Querying Financial Calendars Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.calendars.md Demonstrates initializing the Calendars class, accessing event properties, and performing manual queries with custom filters. ```python import yfinance as yf from datetime import datetime, timedelta # Default init (today + 7 days) calendar = yf.Calendars() # Today's events: calendar of 1 day tomorrow = datetime.now() + timedelta(days=1) calendar = yf.Calendars(end=tomorrow) # Default calendar queries - accessing the properties will fetch the data from YF calendar.earnings_calendar calendar.ipo_info_calendar calendar.splits_calendar calendar.economic_events_calendar # Manual queries calendar.get_earnings_calendar() calendar.get_ipo_info_calendar() calendar.get_splits_calendar() calendar.get_economic_events_calendar() # Earnings calendar custom filters calendar.get_earnings_calendar( market_cap=100_000_000, # filter out small-cap filter_most_active=True, # show only actively traded. Uses: `screen(query="MOST_ACTIVES")` ) # Example of real use case: # Get inminent unreported earnings events today = datetime.now() is_friday = today.weekday() == 4 day_after_tomorrow = today + timedelta(days=4 if is_friday else 2) calendar = yf.Calendars(today, day_after_tomorrow) df = calendar.get_earnings_calendar(limit=100) unreported_df = df[df["Reported EPS"].isnull()] ``` -------------------------------- ### Initialize and Use Ticker Object Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.ticker_tickers.md Demonstrates how to initialize a Ticker object for a specific stock symbol and access various data points like historical data, options, financials, calendar, info, analyst targets, and live data. ```python import yfinance as yf dat = yf.Ticker("MSFT") # get historical market data dat.history(period='1mo') # options dat.option_chain(dat.options[0]).calls # get financials dat.balance_sheet dat.quarterly_income_stmt # dates dat.calendar # general info dat.info # analysis dat.analyst_price_targets # websocket dat.live() ``` -------------------------------- ### Run unit tests Source: https://github.com/ranaroussi/yfinance/blob/main/CONTRIBUTING.md Execute the project's test suite using the Python unittest module. ```bash python -m unittest discover -s tests ``` -------------------------------- ### AsyncWebSocket Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for asynchronously streaming live market data. ```APIDOC ## AsyncWebSocket Class ### Description Provides asynchronous streaming of live market data. ### Usage ```python async_ws = yf.AsyncWebSocket() ``` ``` -------------------------------- ### Initialize and Use Tickers Object for Multiple Stocks Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.ticker_tickers.md Shows how to initialize a Tickers object to manage multiple stock symbols simultaneously and access individual ticker data like info, history, and actions. ```python import yfinance as yf tickers = yf.Tickers('msft aapl goog') # access each ticker using (example) tickers.tickers['MSFT'].info tickers.tickers['AAPL'].history(period="1mo") tickers.tickers['GOOG'].actions # websocket tickers.live() ``` -------------------------------- ### Create feature branch Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/code.md Commands to initialize a new branch from a base branch and ensure it is up to date. ```bash git checkout {base e.g. dev} git pull git checkout -b {your branch} ``` -------------------------------- ### Add methods for downloading option chain Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Introduces new methods specifically for downloading option chains. This functionality was added in version 0.1.41. ```python downloading option chain ``` -------------------------------- ### Access Fund Data with Ticker Object Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.ticker_tickers.md Illustrates how to use a Ticker object for ETFs/Mutual Funds to access fund-specific data such as description, operational information, and holdings. ```python import yfinance as yf spy = yf.Ticker('SPY') data = spy.funds_data # show fund description data.description # show operational information data.fund_overview data.fund_operations # show holdings related information data.asset_classes data.top_holdings data.equity_holdings data.bond_holdings data.bond_ratings data.sector_weightings ``` -------------------------------- ### screen Function Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Run equity/fund queries. ```APIDOC ## screen Function ### Description Executes equity or fund queries based on specified filters. ### Usage ```python results = yf.screen(filters=equity_filter) ``` ``` -------------------------------- ### WebSocket Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for synchronously streaming live market data. ```APIDOC ## WebSocket Class ### Description Enables synchronous streaming of live market data. ### Usage ```python ws = yf.WebSocket() ``` ``` -------------------------------- ### Enable yfinance Debug Logging Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/config.md Set `logging` to `True` to enable verbose debug logging for yfinance operations. This is useful for troubleshooting. ```python yf.config.debug.logging = True ``` -------------------------------- ### config.debug.logging Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Enable verbose debug logging. ```APIDOC ## config.debug.logging ### Description Enables or disables verbose debug logging for the yfinance package. ### Usage ```python yf.config.debug.logging = True ``` ``` -------------------------------- ### Subscribe to price updates with Asynchronous WebSocket Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.websocket.md Uses the AsyncWebSocket class for non-blocking data streaming. Requires an event loop to execute. ```python import asyncio import yfinance as yf # define your message callback def message_handler(message): print("Received message:", message) async def main(): # ======================= # With Context Manager # ======================= async with yf.AsyncWebSocket() as ws: await ws.subscribe(["AAPL", "BTC-USD"]) await ws.listen() # ======================= # Without Context Manager # ======================= ws = yf.AsyncWebSocket() await ws.subscribe(["AAPL", "BTC-USD"]) await ws.listen() asyncio.run(main()) ``` -------------------------------- ### Chain Ticker with Sector and Industry Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.sector_industry.md Shows how to derive Sector and Industry objects from a Ticker instance and vice versa. ```python import yfinance as yf # Ticker to Sector and Industry msft = yf.Ticker('MSFT') tech = yf.Sector(msft.info.get('sectorKey')) software = yf.Industry(msft.info.get('industryKey')) # Sector and Industry to Ticker tech_ticker = tech.ticker tech_ticker.info software_ticker = software.ticker software_ticker.history() ``` -------------------------------- ### Enable Debug Logging in yfinance Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/logging.md Set the debug logging configuration to true to output detailed diagnostic information. ```python import yfinance as yf yf.config.debug.logging = True ``` -------------------------------- ### Initialize Ticker Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/index.md Basic initialization of a Ticker object for a specific symbol. ```python import yfinance as yf dat = yf.Ticker("MSFT") ``` -------------------------------- ### Format Git commit messages Source: https://github.com/ranaroussi/yfinance/blob/main/CONTRIBUTING.md Use multiple -m flags to provide a short summary followed by a detailed commit message. ```bash git commit -m "short sentence summary" -m "full commit message" ``` -------------------------------- ### Run Subset of Price Tests Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/testing.md Execute a specific subset of price tests by targeting a particular test class, such as `TestPriceRepair`, within the `tests.test_prices` module. ```bash python -m unittest tests.test_prices.TestPriceRepair ``` -------------------------------- ### Switch to query2.finance.yahoo.com Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Updates the library to use `query2.finance.yahoo.com`, which utilizes HTTP/1.1. This change was made in version 0.1.61. ```python query2.finance.yahoo.com ``` -------------------------------- ### Subscribe to price updates with Synchronous WebSocket Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.websocket.md Uses the WebSocket class to stream data. Supports both context manager and manual lifecycle management. ```python import yfinance as yf # define your message callback def message_handler(message): print("Received message:", message) # ======================= # With Context Manager # ======================= with yf.WebSocket() as ws: ws.subscribe(["AAPL", "BTC-USD"]) ws.listen(message_handler) # ======================= # Without Context Manager # ======================= ws = yf.WebSocket() ws.subscribe(["AAPL", "BTC-USD"]) ws.listen(message_handler) ``` -------------------------------- ### Add sustainability data/error handling Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Includes sustainability data and error handling for ETFs/MFs, contributed by GregoryMorse. Avoids rounding values from Yahoo by default. Added in version 0.1.45. ```python sustainability data/error handling for ETF/MF ``` -------------------------------- ### Support custom requests session instance Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Allows users to specify a custom `requests.Session` instance for making requests. This feature was added in version 0.1.58 and refined in 0.1.59. ```python holders ``` -------------------------------- ### Add Ticker.analysis and Ticker.get_analysis Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Introduces new methods for accessing ticker analysis data. These are available from version 0.1.64 onwards. ```python Ticker.analysis Ticker.get_analysis(...) ``` -------------------------------- ### EquityQuery Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class to build equity query filters. ```APIDOC ## EquityQuery Class ### Description Used to construct filters for equity queries. ### Usage ```python equity_filter = yf.EquityQuery() ``` ``` -------------------------------- ### Fix Dividend and Adjustment Data Too Large Source: https://github.com/ranaroussi/yfinance/wiki/Price-repair Illustrates a case where both dividend and adjustment data appear excessively large, showing original and corrected values. ```text # ORIGINAL: Close Adj Close Adj Dividends 2024-08-08 00:00:00+01:00 768.0 768.0 1.0000 5150.0 2024-08-07 00:00:00+01:00 819.0 -4331.0 -5.2882 0.0 Close Adj Close Adj Dividends 2024-08-08 00:00:00+01:00 768.0 768.0 1.0000 51.5 2024-08-07 00:00:00+01:00 819.0 767.5 0.9371 0.0 ``` -------------------------------- ### Add Ticker.financials, Ticker.balance_sheet, Ticker.cashflow Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Adds methods `Ticker('XXX').financials`, `Ticker('XXX').balance_sheet`, and `Ticker('XXX').cashflow` for retrieving financial statements. Proxy support for downloading actions was also added. Implemented in version 0.1.39. ```python Ticker('XXX').financials Ticker('XXX').balance_sheet Ticker('XXX').cashflow ``` -------------------------------- ### Set yfinance Network Proxy Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/config.md Configure a proxy server for all yfinance data fetches. Replace `PROXY_SERVER` with your actual proxy address. ```python yf.config.network.proxy = "PROXY_SERVER" ``` -------------------------------- ### Add Ticker.isin and Ticker.get_isin() Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Adds experimental methods `Ticker.isin` and `Ticker.get_isin(...)` for ISIN lookup. Use with caution as it's experimental. Introduced in version 0.1.53. ```python Ticker.isin Ticker.get_isin(...) ``` -------------------------------- ### FundQuery Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class to build fund query filters. ```APIDOC ## FundQuery Class ### Description Used to construct filters for fund queries. ### Usage ```python fund_filter = yf.FundQuery() ``` ``` -------------------------------- ### Retrieve Fund Data Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/index.md Access specific fund data such as descriptions and top holdings. ```python spy = yf.Ticker('SPY').funds_data spy.description spy.top_holdings ``` -------------------------------- ### Access yfinance Global Config Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/config.md View the current global configuration of yfinance. This shows the default network and debug settings. ```python >>> import yfinance as yf >>> yf.config { "network": { "proxy": null, "retries": 0 }, "debug": { "hide_exceptions": true, "logging": false } } ``` ```python >>> yf.config.network { "proxy": null, "retries": 0 } ``` -------------------------------- ### Rebase branch onto dev Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/code.md Workflow to move a branch from main to dev and update local references. ```bash # update all branches: git checkout main git pull git checkout dev git pull # rebase from main to dev: git checkout {your branch} git pull git rebase --onto dev main {your branch} git push --force-with-lease origin {your branch} ``` -------------------------------- ### Handle Multiple Tickers Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/index.md Manage multiple ticker symbols using the Tickers class or bulk download. ```python tickers = yf.Tickers('MSFT AAPL GOOG') tickers.tickers['MSFT'].info yf.download(['MSFT', 'AAPL', 'GOOG'], period='1mo') ``` -------------------------------- ### Add financial data to info() Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Includes financial data within the `info()` method's output. This enhancement was added in version 0.1.60. ```python info() ``` -------------------------------- ### Commit changes Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/code.md Standard format for commit messages to maintain a clean network graph. ```bash git commit -m "short sentence summary" -m "full commit message" # Long message can be multiple lines (tip: copy-paste) ``` -------------------------------- ### download Function Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Function to download market data for multiple tickers. ```APIDOC ## download Function ### Description Downloads historical market data for one or more tickers. ### Usage ```python data = yf.download("AAPL MSFT", start="2023-01-01", end="2023-12-31") ``` ``` -------------------------------- ### Squash commits Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/code.md Interactive rebase command to combine recent commits into a single meaningful entry. ```bash git rebase -i HEAD~2 git push --force-with-lease origin {your branch} ``` -------------------------------- ### Query Market Data - Sector and Industry Modules Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.screener.md Access sector and industry information using the Sector and Industry modules. ```APIDOC ## Query Market Data ### Description The Sector and Industry modules allow you to access the sector and industry information. ### SEE ALSO `EquityQuery.valid_fields`: supported operand values for query `EquityQuery.valid_values`: supported EQ query operand parameters `FundQuery.valid_fields`: supported operand values for query `FundQuery.valid_values`: supported EQ query operand parameters `ETFQuery.valid_fields`: supported operand values for query `ETFQuery.valid_values`: supported EQ query operand parameters ``` -------------------------------- ### Add Conversion rate hint Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Introduces a conversion rate hint using the 'financialCurrency' property in earnings data. This was added in version 0.1.57. ```python 'financialCurrency' ``` -------------------------------- ### Lookup Ticker Information Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.search.md Use the Lookup class to retrieve specific asset types like stocks, ETFs, or cryptocurrencies. Methods support both direct property access and parameterized retrieval. ```python import yfinance as yf # Get All all = yf.Lookup("AAPL").all all = yf.Lookup("AAPL").get_all(count=100) # Get Stocks stock = yf.Lookup("AAPL").stock stock = yf.Lookup("AAPL").get_stock(count=100) # Get Mutual Funds mutualfund = yf.Lookup("AAPL").mutualfund mutualfund = yf.Lookup("AAPL").get_mutualfund(count=100) # Get ETFs etf = yf.Lookup("AAPL").etf etf = yf.Lookup("AAPL").get_etf(count=100) # Get Indices index = yf.Lookup("AAPL").index index = yf.Lookup("AAPL").get_index(count=100) # Get Futures future = yf.Lookup("AAPL").future future = yf.Lookup("AAPL").get_future(count=100) # Get Currencies currency = yf.Lookup("AAPL").currency currency = yf.Lookup("AAPL").get_currency(count=100) # Get Cryptocurrencies cryptocurrency = yf.Lookup("AAPL").cryptocurrency cryptocurrency = yf.Lookup("AAPL").get_cryptocurrency(count=100) ``` -------------------------------- ### Search for Quotes, News, and Research Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.search.md Use the Search class to query financial data by keyword. Results can be filtered by result count or inclusion of research data. ```python import yfinance as yf # get list of quotes quotes = yf.Search("AAPL", max_results=10).quotes # get list of news news = yf.Search("Google", news_count=10).news # get list of related research research = yf.Search("apple", include_research=True).research ``` -------------------------------- ### ETFQuery Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class to build ETF query filters. ```APIDOC ## ETFQuery Class ### Description Used to construct filters for ETF queries. ### Usage ```python etf_filter = yf.ETFQuery() ``` ``` -------------------------------- ### Tickers Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for handling multiple tickers. ```APIDOC ## Tickers Class ### Description Allows for managing and retrieving data for multiple stock tickers simultaneously. ### Usage ```python tickers = yf.Tickers("AAPL MSFT GOOG") ``` ``` -------------------------------- ### Run Specific Test Method Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/testing.md Execute a single, specific test method, like `test_ticker_missing`, within a particular test class (`TestPriceRepair`) and file (`tests.test_prices_repair`). ```bash python -m unittest tests.test_prices_repair.TestPriceRepair.test_ticker_missing ``` -------------------------------- ### PriceHistory.get_actions() Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.price_history.md Retrieves stock actions (dividends and splits) for a given period. ```APIDOC ## GET /actions ### Description Retrieves stock actions, such as dividends and stock splits, for a specified period. ### Method GET ### Endpoint /actions ### Parameters #### Query Parameters - **period** (string) - Optional - Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max. Default: ‘max’. ### Response #### Success Response (200) - **Series** - A pandas Series containing stock actions. #### Response Example ```json { "2023-01-01": 0.5, "2023-06-01": 0.5 } ``` ``` -------------------------------- ### Fix Dividend Data Too Large Source: https://github.com/ranaroussi/yfinance/wiki/Price-repair Compares original dividend data that appears too large with a repaired version, suggesting a potential scaling issue. ```text # ORIGINAL: Close Adj Close Dividends 2024-06-27 00:00:00+01:00 2.360 2.3600 1.78 2024-06-26 00:00:00+01:00 2.375 2.3572 0.00 ``` ```text # REPAIRED: Close Adj Close Dividends 2024-06-27 00:00:00+01:00 2.360 2.3600 0.0178 2024-06-26 00:00:00+01:00 2.375 2.3572 0.0000 ``` -------------------------------- ### Enable yfinance Exception Visibility Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/config.md Set `hide_exceptions` to `False` to prevent yfinance from hiding exceptions during operations. By default, exceptions are hidden. ```python yf.config.debug.hide_exceptions = False ``` -------------------------------- ### PriceHistory.history() Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.price_history.md Retrieves historical stock data for a given ticker within a specified period and interval. Supports various adjustments and data repair options. ```APIDOC ## GET /history ### Description Retrieves historical stock data including Open, High, Low, Close prices, Volume, and Dividends for a specified ticker. Allows for customization of the time period, interval, and data adjustments. ### Method GET ### Endpoint /history ### Parameters #### Query Parameters - **period** (string) - Optional - Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max. Default: ‘1mo’ if start & end None. Can combine with start/end e.g. end = start + period. - **interval** (string) - Optional - Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo. Intraday data cannot extend last 60 days. - **start** (string) - Optional - Download start date string (YYYY-MM-DD) or \_datetime, inclusive. Default: 99 years ago. - **end** (string) - Optional - Download end date string (YYYY-MM-DD) or \_datetime, exclusive. Default: now. - **prepost** (boolean) - Optional - Include Pre and Post market data in results? Default: False. - **actions** (boolean) - Optional - Include dividend and split actions in results? Default: True. - **auto_adjust** (boolean) - Optional - Adjust all OHLC automatically? Default: True. - **back_adjust** (boolean) - Optional - Back-adjusted data to mimic true historical prices. Default: False. - **repair** (boolean) - Optional - Fixes price errors in Yahoo data: 100x, missing, bad dividend adjust. Default: False. - **keepna** (boolean) - Optional - Keep NaN rows returned by Yahoo? Default: False. - **rounding** (boolean) - Optional - Round values to 2 decimal places? Default: False. - **timeout** (integer) - Optional - Timeout fetches after N seconds. Default: 10. - **raise_errors** (boolean) - Optional - If True, then raise errors as Exceptions instead of logging. Default: False. ### Response #### Success Response (200) - **DataFrame** - A pandas DataFrame containing historical stock data (Date, Open, High, Low, Close, Adj Close, Volume). #### Response Example ```json { "Date": ["2023-01-01", "2023-01-02"], "Open": [100.0, 101.0], "High": [102.0, 103.0], "Low": [99.0, 100.5], "Close": [101.5, 102.5], "Adj Close": [101.5, 102.5], "Volume": [100000, 110000] } ``` ``` -------------------------------- ### yfinance Global Configuration Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/config.md Access and modify the global configuration settings for yfinance, including network proxy settings, retry logic, and debug flags. ```APIDOC ## Global Configuration Access ### Description Access the global configuration object to view or modify settings for network and debugging. ### Configuration Structure - **network** (object) - **proxy** (string/null) - Set proxy for all yfinance data fetches. - **retries** (integer) - Configure automatic retry for transient network errors using exponential backoff. - **debug** (object) - **hide_exceptions** (boolean) - Set to False to stop yfinance from hiding exceptions. - **logging** (boolean) - Set to True to enable verbose debug logging. ### Usage Example ```python import yfinance as yf # Set network proxy yf.config.network.proxy = "PROXY_SERVER" # Configure retries yf.config.network.retries = 2 # Disable exception hiding yf.config.debug.hide_exceptions = False # Enable logging yf.config.debug.logging = True ``` ``` -------------------------------- ### PriceHistory.get_dividends() Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.price_history.md Retrieves dividend data for a given period, with an option to repair data. ```APIDOC ## GET /dividends ### Description Retrieves dividend payment history for a specified period. Includes the date and amount of each dividend payment. ### Method GET ### Endpoint /dividends ### Parameters #### Query Parameters - **period** (string) - Optional - Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max. Default: ‘max’. - **repair** (boolean) - Optional - Attempts to repair common data errors. Default: False. ### Response #### Success Response (200) - **Series** - A pandas Series containing dividend data (Date: Dividend Amount). #### Response Example ```json { "2023-01-01": 0.50, "2023-04-01": 0.55 } ``` ``` -------------------------------- ### Lookup Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for looking up tickers. ```APIDOC ## Lookup Class ### Description Provides functionality to look up specific ticker symbols. ### Usage ```python lookup_results = yf.Lookup("AAPL") ``` ``` -------------------------------- ### Rewrite fundamental-related methods Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Refactored all fundamental-related methods to support quarterly financials, cashflow, balance sheets, earnings, analyst recommendations, and earnings calendar data. This was a major update in version 0.1.46. ```python quarterly financials, cashflow, balance sheets, and earnings, analysts recommendations, and earnings calendar data ``` -------------------------------- ### Access Ticker Data Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/index.md Retrieve various financial data points and history for a single ticker. ```python dat = yf.Ticker("MSFT") dat.info dat.calendar dat.analyst_price_targets dat.quarterly_income_stmt dat.history(period='1mo') dat.option_chain(dat.options[0]).calls ``` -------------------------------- ### PriceHistory.get_splits() Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.price_history.md Retrieves stock split data for a given period, with an option to repair data. ```APIDOC ## GET /splits ### Description Retrieves stock split history for a specified period. Indicates the ratio of the stock split. ### Method GET ### Endpoint /splits ### Parameters #### Query Parameters - **period** (string) - Optional - Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max. Default: ‘max’. - **repair** (boolean) - Optional - Attempts to repair common data errors. Default: False. ### Response #### Success Response (200) - **Series** - A pandas Series containing stock split data (Date: Split Ratio). #### Response Example ```json { "2022-11-21": 2.0, "2023-05-10": 3.0 } ``` ``` -------------------------------- ### Configure yfinance Network Retries Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/config.md Set the number of automatic retries for transient network errors. The retry mechanism uses exponential backoff. ```python yf.config.network.retries = 2 ``` -------------------------------- ### Market Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for accessing market summary data. ```APIDOC ## Market Class ### Description Provides access to overall market summary information. ### Usage ```python market = yf.Market() ``` ``` -------------------------------- ### Add Ticker.stats() method Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Adds the Ticker.stats() method to retrieve statistical data for a ticker. This feature was introduced in version 0.1.64. ```python Ticker.stats() ``` -------------------------------- ### Add Ticker.news property Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Introduces the Ticker.news property to access news related to a ticker. Available since version 0.1.64. ```python Ticker.news ``` -------------------------------- ### Enable nested event loops for Jupyter Notebooks Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.websocket.md Required when running asynchronous operations within a Jupyter environment to prevent event loop conflicts. ```python import nest_asyncio nest_asyncio.apply() ``` -------------------------------- ### Display Original vs Repaired Duplicate Dividend Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/price_repair.md Illustrates the correction of duplicate dividend entries within a 7-day period. The 'Dividends' value for the earlier date is set to 0 in the repaired data. ```text # ORIGINAL: Close Adj Close Dividends 2023-05-10 00:00:00+02:00 70.580002 70.352142 0.21 2023-05-09 00:00:00+02:00 65.739998 65.318443 0.21 2023-05-08 00:00:00+02:00 66.379997 65.745682 0.00 ``` ```text # REPAIRED: Close Adj Close Dividends 2023-05-10 00:00:00+02:00 70.580002 70.352142 0.00 2023-05-09 00:00:00+02:00 65.739998 65.527764 0.21 2023-05-08 00:00:00+02:00 66.379997 65.956371 0.00 ``` -------------------------------- ### Ticker Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for accessing single ticker data. ```APIDOC ## Ticker Class ### Description Provides access to data for a single stock ticker. ### Usage ```python ticker = yf.Ticker("AAPL") ``` ``` -------------------------------- ### Fix Yahoo! 30m bars returned as 60m/15m Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Addresses an issue where Yahoo! was returning 30-minute bars as 60-minute or 15-minute intervals. This bug was fixed in version 0.1.30. ```python Yahoo!'s 30m bars being returned as 60m/15m ``` -------------------------------- ### Fix Ex-Dividend Date and Adjustments Source: https://github.com/ranaroussi/yfinance/wiki/Price-repair Highlights a scenario where the ex-dividend date appears incorrect, leading to miscalculations in dividends and adjusted prices. Compares original and repaired data. ```text # ORIGINAL: Close Adj Close Dividends 2022-06-22 00:00:00+02:00 66.699997 60.085415 0.0 2022-06-21 00:00:00+02:00 71.599998 64.499489 0.0 2022-06-20 00:00:00+02:00 71.800003 64.679657 5.0 2022-06-17 00:00:00+02:00 71.000000 59.454838 0.0 ``` ```text # REPAIRED: Close Adj Close Dividends 2022-06-22 00:00:00+02:00 66.699997 60.085415 5.0 2022-06-21 00:00:00+02:00 71.599998 60.007881 0.0 2022-06-20 00:00:00+02:00 71.800003 60.175503 0.0 2022-06-17 00:00:00+02:00 71.000000 59.505021 0.0 ``` -------------------------------- ### PriceHistory.get_capital_gains() Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.price_history.md Retrieves capital gains data for a given period, with an option to repair data. ```APIDOC ## GET /capital_gains ### Description Retrieves capital gains data for a specified period. This can be useful for tax-related calculations. ### Method GET ### Endpoint /capital_gains ### Parameters #### Query Parameters - **period** (string) - Optional - Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max. Default: ‘max’. - **repair** (boolean) - Optional - Attempts to repair common data errors. Default: False. ### Response #### Success Response (200) - **Series** - A pandas Series containing capital gains data. #### Response Example ```json { "2023-01-01": 10.50, "2023-03-15": 5.25 } ``` ``` -------------------------------- ### Add UserAgent to requests Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Ensures all requests include a User-Agent header using `utils.user_agent_headers`. This was implemented in version 0.1.62. ```python utils.user_agent_headers ``` -------------------------------- ### Add holdings data Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Introduces `Ticker.major_holders` and `Ticker.institutional_holders` for accessing holdings data. Also adds logo URL to `Ticker.info`. Implemented in version 0.1.51. ```python Ticker.major_holders Ticker.institutional_holders Ticker.info ``` -------------------------------- ### PriceHistory.get_history_metadata() Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/yfinance.price_history.md Retrieves metadata associated with the historical data. ```APIDOC ## GET /history/metadata ### Description Retrieves metadata associated with the historical data, which may include information about the data source, currency, or other relevant details. ### Method GET ### Endpoint /history/metadata ### Response #### Success Response (200) - **dict** - A dictionary containing metadata related to the historical data. #### Response Example ```json { "currency": "USD", "exchange": "NYSE", "first_trade_date": "1980-01-01", "last_trade_date": "2023-12-31" } ``` ``` -------------------------------- ### Fix Adjusted Close Price Calculation Source: https://github.com/ranaroussi/yfinance/wiki/Price-repair Demonstrates an issue where the adjusted close price seems incorrect, possibly due to an error in the day before the ex-dividend date. Shows original and repaired data. ```text # ORIGINAL: Low Close Adj Close Dividends 2023-12-21 00:00:00+01:00 120.199997 121.099998 118.868782 0.18 2023-12-20 00:00:00+01:00 122.000000 121.900002 119.477371 0.00 ``` ```text # REPAIRED: Low Close Adj Close Dividends 2023-12-21 00:00:00+01:00 120.199997 121.099998 118.868782 0.18 2023-12-20 00:00:00+01:00 122.000000 122.080002 119.654045 0.00 ``` -------------------------------- ### Update branch with base Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/development/code.md Use rebase to incorporate new commits from the base branch without creating merge commits. ```bash git checkout {base branch e.g. dev} git pull git checkout {your branch} git rebase {base} git push --force-with-lease origin {your branch} ``` -------------------------------- ### Display Original vs Repaired Small Dividend Adjustment Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/price_repair.md Shows the difference between original and repaired data when a dividend adjustment is too small. The 'Adj Close' value is corrected in the repaired data. ```text # ORIGINAL: Close Adj Close Dividends 2024-06-13 00:00:00+01:00 3.185 3.185000 0.05950 2024-06-12 00:00:00+01:00 3.270 3.269405 0.00000 ``` ```text # REPAIRED: Close Adj Close Dividends 2024-06-13 00:00:00+01:00 3.185 3.185000 0.05950 2024-06-12 00:00:00+01:00 3.270 3.210500 0.00000 ``` -------------------------------- ### Sector Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Domain class for accessing sector information. ```APIDOC ## Sector Class ### Description Accesses information related to market sectors. ### Usage ```python sector_info = yf.Sector() ``` ``` -------------------------------- ### Search Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for accessing search results. ```APIDOC ## Search Class ### Description Facilitates searching for financial instruments. ### Usage ```python search_results = yf.Search("Apple") ``` ``` -------------------------------- ### Industry Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Domain class for accessing industry information. ```APIDOC ## Industry Class ### Description Retrieves information about different market industries. ### Usage ```python industry_info = yf.Industry() ``` ``` -------------------------------- ### Calendars Class Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Class for accessing calendar events data. ```APIDOC ## Calendars Class ### Description Enables retrieval of financial calendar events. ### Usage ```python calendars = yf.Calendars() ``` ``` -------------------------------- ### Improve Tickers module Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Enhancements to the `Tickers` module, as detailed in issue #86. This update was part of version 0.1.44. ```python Tickers module ``` -------------------------------- ### Set Volume column dtype to np.int64 Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Ensures the 'Volume' column is set to `np.int64` dtype to prevent integer overflow issues on Windows. This change was made in version 0.1.1. ```python np.int64 dtype ``` -------------------------------- ### Set yfinance Timezone Cache Location Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/caching.md Use `set_tz_cache_location` to specify a custom directory for yfinance's timezone cache. Ensure the provided path is valid and accessible. ```python import yfinance as yf yf.set_tz_cache_location("custom/cache/location") ``` -------------------------------- ### Display Original vs Repaired Dividend Adjustment Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/advanced/price_repair.md Compares original and repaired dividend adjustment data for a specific stock. The 'Repaired?' column indicates if a fix was applied. ```text # ORIGINAL: Close Adj Close Dividends 2024-07-08 00:00:00+08:00 4.33 4.33 0.335715 2024-07-04 00:00:00+08:00 4.83 4.83 0.000000 ``` ```text # REPAIRED: Close Adj Close Dividends 2024-07-08 00:00:00+08:00 4.33 4.330000 0.335715 2024-07-04 00:00:00+08:00 4.83 4.494285 0.000000 ``` -------------------------------- ### Fix 60m interval when requesting 30m Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Corrects a bug where Yahoo! returned 60m interval data when 30m was requested, by requesting 15m and resampling. `Ticker.history()` auto-adjusts data by default. Fixed in version 0.1.26. ```python Ticker.history() ``` -------------------------------- ### Propagate timeout parameter Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Ensures the timeout parameter is correctly propagated through the code, specifically setting `request.get(timeout)`. This was part of an update in version 0.1.64. ```python request.get(timeout) ``` -------------------------------- ### Intercept yahoo 'site down' message Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Implements interception for Yahoo!'s 'site down' messages for better error handling. Threading is now True by default. This was added in version 0.1.34. ```python yahoo "site down" message ``` -------------------------------- ### set_tz_cache_location Function Source: https://github.com/ranaroussi/yfinance/blob/main/doc/source/reference/index.md Function to set the timezone cache location. ```APIDOC ## set_tz_cache_location Function ### Description Sets the location for the timezone cache. ### Usage ```python yf.set_tz_cache_location("/path/to/cache") ``` ``` -------------------------------- ### Override pandas_datareader.data.DataReader Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Enables overriding the old `pandas_datareader.data.DataReader` when `pdr_override()` is called. `Tickers()` now returns a named tuple of `Ticker()` objects. This was introduced in version 0.1.37. ```python pandas_datareader.data.DataReader pdr_override() Tickers() ``` -------------------------------- ### Fix Pandas DataFrame constructor issue Source: https://github.com/ranaroussi/yfinance/blob/main/CHANGELOG.rst Resolves the 'DataFrame constructor not properly called!' issue with Pandas. If `threads` is True, it defaults to the number of tickers (max = number of CPU cores). Fixed in version 0.1.29. ```python Pandas "DataFrame constructor not properly called!" threads ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.