<jupyter_start><jupyter_text>Downloading Market and Fundamental Data with `yfinance`  Imports & Settings<jupyter_code>import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import yfinance as yf<jupyter_output><empty_output><jupyter_text>How to work with a Ticker object<jupyter_code>symbol = 'FB'
ticker = yf.Ticker(symbol)<jupyter_output><empty_output><jupyter_text>Show ticker info<jupyter_code>pd.Series(ticker.info).head(20)<jupyter_output><empty_output><jupyter_text>Get market data<jupyter_code>data = ticker.history(period='5d',
                      interval='1m',
                      start=None,
                      end=None,
                      actions=True,
                      auto_adjust=True,
                      back_adjust=False)
data.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1612 entries, 2020-06-10 09:30:00-04:00 to 2020-06-16 12:43:16-04:00
Data columns (total 7 columns):
 #   Column        Non-Null Count  Dtype  
---  ------        --------------  -----  
 0   Open          1612 non-null   float64
 1   High          1612 non-null   float64
 2   Low           1612 non-null   float64
 3   Close         1612 non-null   float64
 4   Volume        1612 non-null   int64  
 5   Dividends     1612 non-null   int64  
 6   Stock Splits  1612 non-null   int64  
dtypes: float64(4), int64(3)
memory usage: 100.8 KB<jupyter_text>View company actions<jupyter_code># show actions (dividends, splits)
ticker.actions
ticker.dividends
ticker.splits<jupyter_output><empty_output><jupyter_text>Annual and Quarterly Financial Statement Summary<jupyter_code>ticker.financials
ticker.quarterly_financials<jupyter_output><empty_output><jupyter_text>Annual and Quarterly Balance Sheet<jupyter_code>ticker.balance_sheet
ticker.quarterly_balance_sheet<jupyter_output><empty_output><jupyter_text>Annual and Quarterly Cashflow Statement<jupyter_code>ticker.cashflow
ticker.quarterly_cashflow
ticker.earnings
ticker.quarterly_earnings<jupyter_output><empty_output><jupyter_text>Sustainability: Environmental, Social and Governance (ESG)<jupyter_code>ticker.sustainability<jupyter_output><empty_output><jupyter_text>Analyst Recommendations<jupyter_code>ticker.recommendations.info()
ticker.recommendations.tail(10)<jupyter_output><empty_output><jupyter_text>Upcoming Events<jupyter_code>ticker.calendar<jupyter_output><empty_output><jupyter_text>Option Expiration Dates<jupyter_code>ticker.options
expiration = ticker.options[0]
options = ticker.option_chain(expiration)
options.calls.info()
options.calls.head()
options.puts.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 67 entries, 0 to 66
Data columns (total 14 columns):
 #   Column             Non-Null Count  Dtype         
---  ------             --------------  -----         
 0   contractSymbol     67 non-null     object        
 1   lastTradeDate      67 non-null     datetime64[ns]
 2   strike             67 non-null     float64       
 3   lastPrice          67 non-null     float64       
 4   bid                67 non-null     float64       
 5   ask                67 non-null     float64       
 6   change             67 non-null     float64       
 7   percentChange      67 non-null     float64       
 8   volume             67 non-null     int64         
 9   openInterest       67 non-null     int64         
 10  impliedVolatility  67 non-null     float64       
 11  inTheMoney         67 non-null     bool          
 12  contractSize       67 non-null     object        
 13  currency           67 non-null     object        
dtypes: bool(1), [...]<jupyter_text>Data Download with proxy server You can use a proxy server to avoid having your IP blacklisted as illustrated below (but need an actual PROXY_SERVER).<jupyter_code>PROXY_SERVER = 'PROXY_SERVER'<jupyter_output><empty_output><jupyter_text>The following will only work with proper PROXY_SERVER...<jupyter_code># 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_balance_sheet(proxy=PROXY_SERVER)
# msft.get_cashflow(proxy=PROXY_SERVER)
# msgt.option_chain(proxy=PROXY_SERVER)<jupyter_output><empty_output><jupyter_text>Downloading multiple symbols<jupyter_code>tickers = yf.Tickers('msft aapl goog')
tickers
pd.Series(tickers.tickers.MSFT.info)
tickers.tickers.AAPL.history(period="1mo")
tickers.history(period='1mo').stack(-1)
data = yf.download("SPY AAPL", start="2020-01-01", end="2020-01-05")
data.info()
data = yf.download(
        tickers = "SPY AAPL MSFT", # list or string

        # use "period" instead of start/end
        # valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max
        # (optional, default is '1mo')
        period = "5d",

        # fetch data by interval (including intraday if period < 60 days)
        # valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo
        # (optional, default is '1d')
        interval = "1m",

        # group by ticker (to access via data['SPY'])
        # (optional, default is 'column')
        group_by = 'ticker',

        # adjust all OHLC automatically
        # (optional, default is False)
        auto_adjust = True,

        # download pre/post regular market hours data
        # (optional, default is False)
        prepost = True,

        # use threads for mass downloading? (True/False/Integer)
        # (optional, default is True)
        threads = True,

        # proxy URL scheme use use when downloading?
        # (optional, default is None)
        proxy = None
    )
data.info()
from pandas_datareader import data as pdr

import yfinance as yf
yf.pdr_override()

# download dataframe
data = pdr.get_data_yahoo('SPY',
                          start='2017-01-01',
                          end='2019-04-30',
                          auto_adjust=False)
# auto_adjust = True
data.tail()
# auto_adjust = False
data.tail()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10041631973355537, 'fraction_numerical': 0.041465445462114905, 'mean_word_length': 2.894941634241245, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '99687', 'license': 'MIT', 'n_tokens_mistral': 2143, 'n_tokens_neox': 1970, 'n_words': 417, 'path': '02_market_and_fundamental_data/03_data_providers/02_yfinance_demo.ipynb', 'repo_name': 'driscolljt/Machine-Learning-for-Algorithmic-Trading-Second-Edition_Original', 'size': '6005'}