├── Example-Images ├── SMA-Vs-RSI.png ├── RSI-Vs-Close.png ├── SMA-vs-Timeseries.png ├── Timeseries-Example.png ├── Stochastic-Oscillator.png ├── Relative-Strength-Index.png ├── Weighted-Moving-Average.png └── Exponential-Moving-Average.png ├── Technical Indicators Notes ├── ts-methods.txt └── Technical Indicator Function Calls.txt ├── timeseries_example.py ├── stochastic_oscillator.py ├── weighted_moving_average.py ├── relative_strength_index.py ├── exponential_moving_average.py ├── sma_vs_close.py ├── rsi_vs_close.py ├── sma_and_rsi.py └── README.md /Example-Images/SMA-Vs-RSI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/SMA-Vs-RSI.png -------------------------------------------------------------------------------- /Example-Images/RSI-Vs-Close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/RSI-Vs-Close.png -------------------------------------------------------------------------------- /Example-Images/SMA-vs-Timeseries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/SMA-vs-Timeseries.png -------------------------------------------------------------------------------- /Example-Images/Timeseries-Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/Timeseries-Example.png -------------------------------------------------------------------------------- /Example-Images/Stochastic-Oscillator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/Stochastic-Oscillator.png -------------------------------------------------------------------------------- /Example-Images/Relative-Strength-Index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/Relative-Strength-Index.png -------------------------------------------------------------------------------- /Example-Images/Weighted-Moving-Average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/Weighted-Moving-Average.png -------------------------------------------------------------------------------- /Example-Images/Exponential-Moving-Average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Derrick-Sherrill/alpha-vantage-examples/HEAD/Example-Images/Exponential-Moving-Average.png -------------------------------------------------------------------------------- /Technical Indicators Notes/ts-methods.txt: -------------------------------------------------------------------------------- 1 | ts methods: 2 | 'get_batch_stock_quotes', 3 | 'get_daily', 'get_daily_adjusted', 4 | 'get_intraday', 'get_monthly', 5 | 'get_monthly_adjusted', 'get_weekly', 6 | 'get_weekly_adjusted', 'indexing_type', 7 | 'key', 'map_to_matype', 'output_format', 8 | 'proxy', 'retries', 'set_proxy', 9 | 'treat_info_as_error' 10 | -------------------------------------------------------------------------------- /timeseries_example.py: -------------------------------------------------------------------------------- 1 | from alpha_vantage.timeseries import TimeSeries 2 | import matplotlib.pyplot as plt 3 | 4 | ts = TimeSeries(key='RNZPXZ6Q9FEFMEHM',output_format='pandas') 5 | data, meta_data = ts.get_intraday(symbol='MSFT',interval='1min', outputsize='full') 6 | print(data) 7 | 8 | data['4. close'].plot() 9 | plt.title('Intraday TimeSeries Microsoft') 10 | plt.show() -------------------------------------------------------------------------------- /stochastic_oscillator.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | import matplotlib.pyplot as plt 4 | 5 | api_key = 'RNZPXZ6Q9FEFMEHM' 6 | 7 | ti = TechIndicators(key=api_key, output_format='pandas') 8 | data, meta_data = ti.get_stoch(symbol='MSFT', interval='1min') 9 | 10 | data.plot() 11 | plt.title('Stochastic Oscillator') 12 | plt.show() -------------------------------------------------------------------------------- /weighted_moving_average.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | import matplotlib.pyplot as plt 4 | 5 | api_key = 'RNZPXZ6Q9FEFMEHM' 6 | 7 | ti = TechIndicators(key=api_key, output_format='pandas') 8 | data, meta_data = ti.get_wma(symbol='MSFT', interval='1min', time_period=60, series_type='close') 9 | 10 | data.plot() 11 | plt.title('Weighted Moving Average') 12 | plt.show() -------------------------------------------------------------------------------- /relative_strength_index.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | import matplotlib.pyplot as plt 4 | 5 | api_key = 'RNZPXZ6Q9FEFMEHM' 6 | 7 | ti = TechIndicators(key=api_key, output_format='pandas') 8 | data, meta_data = ti.get_rsi(symbol='MSFT', interval='1min', time_period=60, series_type='close') 9 | 10 | data.plot() 11 | plt.title('Relative Strength Index') 12 | plt.show() 13 | -------------------------------------------------------------------------------- /exponential_moving_average.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | import matplotlib.pyplot as plt 4 | 5 | api_key = 'RNZPXZ6Q9FEFMEHM' 6 | 7 | ti = TechIndicators(key=api_key, output_format='pandas') 8 | data, meta_data = ti.get_ema(symbol='MSFT', interval='1min', 9 | time_period=60, series_type='close') 10 | 11 | data.plot() 12 | plt.title('Exponential Moving Average (60 Minutes) Microsoft') 13 | plt.show() -------------------------------------------------------------------------------- /sma_vs_close.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.timeseries import TimeSeries 3 | from alpha_vantage.techindicators import TechIndicators 4 | import matplotlib.pyplot as plt 5 | 6 | api_key = 'RNZPXZ6Q9FEFMEHM' 7 | 8 | ts = TimeSeries(key=api_key, output_format='pandas') 9 | data_ts, meta_data_ts = ts.get_intraday(symbol='MSFT',interval='1min', outputsize='full') 10 | 11 | periods = 60 12 | 13 | ti = TechIndicators(key=api_key, output_format='pandas') 14 | data_ti, meta_data_ti = ti.get_sma(symbol='MSFT', interval='1min', 15 | time_period=60, series_type='close') 16 | 17 | 18 | df1 = data_ti 19 | df2 = data_ts['4. close'].iloc[periods-1::] 20 | 21 | print(df1) 22 | df2.index = df1.index 23 | print(df2) 24 | 25 | total_df = pd.concat([df1,df2], axis=1) 26 | print(total_df) 27 | 28 | total_df.plot() 29 | plt.show() 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /rsi_vs_close.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.timeseries import TimeSeries 3 | from alpha_vantage.techindicators import TechIndicators 4 | import matplotlib.pyplot as plt 5 | 6 | api_key = 'RNZPXZ6Q9FEFMEHM' 7 | 8 | ts = TimeSeries(key=api_key, output_format='pandas') 9 | data_ts, meta_data_ts = ts.get_intraday(symbol='MSFT',interval='1min', outputsize='full') 10 | 11 | periods = 14 12 | 13 | ti = TechnicalIndicators(key=api_key, output_format='pandas') 14 | data_ti, meta_data_ti = ti.get_rsi(symbol='MSFT', interval='1min', 15 | time_period=periods, series_type='close') 16 | 17 | 18 | df1 = data_ti 19 | df2 = data_ts['4. close'].iloc[periods::] 20 | 21 | print(df1) 22 | df1.index = df2.index 23 | print(df2) 24 | 25 | fig, ax1 = plt.subplots() 26 | ax1.plot(df1, 'b-') 27 | ax2 = ax1.twinx() 28 | ax2.plot(df2, 'r.') 29 | plt.title('RSI vs Close Price') 30 | plt.show() 31 | -------------------------------------------------------------------------------- /sma_and_rsi.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.timeseries import TimeSeries 3 | from alpha_vantage.techindicators import TechIndicators 4 | import matplotlib.pyplot as plt 5 | 6 | api_key = 'RNZPXZ6Q9FEFMEHM' 7 | 8 | periods = 60 9 | 10 | ti = TechIndicators(key=api_key, output_format='pandas') 11 | data_rsi, meta_data_rsi = ti.get_rsi(symbol='MSFT', interval='1min', 12 | time_period=periods, series_type='close') 13 | 14 | ti = TechIndicators(key=api_key, output_format='pandas') 15 | data_sma, meta_data_sma = ti.get_sma(symbol='MSFT', interval='1min', 16 | time_period=periods, series_type='close') 17 | 18 | 19 | df1 = data_sma.iloc[1::] 20 | df2 = data_rsi 21 | 22 | print(df1) 23 | df1.index = df2.index 24 | print(df2) 25 | 26 | fig, ax1 = plt.subplots() 27 | ax1.plot(df1, 'b-') 28 | ax2 = ax1.twinx() 29 | ax2.plot(df2, 'r.') 30 | plt.title('SMA (In blue) vs RSI (Red)') 31 | plt.show() 32 | -------------------------------------------------------------------------------- /Technical Indicators Notes/Technical Indicator Function Calls.txt: -------------------------------------------------------------------------------- 1 | # Technical Indicators Functions: 2 | """ 3 | Use the below methods as follows: 4 | ti = TechIndicators(key='YOUR_API_KEY', output_format='pandas') #Or Change output 5 | data, meta_data = ti.CALL_METHOD(**kwargs) 6 | """ 7 | 8 | 9 | 'get_ad', 'get_adosc', 'get_adx', 'get_adxr', 10 | 'get_apo', 'get_aroon', 'get_aroonosc' 11 | 'get_atr', 'get_bbands', 'get_bop', 12 | 'get_cci', 'get_cmo', 'get_dema', 13 | 'get_dx', 'get_ema', 'get_ht_dcperiod', 14 | 'get_ht_dcphase', 'get_ht_phasor', 'get_ht_sine', 15 | 'get_ht_trendline', 'get_ht_trendmode', 'get_kama', 16 | 'get_macd', 'get_macdext', 'get_mama', 'get_mfi', 17 | 'get_midpoint', 'get_midprice', 'get_minus_di', 18 | 'get_minus_dm', 'get_mom', 'get_natr', 'get_obv', 19 | 'get_plus_di', 'get_plus_dm', 'get_ppo', 'get_roc', 20 | 'get_rocr', 'get_rsi', 'get_sar', 'get_sma', 'get_stoch', 21 | 'get_stochf', 'get_stochrsi', 'get_t3', 'get_tema', 'get_trange', 22 | 'get_trima', 'get_trix', 'get_ultsoc', 'get_willr', 'get_wma', 23 | 'indexing_type', 'key', 'map_to_matype', 'output_format', 24 | 'proxy', 'retries', 'set_proxy', 'treat_info_as_error' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alpha-vantage-examples 2 | Alpha Vantage Examples and Scripts that I will use in YouTube videos. Feel free to check them out. 3 | 4 | My YouTube to see the videos: 5 | https://www.youtube.com/channel/UCJHs6RO1CSM85e8jIMmCySw 6 | 7 | I left an API key in all these scripts so they would run out of the box. You'll need to get your own API key which can be found here: 8 | https://www.alphavantage.co/support/#api-key 9 | 10 | 11 | 12 | ## 1. Time Series Intraday 13 | (Script provided by Alpha Vantage https://www.alphavantage.co/documentation/ ) 14 | 15 | Returns data on the intraday timeseries of a stock specified by the symbol keyword arguement in the ts.get_intraday method. 16 | 17 | ![Time Series png found in Example-Images](Example-Images/Timeseries-Example.png) 18 | 19 | Multiple output formats, pandas was selected in this script, close prices of each minute plotted with matplotlib 20 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/timeseries_example.py 21 | 22 | 23 | 24 | ## 2. Simple Moving Average VS. Intraday Time Series 25 | 26 | Combination of the technical indicators and time series API calls. Plotted against each other here: 27 | 28 | ![Simple Moving Average Example](Example-Images/SMA-vs-Timeseries.png) 29 | 30 | Simple moving average here being calculated by last 60 minutes. Adjust for own purposes. 31 | 32 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/sma_vs_close.py 33 | 34 | 35 | ## 3. Exponential Moving Average 36 | 37 | Calculating the EMA over each minute, using the last 60 minutes for the calculation. 38 | 39 | ![Exponential Moving Average](Example-Images/Exponential-Moving-Average.png) 40 | 41 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/exponential_moving_average.py 42 | 43 | ## 4. Stoichastic Oscillator 44 | Please note the below script was used on a stock, not a security. Demonstration purposes only. 45 | 46 | ![Stochastic Oscillator Example](Example-Images/Stochastic-Oscillator.png) 47 | 48 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/stochastic_oscillator.py 49 | 50 | 51 | ## 5. Weighted Moving Average 52 | Weighted moving average of Microsoft: 53 | 54 | ![Weighted Moving Average](Example-Images/Weighted-Moving-Average.png) 55 | 56 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/weighted_moving_average.py 57 | 58 | ## 6. Relative Strength Index 59 | RSI is a momentum indicator that that measures the magnitude of recent price changes to evaluate overbought or oversold conditions in the price of a stock or other asset. 60 | 61 | ![Relative Strength Index](Example-Images/Relative-Strength-Index.png) 62 | 63 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/relative_strength_index.py 64 | 65 | ## 7. RSI vs Close prices 66 | Plotting RSI against closing prices on the same graph, two y axis. 67 | 68 | ![Relative Strength Index vs Close](Example-Images/RSI-Vs-Close.png) 69 | 70 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/rsi_vs_close.py 71 | 72 | ## 8. SMA plotted with RSI (Two TI's) 73 | Plotting two technical indicators on the same graph using twinx() in matplotlib 74 | 75 | ![SMA vs RSI Example](Example-Images/SMA-Vs-RSI.png) 76 | 77 | https://github.com/Derrick-Sherrill/alpha-vantage-examples/blob/master/sma_and_rsi.py 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | #### Sources 87 | https://www.alphavantage.co/documentation/ 88 | Chen, James. “Relative Strength Index – RSI.” Investopedia, Investopedia, 10 June 2019, www.investopedia.com/terms/r/rsi.asp. 89 | --------------------------------------------------------------------------------