For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Sanity testing on loaded data in BT.
-
Hello,
I am currently writing a script to load multiple securities data and perform operations on them. Since I am loading the CSV data into BT, I wish to see all the data which is loaded, to make sure BT is correctly reading what I am passing it. Is there any way to do this.
The reason arised because of implementation of one of the strategy, https://teddykoker.com/2019/05/momentum-strategy-from-stocks-on-the-move-in-python/
where I am passing cnx 200 stocks data.for ticker in tickers: data = bt.feeds.GenericCSVData(dataname=f"G:\\{ticker}.csv", nullvalue=0.0,dtformat=('%d-%m-%Y'), fromdate=datetime(2015, 1, 1), todate=datetime(2020, 7, 31), datetime=0,open=1,high=2,low=3,close=4,volume=5,openinterest=-1 ) cerebro.adddata(data)
and defining a momentum strategy where regression slope will be calculated on rolling 90 dataclose.
class Momentum(bt.Indicator): lines = ('trend',) params = (('period', 90),) #def __init__(self): #self.addminperiod(self.params.period) def next(self): returns = np.log(self.data.get(size=self.p.period)) x = np.arange(len(returns)) #mask = ~np.isnan(x) & ~np.isnan(returns) slope, _, rvalue, _, _ = linregress(x, returns) annualized = (1 + slope) ** 252 self.lines.trend[0] = annualized * (rvalue ** 2)
The error which is being thrown is : ValueError: Inputs must not be empty.
I need to know whether the data stored in cerebro is correct. -
Is there any way to do this.