From ac14a94f842a77f5cf624b81b758ef85033b143b Mon Sep 17 00:00:00 2001 From: Zach Coriarty Date: Sun, 9 Jan 2022 10:42:01 -0500 Subject: [PATCH 1/2] Filled out .rst for FRED, FA, IEX, quandl, stooq --- Source/FRED.rst | 273 +++++------------------------- Source/FundamentalAnalysis.rst | 105 ++++++++++++ Source/Stooq.rst | 281 +++---------------------------- Source/iex.rst | 80 +++++++++ Source/quandl.rst | 297 +++++++-------------------------- 5 files changed, 309 insertions(+), 727 deletions(-) create mode 100644 Source/FundamentalAnalysis.rst create mode 100644 Source/iex.rst diff --git a/Source/FRED.rst b/Source/FRED.rst index 186e7f3..ab0a343 100644 --- a/Source/FRED.rst +++ b/Source/FRED.rst @@ -13,160 +13,67 @@ To Do: - Provide a link to the jupyter notebook for this. Fetching the data ---------------- +----------------- - `1. Historical Price and Volume for 1 Stock. <#1>`__ -- `2. Time Periods <#2>`__ -- `3. Frequency <#3>`__ -- `4. Split and Dividends <#4>`__ -- `5. Many Stocks <#5>`__ -- `6. Finanical Indices <#6>`__ -- `7. Currencies <#7>`_ -- `8. Crypto <#8>`_ -- `9. Mutual Funds <#9>`_ -- `10. Treasury <#10>`_ -- `11. Stock Fundamentals <#11>`_ -- `12. Financials <#12>`_ -- `13. Put Call Options <#13>`_ -- `14. Stream Real Time Data <#14>`__ - -.. code:: ipython3 - - import numpy as np - import yfinance as yf - -Historical Price and Volume for 1 Stock ----------- - -.. code:: ipython3 - import numpy as np - import yfinance as yf - ticker = 'GE' - yf.download(ticker) - -Adding Time Periods ----------- - -.. code:: ipython3 - - yf.download(ticker, start = "2014-01-01", end = "2018-12-31") - GE = yf.download(ticker, start = "2014-01-01", end = "2018-12-31") - GE.info() - - -.. parsed-literal:: - - - DatetimeIndex: 1257 entries, 2014-01-02 to 2018-12-28 - Data columns (total 6 columns): - Open 1257 non-null float64 - High 1257 non-null float64 - Low 1257 non-null float64 - Close 1257 non-null float64 - Adj Close 1257 non-null float64 - Volume 1257 non-null int64 - dtypes: float64(5), int64(1) - memory usage: 68.7 KB - +- `2. Many Stocks <#2>`__ +- `3. Currencies <#3>`_ +- `4. Crypto <#4>`_ +- `5. Mutual Funds <#5>`_ +- `6. Treasury <#6>`_ .. code:: ipython3 - yf.download(ticker, period = "ytd") - yf.download(ticker, period = "1mo") - yf.download(ticker, period = "5d") - yf.download(ticker, period = "10y") - - -Frequency Setting ----------- - -.. code:: ipython3 - - yf.download('GE',period='1mo',interval='1h') - yf.download('GE',period='1mo',interval='5m') - GE = yf.download('GE',period='5d',interval='5m') - #Pre or post market data - GE=yf.download('GE',prepost=True,period='5d',interval='5m') - -Stock Split and dividends ----------- - -.. code:: ipython3 - - ticker = "AAPL" - # action = True for dividend and Stock Split - AAPL = yf.download(ticker, period="10y", actions = True) - AAPL.head() - -.. code:: ipython3 - - AAPL[AAPL["Dividends"]>0] - AAPL.loc["2019-08-05":"2019-08-15"].diff() - AAPL[AAPL["Stock Splits"] > 0] - ticker = ['GE', 'AAPL','FB'] - yf.download(ticker, period="5y") -.. code:: ipython3 - - stock=yf.download(ticker, period="5y").Close + import pandas_datareader as web + import pandas as pd + from matplotlib import pyplot as plt + import seaborn as sns + from datetime import datetime + # specify time periods + start = datetime(2010,1,1) + end = datetime(2030,1,1) -FInancial Indices - --------------- + SP500 = web.DataReader('SP500','fred',start,end) -.. code:: ipython3 - - index = ['^DJI', '^GSPC'] +Historical Price for 1 Stock +---------------------------- .. code:: ipython3 + + sns.set() #run this to overide matplotlib + SP500['SP500'].plot(title='S&P 500 Price',figsize=(20, 6)) - stock = yf.download(index,period='10y').Close - - -.. code:: ipython3 + #Use the below to save the chart as an image file + plt.savefig('s&p500.png') - #Total Return - index = ['^DJITR', '^SP500TR'] +Many Stocks +----------- .. code:: ipython3 - indexes = yf.download(index,period='10y').Close - - - + mkt_cap = web.DataReader(['WILLLRGCAPGR', 'WILLSMLCAP'], 'fred',start,end) + mkt_cap.plot(title = 'Wilshire Large-Cap compared to Small-Cap', secondary_y = "DGS10", figsize=(20, 6)) + plt.tight_layout() + Currencies --------------- .. code:: ipython3 - #Tickers - ticker1 = "EURUSD=X" - ticker2 = "USDEUR=X" - -.. code:: ipython3 - - yf.download(ticker1,period='5y') - -.. code:: ipython3 - - yf.download(ticker2,period='5y') - - - - - + er = web.DataReader('AEXCHUS', 'fred',start,end) + er.plot(title = 'Chinese Yuan Renminbi to U.S. Dollar Spot Exchange Rate', secondary_y = "DGS10", figsize=(20, 6)) + plt.tight_layout() Crypto --------------- .. code:: ipython3 - #Tickers - ticker1 = ["BTC-USD", "ETH-USD"] - -.. code:: ipython3 - - data = yf.download(ticker1,start='2019-08-01',end='2020-05-01') + btc = web.DataReader('CBBTCUSD', 'fred',start,end) + btc.plot(title = 'Bitcoin Price', secondary_y = "DGS10", figsize=(20, 6)) + plt.tight_layout() @@ -176,13 +83,9 @@ Mutual Funds .. code:: ipython3 - #Tickers - #20+Y Treasury Bobd ETF and Vivoldi Multi-Strategy Fund Class - ticker1 = ["TLT", "OMOIX"] - -.. code:: ipython3 - - data = yf.download(ticker1,start='2019-08-01',end='2020-05-01') + mf = web.DataReader('BOGZ1LM193064005Q', 'fred',start,end) + mf.plot(title = 'Households; Corporate Equities and Mutual Fund Shares; Asset, Market Value Levels', secondary_y = "DGS10", figsize=(20, 6)) + plt.tight_layout() @@ -192,103 +95,7 @@ Treasury Rates .. code:: ipython3 - #10Y and 5Y Treasury Rates - ticker1 = ["^TNX", "^FVX"] - -.. code:: ipython3 - - data = yf.download(ticker1,period="5y") - - -Stock Fundamentals ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.ticker - - -.. parsed-literal:: - - 'DIS' - -.. code:: ipython3 - - data=dis.history() - -.. code:: ipython3 - - ticker = ["MSFT","FB"] - -.. code:: ipython3 - - for i in ticker: - df.loc["{}".format(i)] = pd.Series(yf.Ticker(i).info) - -.. code:: ipython3 - - df.info() - -Import Financials ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.balance_sheet - -.. code:: ipython3 - - dis.financials - -.. code:: ipython3 - - dis.cashflow - -Put Call Option ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.option_chain() - -.. code:: ipython3 - - calls = dis.option_chain()[0] - calls - -.. code:: ipython3 - - puts = dis.option_chain()[1] - puts - - ### Stream Realtime Data - -.. code:: ipython3 - - import time - -.. code:: ipython3 + treasury = web.DataReader('TB3MS', 'fred',start,end) + treasury.plot(title = '3-Month Treasury Bill Secondary Market Rate', secondary_y = "DGS10", figsize=(20, 6)) + plt.tight_layout() - ticker1 ="EURUSD=X" - data = yf.download(ticker1,interval = '1m', period='1d') - print(data.index[-1], data.iloc[-1,3]) - #Every 5 second data corresponding to 5 seconds - while True: - time.sleep(5) - data = yf.download(ticker1,interval = '1m', period='1d') - print(data.index[-1], data.iloc[-1,3]) diff --git a/Source/FundamentalAnalysis.rst b/Source/FundamentalAnalysis.rst new file mode 100644 index 0000000..c064aa5 --- /dev/null +++ b/Source/FundamentalAnalysis.rst @@ -0,0 +1,105 @@ +.. _FundamentalAnalysis: + +FundamentalAnalysis +=================== + + +Fetching the data +----------------- + +- `1. List all Commands <#1>`__ +- `2. Historical Price and Volume for 1 Stock. <#2>`__ +- `3. Finanical Ratios <#3>`__ +- `4. Stock Fundamentals <#4>`__ +- `5. Financials <#5>`__ +- `6. Key Metrics <#6>`__ + +.. code:: ipython3 + + import FundamentalAnalysis as fa + import financedatabase as fd + import pandas as pd + + ticker = "TSLA" + api_key = "your api key" + +List all Commands +----------------- + +.. code:: ipython3 + + # Options: 'cryptocurrencies', 'currencies', 'equities', 'etfs' or 'funds' + options = fd.show_options('cryptocurrencies', equities_selection=None, country=None, sector=None, industry=None) + options = pd.DataFrame(options) + options + +.. code:: ipython3 + + # Show the available companies + companies = fa.available_companies(api_key) + companies.sort_values('symbol') + +Historical Price and Volume for 1 Stock +--------------------------------------- + +.. code:: ipython3 + + # General stock data + stock_data = fa.stock_data(ticker, period="ytd", interval="1d") + + # Detailed stock data + stock_data_detailed = fa.stock_data_detailed(ticker, api_key, begin="2000-01-01", end="2020-01-01") + stock_data_detailed + +Financial Ratios +---------------- + +.. code:: ipython3 + + # Premium Feature + # Large set of in-depth ratios + financial_ratios_annually = fa.financial_ratios(ticker, api_key, period="annual") + financial_ratios_quarterly = fa.financial_ratios(ticker, api_key, period="quarter") + +Stock Fundamentals +------------------ + +.. code:: ipython3 + + profile = fa.profile(ticker, api_key) + profile + +Import Financials +----------------- + +.. code:: ipython3 + + ticker ="DIS" + +.. code:: ipython3 + + # Balance Sheet statements + balance_sheet_annually = fa.balance_sheet_statement(ticker, api_key, period="annual") + balance_sheet_quarterly = fa.balance_sheet_statement(ticker, api_key, period="quarter") + +.. code:: ipython3 + + # Income Statements + income_statement_annually = fa.income_statement(ticker, api_key, period="annual") + income_statement_quarterly = fa.income_statement(ticker, api_key, period="quarter") + +.. code:: ipython3 + + # Cash Flow Statements + cash_flow_statement_annually = fa.cash_flow_statement(ticker, api_key, period="annual") + cash_flow_statement_quarterly = fa.cash_flow_statement(ticker, api_key, period="quarter") + +Key Metrics +----------- + +.. code:: ipython3 + + # Premium Feature + # Key Metrics + key_metrics_annually = fa.key_metrics(ticker, api_key, period="annual") + key_metrics_quarterly = fa.key_metrics(ticker, api_key, period="quarter") diff --git a/Source/Stooq.rst b/Source/Stooq.rst index 535d6ec..6679e25 100644 --- a/Source/Stooq.rst +++ b/Source/Stooq.rst @@ -13,282 +13,55 @@ To Do: - Provide a link to the jupyter notebook for this. Fetching the data ---------------- +----------------- - `1. Historical Price and Volume for 1 Stock. <#1>`__ - `2. Time Periods <#2>`__ -- `3. Frequency <#3>`__ -- `4. Split and Dividends <#4>`__ -- `5. Many Stocks <#5>`__ -- `6. Finanical Indices <#6>`__ -- `7. Currencies <#7>`_ -- `8. Crypto <#8>`_ -- `9. Mutual Funds <#9>`_ -- `10. Treasury <#10>`_ -- `11. Stock Fundamentals <#11>`_ -- `12. Financials <#12>`_ -- `13. Put Call Options <#13>`_ -- `14. Stream Real Time Data <#14>`__ - -.. code:: ipython3 - - import numpy as np - import yfinance as yf - -Historical Price and Volume for 1 Stock ----------- - -.. code:: ipython3 - import numpy as np - import yfinance as yf - ticker = 'GE' - yf.download(ticker) - -Adding Time Periods ----------- - -.. code:: ipython3 - - yf.download(ticker, start = "2014-01-01", end = "2018-12-31") - GE = yf.download(ticker, start = "2014-01-01", end = "2018-12-31") - GE.info() - - -.. parsed-literal:: - - - DatetimeIndex: 1257 entries, 2014-01-02 to 2018-12-28 - Data columns (total 6 columns): - Open 1257 non-null float64 - High 1257 non-null float64 - Low 1257 non-null float64 - Close 1257 non-null float64 - Adj Close 1257 non-null float64 - Volume 1257 non-null int64 - dtypes: float64(5), int64(1) - memory usage: 68.7 KB - - - -.. code:: ipython3 - - yf.download(ticker, period = "ytd") - yf.download(ticker, period = "1mo") - yf.download(ticker, period = "5d") - yf.download(ticker, period = "10y") - - -Frequency Setting ----------- - -.. code:: ipython3 - - yf.download('GE',period='1mo',interval='1h') - yf.download('GE',period='1mo',interval='5m') - GE = yf.download('GE',period='5d',interval='5m') - #Pre or post market data - GE=yf.download('GE',prepost=True,period='5d',interval='5m') - -Stock Split and dividends ----------- - -.. code:: ipython3 - - ticker = "AAPL" - # action = True for dividend and Stock Split - AAPL = yf.download(ticker, period="10y", actions = True) - AAPL.head() - -.. code:: ipython3 - - AAPL[AAPL["Dividends"]>0] - AAPL.loc["2019-08-05":"2019-08-15"].diff() - AAPL[AAPL["Stock Splits"] > 0] - ticker = ['GE', 'AAPL','FB'] - yf.download(ticker, period="5y") -.. code:: ipython3 +- `3. Mutual Funds <#3>`_ - stock=yf.download(ticker, period="5y").Close -FInancial Indices - --------------- +Replace the ticker variable to whatever you would like from: https://stooq.com/q/?s=btc.v .. code:: ipython3 - index = ['^DJI', '^GSPC'] - -.. code:: ipython3 - - stock = yf.download(index,period='10y').Close - - -.. code:: ipython3 - - #Total Return - index = ['^DJITR', '^SP500TR'] - -.. code:: ipython3 - - indexes = yf.download(index,period='10y').Close - - - -Currencies ---------------- - -.. code:: ipython3 - - #Tickers - ticker1 = "EURUSD=X" - ticker2 = "USDEUR=X" - -.. code:: ipython3 + import pandas as pd + import numpy as np + import pandas_datareader.data as web + from datetime import datetime - yf.download(ticker1,period='5y') +Historical Price and Volume for 1 Stock +--------------------------------------- .. code:: ipython3 + + # adjust the variables below + ticker = 'AAPL' - yf.download(ticker2,period='5y') - - + df = web.DataReader(ticker, 'stooq') + df - - - -Crypto ---------------- - -.. code:: ipython3 - - #Tickers - ticker1 = ["BTC-USD", "ETH-USD"] +Adding Time Periods +------------------- .. code:: ipython3 - data = yf.download(ticker1,start='2019-08-01',end='2020-05-01') - - + # adjust the variables below + ticker = 'AAPL' + start = datetime(1990,1,1) + end = datetime(2020,1,1) + df = web.DataReader(ticker, 'stooq', start, end) + df Mutual Funds --------------- .. code:: ipython3 - #Tickers - #20+Y Treasury Bobd ETF and Vivoldi Multi-Strategy Fund Class - ticker1 = ["TLT", "OMOIX"] - -.. code:: ipython3 - - data = yf.download(ticker1,start='2019-08-01',end='2020-05-01') - - - - -Treasury Rates ---------------- - -.. code:: ipython3 - - #10Y and 5Y Treasury Rates - ticker1 = ["^TNX", "^FVX"] - -.. code:: ipython3 - - data = yf.download(ticker1,period="5y") - - -Stock Fundamentals ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.ticker - - -.. parsed-literal:: - - 'DIS' - -.. code:: ipython3 - - data=dis.history() - -.. code:: ipython3 - - ticker = ["MSFT","FB"] - -.. code:: ipython3 - - for i in ticker: - df.loc["{}".format(i)] = pd.Series(yf.Ticker(i).info) - -.. code:: ipython3 - - df.info() - -Import Financials ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.balance_sheet - -.. code:: ipython3 - - dis.financials - -.. code:: ipython3 - - dis.cashflow - -Put Call Option ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.option_chain() - -.. code:: ipython3 - - calls = dis.option_chain()[0] - calls - -.. code:: ipython3 - - puts = dis.option_chain()[1] - puts - - ### Stream Realtime Data - -.. code:: ipython3 - - import time - -.. code:: ipython3 + ticker = 'SPY' + start = datetime(1990,1,1) + end = datetime(2020,1,1) - ticker1 ="EURUSD=X" - data = yf.download(ticker1,interval = '1m', period='1d') - print(data.index[-1], data.iloc[-1,3]) - #Every 5 second data corresponding to 5 seconds - while True: - time.sleep(5) - data = yf.download(ticker1,interval = '1m', period='1d') - print(data.index[-1], data.iloc[-1,3]) + df = web.DataReader(ticker, 'stooq', start, end) + df diff --git a/Source/iex.rst b/Source/iex.rst new file mode 100644 index 0000000..ecea00e --- /dev/null +++ b/Source/iex.rst @@ -0,0 +1,80 @@ +.. _iex: + +IEX +============= + +Fetching the data +----------------- + +- `1. Show all Functions <#1>`__ +- `2. Historical Price and Volume for 1 Stock <#2>`__ +- `3. Time Periods or Frequency<#3>`__ +- `4. Split and Dividends <#4>`__ +- `5. News <#5>`__ +- `6. Stream Real Time Data <#6>`__ + +.. code:: ipython3 + + import pandas as pd + import pyEX as p + import requests + +Show all functions +------------------ + +The following command shows all functions available, all of which follow the same structure as the examples below + +- `Some require a premium substription` + +.. code:: ipython3 + + [_ for _ in dir(p) if _.endswith('DF')] + +Historical Price and Volume for 1 Stock +--------------------------------------- + +.. code:: ipython3 + + history = conn.chartDF(ticker) + history + + + +Adding Time Periods or Frequency +-------------------------------- + +.. code:: ipython3 + + timeframe = '5d' # up to 15 years, or minute-by-minute for the last 30 days + history = conn.chartDF(ticker, timeframe=timeframe) + history + +Stock Split and dividends +------------------------- + +.. code:: ipython3 + + # premium feature + timeframe = '6m' + dividends = conn.dividendsDF(ticker) + dividends + + +News +---- + +.. code:: ipython3 + + news = conn.newsDF(ticker, count=10) + news + +Stream Realtime Data +-------------------- + +.. code:: ipython3 + + ticker = 'GE' + + real_time = conn.quote(ticker) + real_time = pd.DataFrame(real_time, index = ['value']).T + real_time diff --git a/Source/quandl.rst b/Source/quandl.rst index c2f8264..e711ff7 100644 --- a/Source/quandl.rst +++ b/Source/quandl.rst @@ -34,170 +34,80 @@ Fetching the data - `3. Frequency <#3>`__ - `4. Split and Dividends <#4>`__ - `5. Many Stocks <#5>`__ -- `6. Finanical Indices <#6>`__ -- `7. Currencies <#7>`_ -- `8. Crypto <#8>`_ -- `9. Mutual Funds <#9>`_ -- `10. Treasury <#10>`_ -- `11. Stock Fundamentals <#11>`_ -- `12. Financials <#12>`_ -- `13. Put Call Options <#13>`_ -- `14. Stream Real Time Data <#14>`__ +- `6. Crypto <#6>`_ +- `7. Mutual Funds <#7>`_ +- `8. Treasury <#8>`_ +- `9. Stock Fundamentals <#9>`_ +- `10. Put Call Options <#10>`_ .. code:: ipython3 - import quandl + import quandl + import pandas as pd + import numpy as np + from datetime import datetime + from matplotlib import pyplot as plt + import seaborn as sns - # To get your API key, sign up for a free Quandl account. - # Then, you can find your API key on Quandl account settings page. - QUANDL_API_KEY = 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY' + # To get your API key, sign up for a free Quandl account. + # Then, you can find your API key on Quandl account settings page. + QUANDL_API_KEY = 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY' - # This is to prompt you to change the Quandl Key - if QUANDL_API_KEY == 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY': - raise Exception("Please provide a valid Quandl API key!") + # This is to prompt you to change the Quandl Key + if QUANDL_API_KEY == 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY': + raise Exception("Please provide a valid Quandl API key!") + quandl.ApiConfig.api_key = QUANDL_API_KEY - # Set the start and end date - start_date = '1990-01-01' - end_date = '2018-03-01' + # Set the start and end date + start_date = '1990-01-01' + end_date = '2018-03-01' - # Set the ticker name - ticker = 'AMZN' + # Set the ticker name + ticker = 'AMZN' - # Feth the data - data = quandl.get('WIKI/'+ticker, - start_date=start_date, - end_date=end_date, - api_key=QUANDL_API_KEY) + # Feth the data + data = quandl.get('WIKI/'+ticker, + start_date=start_date, + end_date=end_date, + api_key=QUANDL_API_KEY) - # Print the first 5 rows of the dataframe -data.head() + # Print the first 5 rows of the dataframe + data.head() + sns.set() Historical Price and Volume for 1 Stock ----------- +--------------------------------------- .. code:: ipython3 - import numpy as np - import yfinance as yf - ticker = 'GE' - yf.download(ticker) - -Adding Time Periods ----------- - -.. code:: ipython3 - - yf.download(ticker, start = "2014-01-01", end = "2018-12-31") - GE = yf.download(ticker, start = "2014-01-01", end = "2018-12-31") - GE.info() - - -.. parsed-literal:: - - - DatetimeIndex: 1257 entries, 2014-01-02 to 2018-12-28 - Data columns (total 6 columns): - Open 1257 non-null float64 - High 1257 non-null float64 - Low 1257 non-null float64 - Close 1257 non-null float64 - Adj Close 1257 non-null float64 - Volume 1257 non-null int64 - dtypes: float64(5), int64(1) - memory usage: 68.7 KB + data = quandl.get('WIKI/'+ticker) + data.head() +Adding Time Periods +------------------- .. code:: ipython3 - yf.download(ticker, period = "ytd") - yf.download(ticker, period = "1mo") - yf.download(ticker, period = "5d") - yf.download(ticker, period = "10y") - + data = quandl.get('WIKI/'+ticker, + start_date=start, + end_date=end) + data.head() -Frequency Setting ----------- - -.. code:: ipython3 - - yf.download('GE',period='1mo',interval='1h') - yf.download('GE',period='1mo',interval='5m') - GE = yf.download('GE',period='5d',interval='5m') - #Pre or post market data - GE=yf.download('GE',prepost=True,period='5d',interval='5m') Stock Split and dividends ----------- +------------------------- .. code:: ipython3 - ticker = "AAPL" - # action = True for dividend and Stock Split - AAPL = yf.download(ticker, period="10y", actions = True) - AAPL.head() - -.. code:: ipython3 - - AAPL[AAPL["Dividends"]>0] - AAPL.loc["2019-08-05":"2019-08-15"].diff() - AAPL[AAPL["Stock Splits"] > 0] - ticker = ['GE', 'AAPL','FB'] - yf.download(ticker, period="5y") -.. code:: ipython3 - - stock=yf.download(ticker, period="5y").Close - - -FInancial Indices - --------------- - -.. code:: ipython3 - - index = ['^DJI', '^GSPC'] - -.. code:: ipython3 - - stock = yf.download(index,period='10y').Close - - -.. code:: ipython3 - - #Total Return - index = ['^DJITR', '^SP500TR'] - -.. code:: ipython3 - - indexes = yf.download(index,period='10y').Close - - - -Currencies ---------------- - -.. code:: ipython3 - - #Tickers - ticker1 = "EURUSD=X" - ticker2 = "USDEUR=X" - -.. code:: ipython3 - - yf.download(ticker1,period='5y') - -.. code:: ipython3 - - yf.download(ticker2,period='5y') - - - - + sp = quandl.get('YALE/SPCOMP', start_date='2015-04-01', end_date='2021-10-01') + sp[['Dividend', 'Real Dividend']] Crypto @@ -205,134 +115,41 @@ Crypto .. code:: ipython3 - #Tickers - ticker1 = ["BTC-USD", "ETH-USD"] - -.. code:: ipython3 - - data = yf.download(ticker1,start='2019-08-01',end='2020-05-01') - - - + # bitcoin price + btc = quandl.get('BCHAIN/MKPRU', start_date='2020-12-29', end_date='2021-12-29') + btc Mutual Funds --------------- .. code:: ipython3 - #Tickers - #20+Y Treasury Bobd ETF and Vivoldi Multi-Strategy Fund Class - ticker1 = ["TLT", "OMOIX"] - -.. code:: ipython3 - - data = yf.download(ticker1,start='2019-08-01',end='2020-05-01') - - - + # Mutual Fund Assets to GDP for World + mf = quandl.get('FRED/DDDI071WA156NWDB', start_date='1980-04-01', end_date='2020-10-01') + mf.plot(title = 'Mutual Fund Assets to GDP', figsize=(20, 6)) Treasury Rates --------------- .. code:: ipython3 - #10Y and 5Y Treasury Rates - ticker1 = ["^TNX", "^FVX"] - -.. code:: ipython3 - - data = yf.download(ticker1,period="5y") + mf = quandl.get('USTREASURY/REALLONGTERM', start_date='2000-04-01', end_date='2020-10-01') + mf.plot(title = 'Treasury Real Long-Term Rates', figsize=(20, 6)) Stock Fundamentals ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) +------------------ .. code:: ipython3 - dis.ticker - - -.. parsed-literal:: - - 'DIS' - -.. code:: ipython3 - - data=dis.history() - -.. code:: ipython3 - - ticker = ["MSFT","FB"] - -.. code:: ipython3 - - for i in ticker: - df.loc["{}".format(i)] = pd.Series(yf.Ticker(i).info) - -.. code:: ipython3 - - df.info() - -Import Financials ---------------- - -.. code:: ipython3 - - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.balance_sheet - -.. code:: ipython3 - - dis.financials - -.. code:: ipython3 - - dis.cashflow + sp = quandl.get('YALE/SPCOMP', start_date='2015-04-01', end_date='2021-10-01') + sp Put Call Option --------------- .. code:: ipython3 + + fo = quandl.get('CFTC/1170E1_FO_ALL', start_date='2015-04-01', end_date='2021-10-01') + fo - ticker ="DIS" - dis = yf.Ticker(ticker) - -.. code:: ipython3 - - dis.option_chain() - -.. code:: ipython3 - - calls = dis.option_chain()[0] - calls - -.. code:: ipython3 - - puts = dis.option_chain()[1] - puts - - ### Stream Realtime Data - -.. code:: ipython3 - - import time - -.. code:: ipython3 - - ticker1 ="EURUSD=X" - data = yf.download(ticker1,interval = '1m', period='1d') - print(data.index[-1], data.iloc[-1,3]) - #Every 5 second data corresponding to 5 seconds - while True: - time.sleep(5) - data = yf.download(ticker1,interval = '1m', period='1d') - print(data.index[-1], data.iloc[-1,3]) From 05a76e5a9af5b6a9123ac574c66d623027d51c73 Mon Sep 17 00:00:00 2001 From: Zach Coriarty Date: Mon, 10 Jan 2022 15:51:17 -0500 Subject: [PATCH 2/2] alphavantage links added --- JupyterNotebooks/Alphavantage.ipynb | 438 +++++----------------------- Source/Alphavantage.rst | 66 ++++- 2 files changed, 119 insertions(+), 385 deletions(-) diff --git a/JupyterNotebooks/Alphavantage.ipynb b/JupyterNotebooks/Alphavantage.ipynb index 7abd8aa..af3d799 100644 --- a/JupyterNotebooks/Alphavantage.ipynb +++ b/JupyterNotebooks/Alphavantage.ipynb @@ -73,6 +73,13 @@ "key = \"AAUUBAYEDCI353AC\"" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Historic Stock Price and Volume" + ] + }, { "cell_type": "code", "execution_count": 27, @@ -244,7 +251,18 @@ } ], "source": [ - "data" + "data = {\n", + " \"function\": \"DIGITAL_CURRENCY_DAILY\", # WEEKLY, MONTHLY possible\n", + " \"symbol\": \"ETH\",\n", + " \"market\": 'CNY',\n", + " \"apikey\": key\n", + " }\n", + "r = requests.get(url, params=data)\n", + "data = r.json()\n", + "crypto_df = pd.DataFrame(data['Time Series (Digital Currency Daily)']).T.reset_index()\n", + "crypto_df = crypto_df.rename(columns={\"index\": \"Date\"})\n", + "crypto_df['Date'] = pd.to_datetime(crypto_df['Date'])\n", + "crypto_df " ] }, { @@ -367,7 +385,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Live Updates" + "### Realtime Data" ] }, { @@ -1236,6 +1254,24 @@ "data = r.json()\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data = {\n", + " \"function\": \"CURRENCY_EXCHANGE_RATE\", # WEEKLY, MONTHLY possible\n", + " \"from_currency\": \"ETH\",\n", + " \"to_currency\": 'USD',\n", + " \"apikey\": key\n", + " }\n", + "r = requests.get(url, params=data)\n", + "data = r.json()\n", + "crypto_df = pd.DataFrame(data['Realtime Currency Exchange Rate'], index=[0]).T\n", + "crypto_df" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -2314,377 +2350,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Historic Data" + "### Treasury Yield" ] }, { "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Date1a. open (CNY)1b. open (USD)2a. high (CNY)2b. high (USD)3a. low (CNY)3b. low (USD)4a. close (CNY)4b. close (USD)5. volume6. market cap (USD)
02021-12-2725883.315472004063.5700000025990.961712004080.4700000025780.127952004047.3700000025954.400208004074.7300000014823.9076000014823.90760000
12021-12-2626079.435456004094.3600000026147.208000004105.0000000025478.400000004000.0000000025883.251776004063.56000000189309.25500000189309.25500000
22021-12-2525773.630960004046.3500000026356.831536004137.9100000025597.001952004018.6200000026082.429168004094.83000000208126.88050000208126.88050000
32021-12-2426188.037136004111.4100000026337.276864004134.8400000025587.766032004017.1700000025773.694656004046.36000000230833.16610000230833.16610000
42021-12-2325347.886896003979.5100000026433.840000004150.0000000024798.317808003893.2300000026188.037136004111.41000000380207.81660000380207.81660000
....................................
9952019-04-071054.55097600165.560000001117.41892800175.430000001044.99657600164.060000001109.64801600174.21000000465507.52497000465507.52497000
9962019-04-061049.96486400164.840000001100.47579200172.770000001014.04032000159.200000001054.16880000165.50000000528168.33297000528168.33297000
9972019-04-051002.12916800157.330000001069.00996800167.83000000993.27542400155.940000001049.51899200164.77000000516070.34553000516070.34553000
9982019-04-041018.88121600159.960000001044.61440000164.00000000973.27488000152.800000001002.32025600157.36000000686080.95248000686080.95248000
9992019-04-031039.90089600163.260000001132.57857600177.81000000950.53540800149.230000001018.88121600159.960000001345344.538450001345344.53845000
\n", - "

