I have a list of 5 stocks for which I would like to obtain data using Alpha Vantage's TechIndicators. Below are what I have imported and defined:
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.foreignexchange import ForeignExchange
from alpha_vantage.cryptocurrencies import CryptoCurrencies
from alpha_vantage.techindicators import TechIndicators
from alpha_vantage.sectorperformance import SectorPerformances
import datetime
import numpy as np
import pandas as pd
top5 = ['CELH', 'MAXR', 'CD', 'WDC', 'IMAB']
Querying for technical indicators returns a dataframe (data) and a dictionary (meta_data)
data, meta_data = ti.get_sma(symbol=ticker, interval='weekly')
How do I run the query for my top5 list? I first thought it should look like this:
for ticker in top5:
ticker_sma[ticker], ticker_meta_sma[ticker] =
ti.get_sma(symbol=ticker, interval='weekly')
or like this:
sma = {}
for ticker in top5gainers:
gainers_sma[ticker], gainers_sma_data[ticker] =
ti.get_sma(symbol=ticker, interval='weekly')
gainers_sma.keys()
gainers_sma.values()
But I have had zero luck with that approach. I get a name error...
NameError: name 'ticker_sma' is not defined
...which is odd to me because I have success getting data for an individual stock, e.g., Microsoft, below:
msft_sma, msft_meta_sma = ti.get_sma(symbol='msft', interval='weekly')
If I remove [ticker], and just run this get request...
for ticker in top5:
data_sma, meta_sma = ti.get_sma(symbol=ticker, interval='weekly')
...then according to the meta data in meta_sma, I've only obtained data for the 4th ticker out of the 5 tickers:
{'1: Symbol': 'IMAB',
'2: Indicator': 'Simple Moving Average (SMA)',
'3: Last Refreshed': '2020-12-31',
'4: Interval': 'weekly',
'5: Time Period': 20,
'6: Series Type': 'close',
'7: Time Zone': 'US/Eastern'}
Thank you for reading this question and for your answer!