For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
calculating SMA for multiple datas
-
Greetings,
I am adding data to cerebro in the following manner,
url = "https://archives.nseindia.com/content/indices/ind_nifty50list.csv" # url = r"C:\Users\s13rw81\Desktop\ind_nifty50list.csv" symbols_list = pandas.read_csv(url, usecols=[2], names=["symbol"], header=0) symbols_list = symbols_list[:2] for index, row in symbols_list.iterrows(): dx = yfinance.download(tickers=row['symbol'] + ".NS", actions=False, period="1y", interval="1d", threads=True, progress=False) cerebro.adddata(bt.feeds.PandasData(name=row['symbol'], dataname=dx, tz=timezone))
How do i calculate SMA for each of these symbols and also calculate crossovers.
My
__init__()
function looks like this,class Strategy(StandardStrategy): get_parameter = id.Scenario() params = get_parameter.all_param() def __init__(self): self.sma = bt.ind.SMA(period=44) self.crossover = bt.ind.CrossOver(self.sma, self.data.close)
It looks like, the crossover is being calculated only for the first data added to the cerebro.
Kindly help me with the above issue and also teach me how to check the crossovers.
I need to check when- the value of sma crosses above the close price of the symbol and
- the value of sma crosses below the close price of the symbol
TIA
-
if i calculate the moving average in the following manner, i do know know how to refer to the moving average for a particular date.
def __init__(self): for d in self.datas: self.sma[d.params.name] = bt.ind.SMA(period=44) self.crossover[d.params.name] = bt.ind.CrossOver(self.sma[d], d.close)
@backtrader could you kindly take a look at this.