### Install Stockdex Python Package Source: https://github.com/ahnazary/stockdex/blob/main/README.md Instructions to install the Stockdex Python package using pip. The `-U` flag ensures the package is updated to the latest version, and `--no-cache-dir` prevents caching issues during installation. ```bash pip install stockdex -U --no-cache-dir ``` -------------------------------- ### Python Project Dependencies List Source: https://github.com/ahnazary/stockdex/blob/main/requirements_sphinx.txt This snippet details the Python packages and their exact versions necessary for the project. These dependencies are crucial for reproducing the project's environment and ensuring all required libraries are installed correctly. ```Python sphinx-rtd-theme==1.2.2 sphinxcontrib-applehelp==1.0.4 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.1 sphinxcontrib-jquery==4.1 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 myst-parser==2.0.0 plotly>=5.24.1 dash>=2.18.0 numpy==1.25.1 ``` -------------------------------- ### Retrieve Raw Financial Data from Yahoo Finance, Digrin, and Macrotrends Source: https://github.com/ahnazary/stockdex/blob/main/README.md Examples of retrieving various types of raw financial data for a given stock ticker using the `Ticker` object. This includes price data from Yahoo Finance API, historical dividends from Digrin, income statements from Macrotrends, and summary information from the Yahoo Finance website. It also shows how to plot financial data using Plotly. ```python from stockdex import Ticker from datetime import datetime ticker = Ticker(ticker="AAPL") # Price data (use range and dataGranularity to make range and granularity more specific) from Yahoo Finance API price = ticker.yahoo_api_price(range='1y', dataGranularity='1d') # plot financial data using Plotly ticker = Ticker(ticker="MSFT") ticker.plot_yahoo_api_financials(group_by="field") # Complete historical data of the stock in certain categories from digrin website dividend = ticker.digrin_dividend # Financial data from macrotrends website income_statement = ticker.macrotrends_income_statement # Summary including general financial information from Yahoo Finance website summary = ticker.yahoo_web_summary ``` -------------------------------- ### Retrieve Raw Historical and Non-Historical Data from Digrin Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md This snippet shows how to access various historical and non-historical stock data points from the Digrin website using the `stockdex.Ticker` object. Unlike Yahoo Finance, Digrin provides more extensive historical data. Examples include dividend history, payout ratios, stock splits, price data, assets vs. liabilities, free cash flow, net income, cash and debt, shares outstanding, expenses, cost of revenue, and upcoming estimated earnings. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") # Complete historical data of the stock in certain categories dividend = ticker.digrin_dividend payout_ratio = ticker.digrin_payout_ratio stock_splits = ticker.digrin_stock_splits price = ticker.digrin_price # Non-historical data assets_vs_liabilities = ticker.digrin_assets_vs_liabilities free_cash_flow = ticker.digrin_free_cash_flow net_income = ticker.digrin_net_income cash_and_debt = ticker.digrin_cash_and_debt shares_outstanding = ticker.digrin_shares_outstanding expenses = ticker.digrin_expenses cost_of_revenue = ticker.digrin_cost_of_revenue upcoming_estimated_earnings = ticker.digrin_upcoming_estimated_earnings # Dividend data dividend = ticker.digrin_dividend dgr3 = ticker.digrin_dgr3 dgr5 = ticker.digrin_dgr5 dgr10 = ticker.digrin_dgr10 ``` -------------------------------- ### Plot Financial Data from Yahoo Finance API Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md This snippet illustrates how to use `stockdex` functions to plot financial data retrieved from the Yahoo Finance API. These functions leverage the `plotly` library to generate interactive visualizations. Examples include plotting financials, income statements, cash flow, and balance sheets. The `group_by` and `freq` parameters allow for customization of the plot's aggregation and frequency. ```python from stockdex import Ticker ticker = Ticker(ticker="MSFT") ticker.plot_yahoo_api_financials(group_by="field") ticker.plot_yahoo_api_income_statement(group_by="timeframe") ticker.plot_yahoo_api_cash_flow(freq="quarterly") ticker.plot_yahoo_api_balance_sheet(freq="quarterly") ``` -------------------------------- ### Retrieve Raw Financial Data from Yahoo Finance API Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md This snippet demonstrates how to use the `stockdex.Ticker` object to fetch various raw financial data points from the Yahoo Finance API. Data is returned as pandas DataFrames. Examples include price data, current trading periods, income statements, cash flow, balance sheets, and general financials. Parameters like `range`, `dataGranularity`, `frequency`, `format`, `period1`, and `period2` can be used to fine-tune the data retrieval. ```python from stockdex import Ticker from datetime import datetime ticker = Ticker(ticker="AAPL") # Price data (use range and dataGranularity to make range and granularity more specific) price = ticker.yahoo_api_price(range='1y', dataGranularity='1d') # Current trading period of the stock (pre-market, regular, post-market trading periods) current_trading_period = ticker.yahoo_api_current_trading_period # Fundamental data (use frequency, format, period1 and period2 to fine-tune the returned data) income_statement = ticker.yahoo_api_income_statement(frequency='quarterly') cash_flow = ticker.yahoo_api_cash_flow(format='raw') balance_sheet = ticker.yahoo_api_balance_sheet(period1=datetime(2020, 1, 1)) financials = ticker.yahoo_api_financials(period1=datetime(2022, 1, 1), period2=datetime.today()) ``` -------------------------------- ### API Documentation for stockdex.justetf_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.justetf_interface` module, including all public and undocumented members, and inheritance hierarchy. This module is designed for interacting with the JustETF data source. ```APIDOC stockdex.justetf_interface module ---------------------------------- .. automodule:: stockdex.justetf_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.config Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.config` module, including all public and undocumented members, and inheritance hierarchy. This module likely handles configuration settings for the stockdex library. ```APIDOC stockdex.config module ---------------------- .. automodule:: stockdex.config :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.lib Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.lib` module, including all public and undocumented members, and inheritance hierarchy. This module likely contains general utility functions and helper classes for the stockdex library. ```APIDOC stockdex.lib module ------------------- .. automodule:: stockdex.lib :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex Main Package Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the main `stockdex` package, including all public and undocumented members, and inheritance hierarchy. This entry documents the top-level components and functionalities of the stockdex library. ```APIDOC Module contents --------------- .. automodule:: stockdex :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.digrin_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.digrin_interface` module, including all public and undocumented members, and inheritance hierarchy. This module is expected to facilitate interaction with the Digrin data source. ```APIDOC stockdex.digrin_interface module --------------------------------- .. automodule:: stockdex.digrin_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.nasdaq_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.nasdaq_interface` module, including all public and undocumented members, and inheritance hierarchy. This module facilitates interaction with the Nasdaq data source. ```APIDOC stockdex.nasdaq_interface module --------------------------------- .. automodule:: stockdex.nasdaq_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.yahoo_api_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.yahoo_api_interface` module, including all public and undocumented members, and inheritance hierarchy. This module is designed for interacting with Yahoo's financial API. ```APIDOC stockdex.yahoo_api_interface module ------------------------------------- .. automodule:: stockdex.yahoo_api_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### Plotting Stock Data from Digrin with Plotly Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md Demonstrates how to plot various financial metrics (shares outstanding, price, dividend, assets vs. liabilities, free cash flow, cash and debt, net income, expenses, cost of revenue) extracted from Digrin using the `stockdex` library and `plotly`. Each function call opens a plot in the default browser. ```python from stockdex import Ticker ticker = Ticker(ticker="ASML") ticker.plot_digrin_shares_outstanding() ticker.plot_digrin_price() ticker.plot_digrin_dividend() ticker.plot_digrin_assets_vs_liabilities() ticker.plot_digrin_free_cash_flow() ticker.plot_digrin_cash_and_debt() ticker.plot_digrin_net_income() ticker.plot_digrin_expenses() ticker.plot_digrin_cost_of_revenue() ``` -------------------------------- ### API Documentation for stockdex.macrotrends_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.macrotrends_interface` module, including all public and undocumented members, and inheritance hierarchy. This module is intended for interacting with the Macrotrends data source. ```APIDOC stockdex.macrotrends_interface module -------------------------------------- .. automodule:: stockdex.macrotrends_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.exceptions Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.exceptions` module, including all public and undocumented members, and inheritance hierarchy. This module defines custom exception classes used throughout the stockdex library. ```APIDOC stockdex.exceptions module -------------------------- .. automodule:: stockdex.exceptions :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.selenium_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.selenium_interface` module, including all public and undocumented members, and inheritance hierarchy. This module likely integrates Selenium for web scraping or automation tasks. ```APIDOC stockdex.selenium_interface module ----------------------------------- .. automodule:: stockdex.selenium_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### API Documentation for stockdex.ticker_base Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.ticker_base` module, including all public and undocumented members, and inheritance hierarchy. This module likely contains the base class or foundational elements for ticker-related operations. ```APIDOC stockdex.ticker_base module ---------------------------- .. automodule:: stockdex.ticker_base :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### Initialize Stockdex Ticker Object for Stock Data Source: https://github.com/ahnazary/stockdex/blob/main/README.md Demonstrates how to create a `Ticker` object in Stockdex, which serves as the primary entry point for accessing financial data. The ticker symbol of the desired stock is passed as an argument during initialization. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") ``` -------------------------------- ### API Documentation for stockdex.yahoo_web_interface Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.yahoo_web_interface` module, including all public and undocumented members, and inheritance hierarchy. This module likely handles web scraping or direct web interaction with Yahoo Finance. ```APIDOC stockdex.yahoo_web_interface module ------------------------------------- .. automodule:: stockdex.yahoo_web_interface :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### Retrieving EU ETF Data from justETF by ISIN Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md Explains how to retrieve specific data for EU ETFs from the justETF website. It requires passing the `isin` (International Securities Identification Number) and setting `security_type` to 'etf' when initializing the `Ticker` object. Data includes general info, WKN, description, basic ETF data, and holdings by company, country, and sector. ```python from stockdex import Ticker etf = Ticker(isin="IE00B4L5Y983", security_type="etf") etf_general_info = etf.justetf_general_info etf_wkn = etf.justetf_wkn etf_description = etf.justetf_description # Basic data about the ETF etf_basics = etf.justetf_basics # Holdings of the ETF by company, country and sector etf_holdings_companies = etf.justetf_holdings_companies etf_holdings_countries = etf.justetf_holdings_countries etf_holdings_sectors = etf.justetf_holdings_sectors ``` -------------------------------- ### Creating a Multi-Plot Financial Dashboard with Stockdex and Dash Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python code snippet illustrates how to generate a dashboard displaying various financial metrics for a given stock (e.g., MSFT) using `stockdex` and `dash`. It fetches data from Digrin, creates individual `plotly` figures by calling `ticker.plot_digrin_*` methods with `show_plot=False` to prevent immediate display, and then consolidates these figures into a single web application using `plot_multiple_categories`. The dashboard will be accessible at `http://127.0.0.1:8050/`. ```Python from stockdex.ticker import Ticker from stockdex.lib import plot_multiple_categories # choose the stock ticker = Ticker(ticker="MSFT") # Here you will choose arbitrary figures to plot. In this example we will plot data extracted from digrin website # IMPORTANT: make sure to set show_plot=False in each function to return the plotly figure object instead of showing the plot. Not setting this parameter will show the plots in separate tabs. figures = [ ticker.plot_digrin_shares_outstanding(show_plot=False), ticker.plot_digrin_price(show_plot=False), ticker.plot_digrin_dividend(show_plot=False), ticker.plot_digrin_assets_vs_liabilities(show_plot=False), ticker.plot_digrin_free_cash_flow(show_plot=False), ticker.plot_digrin_net_income(show_plot=False), ticker.plot_digrin_cash_and_debt(show_plot=False), ticker.plot_digrin_expenses(show_plot=False), ticker.plot_digrin_cost_of_revenue(show_plot=False) ] # main functions that will create the dash app plot_multiple_categories(ticker=ticker.ticker, figures=figures) ``` -------------------------------- ### API Documentation for stockdex.sankey_charts Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.sankey_charts` module, including all public and undocumented members, and inheritance hierarchy. This module likely contains functionalities for generating Sankey charts. ```APIDOC stockdex.sankey_charts module ------------------------------ .. automodule:: stockdex.sankey_charts :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### Retrieving Raw Financial Data from Macrotrends as Pandas DataFrame Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md Shows how to extract various financial data points (income statement, balance sheet, cash flow, key financial ratios, and different margin types) from the Macrotrends website using `stockdex`. The data is returned as pandas DataFrames for further analysis. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") # Financial data income_statement = ticker.macrotrends_income_statement balance_sheet = ticker.macrotrends_balance_sheet cash_flow = ticker.macrotrends_cash_flow key_financial_ratios = ticker.macrotrends_key_financial_ratios # Margins gross_margin = ticker.macrotrends_gross_margin operating_margin = ticker.macrotrends_operating_margin ebitda_margin = ticker.macrotrends_ebitda_margin pre_tax_margin = ticker.macrotrends_pre_tax_margin net_margin = ticker.macrotrends_net_margin ``` -------------------------------- ### Python Project Dependency List Source: https://github.com/ahnazary/stockdex/blob/main/requirements.txt This snippet provides a comprehensive list of Python packages and their specific versions required to run the 'stockdex' project. These dependencies are typically managed via a `requirements.txt` file and are crucial for setting up the project's virtual environment. ```Python beautifulsoup4==4.12.3 numpy pandas>=2.2.3 plotly>=5.24.1 Requests==2.32.3 selenium==4.25.0 plotly>=5.24.1 dash>=2.18.0 ``` -------------------------------- ### Stockdex Python Package Requirements Source: https://github.com/ahnazary/stockdex/blob/main/requirements_tests.txt This snippet details the Python packages and their exact versions necessary to run the 'stockdex' project. It includes libraries for generating documentation (sphinx, myst-parser), handling data (pandas, numpy), performing web scraping (beautifulsoup4, requests, selenium), unit testing (pytest), and creating interactive dashboards (plotly, dash). ```Python sphinx-rtd-theme==1.2.2 sphinxcontrib-applehelp==1.0.4 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.1 sphinxcontrib-jquery==4.1 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 myst-parser==2.0.0 pandas==2.0.3 beautifulsoup4==4.12.2 pytest >=8.0.0 requests==2.31.0 selenium==4.18.1 numpy==1.25.1 plotly==5.24.1 dash>=2.18.0 ``` -------------------------------- ### Create a Multi-Plot Financial Dashboard with Stockdex and Dash Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md This Python snippet illustrates how to generate an interactive dashboard containing multiple financial plots using the `stockdex` library and the `dash` framework. It fetches various financial metrics (e.g., shares outstanding, price, dividend, assets vs. liabilities, free cash flow, net income, cash and debt, expenses, cost of revenue) for a specified ticker (e.g., MSFT) from the Digrin website. Each individual plot function must be called with `show_plot=False` to return a Plotly figure object, which is then passed to `plot_multiple_categories` to construct the Dash application, accessible at `http://127.0.0.1:8050/` by default. ```python from stockdex.ticker import Ticker from stockdex.lib import plot_multiple_categories # choose the stock ticker = Ticker(ticker="MSFT") # Here you will choose arbitrary figures to plot. In this example we will plot data extracted from digrin website # IMPORTANT: make sure to set show_plot=False in each function to return the plotly figure object instead of showing the plot. Not setting this parameter will show the plots in separate tabs. figures = [ ticker.plot_digrin_shares_outstanding(show_plot=False), ticker.plot_digrin_price(show_plot=False), ticker.plot_digrin_dividend(show_plot=False), ticker.plot_digrin_assets_vs_liabilities(show_plot=False), ticker.plot_digrin_free_cash_flow(show_plot=False), ticker.plot_digrin_net_income(show_plot=False), ticker.plot_digrin_cash_and_debt(show_plot=False), ticker.plot_digrin_expenses(show_plot=False), ticker.plot_digrin_cost_of_revenue(show_plot=False) ] # main functions that will create the dash app plot_multiple_categories(ticker=ticker.ticker, figures=figures) ``` -------------------------------- ### API Documentation for stockdex.ticker Module Source: https://github.com/ahnazary/stockdex/blob/main/docs/stockdex.rst Provides API reference for the `stockdex.ticker` module, including all public and undocumented members, and inheritance hierarchy. This module likely defines the core Ticker class or related functionalities. ```APIDOC stockdex.ticker module ---------------------- .. automodule:: stockdex.ticker :members: :undoc-members: :show-inheritance: ``` -------------------------------- ### Retrieving Various Stock Data from Yahoo Finance Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md Illustrates how to fetch a wide range of stock-related data from Yahoo Finance, including summary, financial statements, analyst estimates, options data (calls/puts), company profile, shareholder information, and various statistics. Data is accessed via `stockdex` attributes. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") # Summary including general financial information summary = ticker.yahoo_web_summary # Financial data as it is seen in the yahoo finance website income_stmt = ticker.yahoo_web_income_stmt balance_sheet = ticker.yahoo_web_balance_sheet cash_flow = ticker.yahoo_web_cashflow # Analysts and estimates analysis = ticker.yahoo_web_analysis # Data about options calls = ticker.yahoo_web_calls puts = ticker.yahoo_web_puts # Profile data key_executives = ticker.yahoo_web_key_executives description = ticker.yahoo_web_description corporate_governance = ticker.yahoo_web_corporate_governance # Data about shareholders major_holders = ticker.yahoo_web_major_holders top_institutional_holders = ticker.yahoo_web_top_institutional_holders top_mutual_fund_holders = ticker.yahoo_web_top_mutual_fund_holders # Statistics valuation_measures = ticker.yahoo_web_valuation_measures financial_highlights = ticker.yahoo_web_financial_highlights trading_information = ticker.yahoo_web_trading_information ``` -------------------------------- ### Plotting Financial Data from Macrotrends with Plotly Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md Demonstrates how to plot financial statements (income statement, balance sheet, cash flow) extracted from Macrotrends using the `stockdex` library and `plotly`. Each function call opens a plot in the default browser for visual inspection. ```python from stockdex import Ticker ticker = Ticker(ticker="GOOGL") ticker.plot_macrotrends_income_statement() ticker.plot_macrotrends_balance_sheet() ticker.plot_macrotrends_cash_flow() ``` -------------------------------- ### Plotting Historical Stock Price from Digrin as Line Chart Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md Illustrates how to plot the historical price data from Digrin as a line chart for stocks with many data points, such as 'CAT'. This function visualizes both real and adjusted prices, automatically switching from bar to line chart for dense data. ```python from stockdex import Ticker ticker = Ticker(ticker="CAT") ticker.plot_digrin_price() ``` -------------------------------- ### Retrieving EU ETF Data from justETF using ISIN Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python snippet shows how to retrieve detailed information for EU ETFs from the justETF website using `stockdex`. It requires passing the ETF's ISIN and setting `security_type` to 'etf'. The code fetches general info, WKN, description, price data, basic ETF details, and holdings by company, country, and sector. ```python from stockdex import Ticker etf = Ticker(isin="IE00B4L5Y983", security_type="etf") etf_general_info = etf.justetf_general_info etf_wkn = etf.justetf_wkn etf_description = etf.justetf_description # Price data and chabges etf_price = etf.justetf_price # Basic data about the ETF etf_basics = etf.justetf_basics # Holdings of the ETF by company, country and sector etf_holdings_companies = etf.justetf_holdings_companies etf_holdings_countries = etf.justetf_holdings_countries etf_holdings_sectors = etf.justetf_holdings_sectors ``` -------------------------------- ### Plotting Financial Data from Digrin with Plotly Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python code demonstrates how to use the `stockdex` library to extract and plot various financial data points from the Digrin website using `plotly`. It covers shares outstanding, price, dividend, assets vs. liabilities, free cash flow, cash and debt, net income, expenses, and cost of revenue. Each function call opens a new browser tab with the generated plot. ```python from stockdex import Ticker ticker = Ticker(ticker="ASML") ticker.plot_digrin_shares_outstanding() ticker.plot_digrin_price() ticker.plot_digrin_dividend() ticker.plot_digrin_assets_vs_liabilities() ticker.plot_digrin_free_cash_flow() ticker.plot_digrin_cash_and_debt() ticker.plot_digrin_net_income() ticker.plot_digrin_expenses() ticker.plot_digrin_cost_of_revenue() ``` -------------------------------- ### Retrieve EU ETF General Information from justETF Source: https://github.com/ahnazary/stockdex/blob/main/README.md Shows how to retrieve general information for EU ETFs using Stockdex. The `Ticker` object is initialized with the ETF's International Securities Identification Number (ISIN) and the `security_type` parameter set to 'etf'. Users should be aware of justETF's strict rate limiting. ```python from stockdex import Ticker etf = Ticker(isin="IE00B4L5Y983", security_type="etf") etf_general_info = etf.justetf_general_info ``` -------------------------------- ### Generate Sankey Charts for Cash Flow Visualization Source: https://github.com/ahnazary/stockdex/blob/main/USAGE.md This snippet demonstrates how to create a Sankey chart using the `plot_sankey_chart` function in `stockdex`. Sankey charts are used to visualize the flow of cash within a company, based on data extracted from the Yahoo Finance API. The generated chart is interactive, allowing users to hover over categories to see specific cash amounts. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") ticker.plot_sankey_chart() ``` -------------------------------- ### Generate Sankey Chart for Cash Flow Visualization Source: https://github.com/ahnazary/stockdex/blob/main/README.md This snippet demonstrates how to create a Sankey chart using the `plot_sankey_chart` function. This chart visualizes the flow of cash based on data extracted from the Yahoo Finance API, typically representing the income statement. Hovering over the chart provides detailed amounts for each category. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") ticker.plot_sankey_chart() ``` -------------------------------- ### Retrieving Comprehensive Financial Data from Yahoo Finance Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python code demonstrates how to use `stockdex` to extract a wide range of financial information from Yahoo Finance. It covers summary data, detailed financial statements (income, balance, cash flow), analyst estimates, options data (calls, puts), company profile details (executives, description, governance), shareholder information, and various financial statistics. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") # Summary including general financial information summary = ticker.yahoo_web_summary # Financial data as it is seen in the yahoo finance website income_stmt = ticker.yahoo_web_income_stmt balance_sheet = ticker.yahoo_web_balance_sheet cash_flow = ticker.yahoo_web_cashflow # Analysts and estimates analysis = ticker.yahoo_web_analysis # Data about options calls = ticker.yahoo_web_calls puts = ticker.yahoo_web_puts # Profile data key_executives = ticker.yahoo_web_key_executives description = ticker.yahoo_web_description corporate_governance = ticker.yahoo_web_corporate_governance # Data about shareholders major_holders = ticker.yahoo_web_major_holders top_institutional_holders = ticker.yahoo_web_top_institutional_holders top_mutual_fund_holders = ticker.yahoo_web_top_mutual_fund_holders # Statistics valuation_measures = ticker.yahoo_web_valuation_measures financial_highlights = ticker.yahoo_web_financial_highlights trading_information = ticker.yahoo_web_trading_information ``` -------------------------------- ### Retrieving Raw Financial Data from Macrotrends as Pandas DataFrames Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python code demonstrates how to fetch various raw financial datasets from the Macrotrends website using `stockdex`. The data, including income statements, balance sheets, cash flow, key financial ratios, and different margin types (gross, operating, EBITDA, pre-tax, net), is returned as pandas DataFrames for further analysis. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") # Financial data income_statement = ticker.macrotrends_income_statement balance_sheet = ticker.macrotrends_balance_sheet cash_flow = ticker.macrotrends_cash_flow key_financial_ratios = ticker.macrotrends_key_financial_ratios # Margins gross_margin = ticker.macrotrends_gross_margin operating_margin = ticker.macrotrends_operating_margin ebitda_margin = ticker.macrotrends_ebitda_margin pre_tax_margin = ticker.macrotrends_pre_tax_margin net_margin = ticker.macrotrends_net_margin ``` -------------------------------- ### Retrieve Raw Financial Data from Yahoo Finance API Source: https://github.com/ahnazary/stockdex/blob/main/README.md This snippet demonstrates how to use the `stockdex` package to fetch various raw financial data points from the Yahoo Finance API for a given ticker. It covers price data, current trading periods, and fundamental data like income statements, cash flow, balance sheets, and general financials, returning them as pandas DataFrames. Parameters like `range`, `dataGranularity`, `frequency`, `format`, `period1`, and `period2` can be used to refine the data. ```python from stockdex import Ticker from datetime import datetime ticker = Ticker(ticker="AAPL") # Price data (use range and dataGranularity to make range and granularity more specific) price = ticker.yahoo_api_price(range='1y', dataGranularity='1d') # Current trading period of the stock (pre-market, regular, post-market trading periods) current_trading_period = ticker.yahoo_api_current_trading_period # Fundamental data (use frequency, format, period1 and period2 to fine-tune the returned data) income_statement = ticker.yahoo_api_income_statement(frequency='quarterly') cash_flow = ticker.yahoo_api_cash_flow(format='raw') balance_sheet = ticker.yahoo_api_balance_sheet(period1=datetime(2020, 1, 1)) financials = ticker.yahoo_api_financials(period1=datetime(2022, 1, 1), period2=datetime.today()) ``` -------------------------------- ### Plotting Historical Price Data from Digrin as a Line Chart Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python snippet shows how to plot historical price data from the Digrin website using `stockdex`. For datasets with many points, the `plot_digrin_price()` function automatically generates a line chart instead of a bar chart, illustrating real and adjusted prices. ```python from stockdex import Ticker ticker = Ticker(ticker="CAT") ticker.plot_digrin_price() ``` -------------------------------- ### Retrieve Raw Historical Data from Digrin Website Source: https://github.com/ahnazary/stockdex/blob/main/README.md This snippet shows how to access comprehensive historical and non-historical stock data from the Digrin website, which often provides more extensive historical coverage than Yahoo Finance. It retrieves various data points such as dividends, payout ratios, stock splits, prices, assets vs. liabilities, free cash flow, net income, cash and debt, shares outstanding, expenses, cost of revenue, and upcoming estimated earnings, all returned as pandas DataFrames. ```python from stockdex import Ticker ticker = Ticker(ticker="AAPL") # Complete historical data of the stock in certain categories dividend = ticker.digrin_dividend payout_ratio = ticker.digrin_payout_ratio stock_splits = ticker.digrin_stock_splits price = ticker.digrin_price # Non-historical data assets_vs_liabilities = ticker.digrin_assets_vs_liabilities free_cash_flow = ticker.digrin_free_cash_flow net_income = ticker.digrin_net_income cash_and_debt = ticker.digrin_cash_and_debt shares_outstanding = ticker.digrin_shares_outstanding expenses = ticker.digrin_expenses cost_of_revenue = ticker.digrin_cost_of_revenue upcoming_estimated_earnings = ticker.digrin_upcoming_estimated_earnings # Dividend data dividend = ticker.digrin_dividend dgr3 = ticker.digrin_dgr3 dgr5 = ticker.digrin_dgr5 dgr10 = ticker.digrin_dgr10 ``` -------------------------------- ### Plot Financial Data from Yahoo Finance API using Plotly Source: https://github.com/ahnazary/stockdex/blob/main/README.md This snippet illustrates how to visualize financial data obtained from the Yahoo Finance API using `plotly`. Functions prefixed with `plot_yahoo_api_` generate interactive plots for financials, income statements, cash flow, and balance sheets. The `group_by` and `freq` parameters allow for customization of the plot's aggregation and frequency. By default, these functions open a new browser tab with the plot, but setting `show_plot=False` returns the Plotly figure object for custom handling. ```python from stockdex import Ticker ticker = Ticker(ticker="MSFT") ticker.plot_yahoo_api_financials(group_by="field") ticker.plot_yahoo_api_income_statement(group_by="timeframe") ticker.plot_yahoo_api_cash_flow(freq="quarterly") ticker.plot_yahoo_api_balance_sheet(freq="quarterly") ``` -------------------------------- ### Plotting Financial Data from Macrotrends with Plotly Source: https://github.com/ahnazary/stockdex/blob/main/README.md This Python snippet illustrates how to plot key financial statements (income statement, balance sheet, cash flow) extracted from the Macrotrends website using `stockdex` and `plotly`. Each function call generates a plot that opens in a new browser tab. ```python from stockdex import Ticker ticker = Ticker(ticker="GOOGL") ticker.plot_macrotrends_income_statement() ticker.plot_macrotrends_balance_sheet() ticker.plot_macrotrends_cash_flow() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.