Back

Why am I getting this error ?

Hi everyone I'm getting an error and I can't seem to find the source of the problem! I am asking for you help friends :)
Runtime Error: TypeError : unindexable object

at OnData in main.py:line 47

at getClose in main.py:line 58
:: return df["close"].unstack(level=0)
TypeError : unindexable object (Open Stacktrace

The code (at line 58) :

    def getClose(self, tickers, timeDelta):
        df = self.History(tickers, timeDelta, Resolution.Daily)
        return df["close"].unstack(level=0)

I'm trying to get the close values from the last timeDelta days for one ticker.

Thanks for you help in advance!

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 Alexis,

This error occurs when we try to access the "close" column of an empty DataFrame. To ensure this doesn't happen, we can check if 'close' is a column in the DataFrame before accessing it.

if 'close' in history.columns:
history['close'].unstack(level=0)

See the attached research notebook for reference. If this does not fix the issue, please attach a backtest which demonstrates the issue.

Best,
Derek Melchin

1

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...

This discussion is closed