Constructing Keltner Channels for Universe Selection within class SelectionData()

Back

Hi! I'm trying to add the Keltner Channels indicator as an extra filter for my universe selection, but I seem to be encountering some problems. Before trying to add the keltner indicator, I was only constructing EMAs and an RSI indicator to use for my universe selection, but I wasn't encountering this problem then with just these indicators. After trying to add the Keltner Channel, I encounter this error:

Runtime Error: TypeError : 'Timestamp' object does not support indexing
at <lambda> in FundamentalUniverseSelectionModel.py:46
TypeError : 'Timestamp' object does not support indexing (Open Stacktrace)

This is the class constructor:

class SelectionData():

def __init__(self, history):

self.slow = ExponentialMovingAverage(200)
self.fast = ExponentialMovingAverage(50)
self.keltner = KeltnerChannels(10, 2, MovingAverageType.Simple)

for bar in history.itertuples():

tradeBar = TradeBar(bar.Index[1], bar.Index[0], bar.open, bar.high, bar.low, bar.close, bar.volume, timedelta(1))

self.fast.Update(bar.Index[1], bar.close)
self.slow.Update(bar.Index[1], bar.close)
self.keltner.Update(tradeBar)


def is_ready(self):

return self.slow.IsReady and self.fast.IsReady and self.keltner.IsReady


def update(self, time, price):

self.fast.Update(time, price)
self.slow.Update(time, price)

And how I apply it to the symbols:

 

for security in sortedByDollarVolume:

symbol = security.Symbol
dollar = self.dollarVolumeBySymbol[symbol]
price = self.AdjustedPrice[symbol]

if symbol in history_symbols:

if not str(symbol) in history.index:
continue

self.averages[symbol] = SelectionData(history.loc[symbol])

self.averages[symbol].update(algorithm.Time, price)
selected[symbol] = dollar

 

I'm stumped.. I followed the suggestion here: 

https://www.quantconnect.com/forum/discussion/8840/keltner-channel-on-a-class

Thank you!

Update Backtest







 
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Vncne,

Try replacing

self.averages[symbol] = SelectionData(history.loc[symbol])

with

self.averages[symbol] = SelectionData(history)

If that doesn't fix it, please attach a backtest which demonstrates the issue so I can further assist.

Best,
Derek Melchin

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!