Indicator per ticker in multi-ticker strategy
-
Hello,
I have implemented an indicator that is initialized in Strategy init for a multi-ticker strategy,
The indicator's next() is calculated OK for the first ticker(data0) but not for the rest of the tickerscode:
Here is the Strategy init code:self.lr = {data._name: lr(lr_lookback=self.p.rank_period, ticker_data=data) for data in self.datas}
the indicators code
class LinearRegression(bt.Indicator): lines = ('slope','r2',) def __init__(self, lr_lookback, ticker_data): self.addminperiod(lr_lookback) self.ticker_data = ticker_data self.lr_lookback = lr_lookback def next(self): samples = self.ticker_data.get(size=self.lr_lookback)# ERROR return 0 for ALL tickers other than the first one if len(samples): slope, intercept, r_value, p_value, std_err = stats.linregress(np.arange(self.lr_lookback), np.array(samples)) else: slope=0 r_value=0 self.lines.slope[0] = slope self.lines.r2[0] = r_value ** 2
please advise,
Thank you -
You are never passing any specific data feed to the indicator. And the 1st data get passed automatically.
-
OK,
What am I doing wrong?
How can I pass specific data feed to an indicator?
Can you give an example?Thank you
-
indicator(datax)
-
in the next() method?
-
@trade-prophet said in Indicator per ticker in multi-ticker strategy:
Here is the Strategy init code:
self.lr = {data._name: lr(lr_lookback=self.p.rank_period, ticker_data=data) for data in self.datas}
-
@backtrader
Sorry for the late response,
in the lineself.lr = {data._name: lr(lr_lookback=self.p.rank_period, ticker_data=data) for data in self.datas}
I pass the specific data in ... ticker_data=data) for data in self.datas
Or am I missing something ?Thank you.
-
Docs - Platform Concepts - Data Feeds - Passing them around
@backtrader said in Indicator per ticker in multi-ticker strategy:
indicator(datax)