Passing a dataframe with all indicator/signal precalculated
Looking to use use backtrader as a quick way of prototyping signals.
If I have a data frame with mid price of closes and some (one for simplicity) signals, how do I pass them to backtrader. I assume
I do not need to build a custom indicator and instantiate them to do this but in effect just pass the frame directly and iterate over it.
Arun Lama last edited by
@azuric This is how I add Pandas Dataframe to datafeeds
cerebro = bt.Cerebro() feed = pd.read_csv('test.csv',index_col = 'Date',parse_dates = True) data = bt.feeds.PandasData(dataname = feed)
and this is how I used talib library to calculate indicators (you can get indicator calculations from backtrader itself too)
class SmaCross(bt.Strategy): params = dict(pslow=20,order_percentage= 0.99,ticker = 'NEPSE') def __init__(self): sma = bt.talib.SMA(self.data.close,timeperiod=self.p.pslow) self.crossover = bt.ind.CrossOver(self.data.close, sma, plot = True) ``
You can have data and indicators in the data frame which you will pass to
btas a data feed, but this data feed should be extended - additional lines for indicators added. Couple links -
Thanks guys that puts me on the right track.
run-out last edited by
The answers over here might help.