1000 rows × 11 columns

\n", - "
" - ], - "text/plain": [ - " Date 1a. open (CNY) 1b. open (USD) 2a. high (CNY) 2b. high (USD) \\\n", - "0 2021-12-27 25883.31547200 4063.57000000 25990.96171200 4080.47000000 \n", - "1 2021-12-26 26079.43545600 4094.36000000 26147.20800000 4105.00000000 \n", - "2 2021-12-25 25773.63096000 4046.35000000 26356.83153600 4137.91000000 \n", - "3 2021-12-24 26188.03713600 4111.41000000 26337.27686400 4134.84000000 \n", - "4 2021-12-23 25347.88689600 3979.51000000 26433.84000000 4150.00000000 \n", - ".. ... ... ... ... ... \n", - "995 2019-04-07 1054.55097600 165.56000000 1117.41892800 175.43000000 \n", - "996 2019-04-06 1049.96486400 164.84000000 1100.47579200 172.77000000 \n", - "997 2019-04-05 1002.12916800 157.33000000 1069.00996800 167.83000000 \n", - "998 2019-04-04 1018.88121600 159.96000000 1044.61440000 164.00000000 \n", - "999 2019-04-03 1039.90089600 163.26000000 1132.57857600 177.81000000 \n", - "\n", - " 3a. low (CNY) 3b. low (USD) 4a. close (CNY) 4b. close (USD) \\\n", - "0 25780.12795200 4047.37000000 25954.40020800 4074.73000000 \n", - "1 25478.40000000 4000.00000000 25883.25177600 4063.56000000 \n", - "2 25597.00195200 4018.62000000 26082.42916800 4094.83000000 \n", - "3 25587.76603200 4017.17000000 25773.69465600 4046.36000000 \n", - "4 24798.31780800 3893.23000000 26188.03713600 4111.41000000 \n", - ".. ... ... ... ... \n", - "995 1044.99657600 164.06000000 1109.64801600 174.21000000 \n", - "996 1014.04032000 159.20000000 1054.16880000 165.50000000 \n", - "997 993.27542400 155.94000000 1049.51899200 164.77000000 \n", - "998 973.27488000 152.80000000 1002.32025600 157.36000000 \n", - "999 950.53540800 149.23000000 1018.88121600 159.96000000 \n", - "\n", - " 5. volume 6. market cap (USD) \n", - "0 14823.90760000 14823.90760000 \n", - "1 189309.25500000 189309.25500000 \n", - "2 208126.88050000 208126.88050000 \n", - "3 230833.16610000 230833.16610000 \n", - "4 380207.81660000 380207.81660000 \n", - ".. ... ... \n", - "995 465507.52497000 465507.52497000 \n", - "996 528168.33297000 528168.33297000 \n", - "997 516070.34553000 516070.34553000 \n", - "998 686080.95248000 686080.95248000 \n", - "999 1345344.53845000 1345344.53845000 \n", - "\n", - "[1000 rows x 11 columns]" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data = {\n", - " \"function\": \"DIGITAL_CURRENCY_DAILY\", # WEEKLY, MONTHLY possible\n", - " \"symbol\": \"ETH\",\n", - " \"market\": 'CNY',\n", - " \"apikey\": key\n", - " }\n", - "r = requests.get(url, params=data)\n", - "data = r.json()\n", - "crypto_df = pd.DataFrame(data['Time Series (Digital Currency Daily)']).T.reset_index()\n", - "crypto_df = crypto_df.rename(columns={\"index\": \"Date\"})\n", - "crypto_df['Date'] = pd.to_datetime(crypto_df['Date'])\n", - "crypto_df\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exchange Rates\n" - ] - }, - { - "cell_type": "code", - "execution_count": 98, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
0
1. From_Currency CodeETH
2. From_Currency NameEthereum
3. To_Currency CodeUSD
4. To_Currency NameUnited States Dollar
5. Exchange Rate4095.02000000
6. Last Refreshed2021-12-27 18:57:01
7. Time ZoneUTC
8. Bid Price4095.29000000
9. Ask Price4095.30000000
\n", - "
" - ], - "text/plain": [ - " 0\n", - "1. From_Currency Code ETH\n", - "2. From_Currency Name Ethereum\n", - "3. To_Currency Code USD\n", - "4. To_Currency Name United States Dollar\n", - "5. Exchange Rate 4095.02000000\n", - "6. Last Refreshed 2021-12-27 18:57:01\n", - "7. Time Zone UTC\n", - "8. Bid Price 4095.29000000\n", - "9. Ask Price 4095.30000000" - ] - }, - "execution_count": 98, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "data = {\n", - " \"function\": \"CURRENCY_EXCHANGE_RATE\", # WEEKLY, MONTHLY possible\n", - " \"from_currency\": \"ETH\",\n", - " \"to_currency\": 'USD',\n", + "treasury_yield = {\n", + " \"function\": \"TREASURY_YIELD\",\n", + " \"interval\": \"weekly\", # daily, monthly\n", + " \"maturity\": \"3month\", # OPTIONAL 5year, 10year, 30year\n", " \"apikey\": key\n", - " }\n", - "r = requests.get(url, params=data)\n", - "data = r.json()\n", - "crypto_df = pd.DataFrame(data['Realtime Currency Exchange Rate'], index=[0]).T\n", - "crypto_df" + "}" ] }, { @@ -2806,12 +2486,7 @@ " \"interval\": \"annual\", # quarterly\n", " \"apikey\": key\n", "}\n", - "treasury_yield = {\n", - " \"function\": \"TREASURY_YIELD\",\n", - " \"interval\": \"weekly\", # daily, monthly\n", - " \"maturity\": \"3month\", # OPTIONAL 5year, 10year, 30year\n", - " \"apikey\": key\n", - "}\n", + "\n", "federal_funds_rate = {\n", " \"function\": \"FEDERAL_FUNDS_RATE\",\n", " \"interval\": \"weekly\", # daily, monthly\n", @@ -2842,6 +2517,25 @@ "crypto_df" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Financials" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "document = 'INCOME_STATEMENT' # BALANCE_SHEET, CASH_FLOW\n", + "url = 'https://www.alphavantage.co/query?function='+document+'&symbol=IBM&apikey=demo'\n", + "r = requests.get(url)\n", + "data = r.json()" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/Source/Alphavantage.rst b/Source/Alphavantage.rst index 145daa9..c8eba71 100644 --- a/Source/Alphavantage.rst +++ b/Source/Alphavantage.rst @@ -21,17 +21,17 @@ Fetching the data - `5. Many Stocks <#5>`_ - `6. Finanical Indices <#6>`_ - `7. Currencies <#7>`_ -- `8. Crypto <#8>`_ -- `9. Mutual Funds <#9>`_ -- `10. Treasury <#10>`_ -- `11. Stock Fundamentals <#11>`_ -- `12. Financials <#12>`_ -- `13. Put Call Options <#13>`_ -- `14. Stream Real Time Data <#14>`_ -- `15. Economic Indicators <#15>`_ -- `16. Technical Indicators <#16>`_ - -.. code:: ipython3 +- `8. Crypto <#8>`_ +- `9. Mutual Funds <#9>`_ +- `10. Treasury <#10>`_ +- `11. Stock Fundamentals <#11>`_ +- `12. Financials <#12>`_ +- `13. Put Call Options <#13>`_ +- `14. Stream Real Time Data <#14>`_ +- `15. Economic Indicators <#15>`_ +- `16. Technical Indicators <#16>`_ + +.. code-block:: ipython3 from alpha_vantage.timeseries import TimeSeries import pandas as pd @@ -42,6 +42,10 @@ Fetching the data Historical Price and Volume for 1 Stock --------------------------------------- +Link to the `historic price and volume of one stock`_ JupyterNB cell. + +.. _historic price and volume of one stock: Source/Alphavantage.ipynb#Historic-Stock-Price-and-Volume + .. code:: ipython3 data = { @@ -77,6 +81,9 @@ Adding Time Periods Frequency Setting ----------------- +Link to the `intraday data`_ JupyterNB cell. + +.. _intraday data: Source/Alphavantage.ipynb#Intraday-Data .. code:: ipython3 @@ -96,6 +103,9 @@ Frequency Setting Stock Split and dividends ------------------------- +Link to the `dividends`_ JupyterNB cell. + +.. _dividends: Source/Alphavantage.ipynb#Dividends .. code:: ipython3 @@ -108,6 +118,9 @@ Stock Split and dividends Financial Indices ----------------- +Link to the `financial indices`_ JupyterNB cell. + +.. _Financial Indices: Source/Alphavantage.ipynb#Indices .. code:: ipython3 @@ -120,6 +133,9 @@ Financial Indices Currencies --------------- +Link to the `currency exchange`_ JupyterNB cell. + +.. _Currency Exchange: Source/Alphavantage.ipynb#Currency-Exchange .. code:: ipython3 @@ -131,8 +147,11 @@ Currencies r = requests.get(url) data = r.json() -Crypto ---------------- +Cryptocurrencies +---------------- +Link to the `cryptocurrencies`_ JupyterNB cell. + +.. _Cryptocurrencies: Source/Alphavantage.ipynb#Cryptocurrencies .. code:: ipython3 @@ -146,6 +165,9 @@ Crypto Mutual Funds --------------- +Link to the `mutual funds`_ JupyterNB cell. + +.. _Mutual Funds: Source/Alphavantage.ipynb#Mutual-Funds .. code:: ipython3 @@ -159,6 +181,9 @@ Mutual Funds Treasury Rates --------------- +Link to the `treasury yield`_ JupyterNB cell. + +.. _Treasury Yield: Source/Alphavantage.ipynb#Treasury-Yield .. code:: ipython3 @@ -171,6 +196,9 @@ Treasury Rates Stock Fundamentals ------------------ +Link to the `intraday data`_ JupyterNB cell. + +.. _intraday data: Source/Alphavantage.ipynb#Intraday-Data .. code:: ipython3 @@ -181,6 +209,9 @@ Stock Fundamentals Import Financials ----------------- +Link to the `financials`_ JupyterNB cell. + +.. _Financials: Source/Alphavantage.ipynb#Financials .. code:: ipython3 @@ -191,6 +222,9 @@ Import Financials Stream Realtime Data -------------------- +Link to the `realtime data`_ JupyterNB cell. + +.. _Realtime Data: Source/Alphavantage.ipynb#Realtime-Data .. code:: ipython3 @@ -214,6 +248,9 @@ Stream Realtime Data Economic Indicators ------------------- +Link to the `economic indicators`_ JupyterNB cell. + +.. _Economic Indicators: Source/Alphavantage.ipynb#Economic-Indicators .. code:: ipython3 @@ -258,6 +295,9 @@ Economic Indicators Technical Indicators -------------------- +Link to the `technical indicators`_ JupyterNB cell. + +.. _Technical Indicators: Source/Alphavantage.ipynb#Technical-Indicators .. code:: ipython3