KeyError: "cannot represent labeled-based slice indexer for coordinate 'time' with a slice over integer positions; the index is unsorted or non-unique"
-
Hello, I am currently using the following backtest to develop a strategy using neural network
import qnt.data as qndata import qnt.stats as qnstats retrain_interval = 19*365 + 1 data = qndata.stocks.load_ndx_data(min_date ="2005-01-01") models = train_model(data) weights = predict(models, data) is_liquid = data.sel(field="is_liquid") weights = weights * is_liquid def get_enough_bid_for(data_, weights_): time_traded = weights_.time[abs(weights_).fillna(0).sum('asset') > 0] is_strategy_traded = len(time_traded) if is_strategy_traded: return xr.where(weights_.time < time_traded.min(), data_.sel(field="is_liquid"), weights_) return weights_ weights = get_enough_bid_for(data, weights) weights = weights.fillna(0) # Calculate stats stats = qnstats.calc_stat(data, weights) display(stats.to_pandas().tail()) # Graph performance = stats.to_pandas()["equity"] import qnt.graph as qngraph #qngraph.make_plot_filled(performance.index, performance, name="PnL (Equity)", type="log")
The results of checking the strategy file are normal, however when I run precheck the following error occurs
And when I submit the strategy, it is put into the filter with the error that there is no weight. Please help me fix the error. Thank you.
My strategy ID is 16900804
-
Hi @newbiequant96,
You need to need to, in the init notebook write: !pip install pandas==1.2.5
I recently encountered that problem again, in my case I think, because statsmodels is not compatible with the default pandas version, it upgrades it.
It needs to be downgraded again in my case.
Hope this will work for you.
Regards -
This post is deleted! -
@newbiequant96 no problem.
I think the issue now is unrelated to the the previous issue. If you can show what is written above return code 1, I can maybe help.
It seems to be an issue in the code.
Regards -
This post is deleted!