KeyError: MarketData(NIFTY [2])

I am not sure why I am getting this error. I have tried both NIFTY and NIFTY-I as symbol but I get above error. Below are the specifics.





Backtest Period

Start Date = 1st Jan 2021

End Date = 1st Nov 2021



Below code for lookback and frequncy.

context.params = {'indicator_lookback': 375, 'indicator_freq': '1m',

'buy_signal_threshold': 0.5, 'sell_signal_threshold': -0.5,

'ROC_period_short': 30, 'ROC_period_long': 120, 'ADX_period': 120,

'trade_freq': 5, 'leverage': 2}

Can you please share a minimum version of your strategy code that can reproduce this error? In general, running strategies (i.e. placing orders) with NIFTY (which is not tradeable) will throw errors. But futures (NIFTY-I) should be alright. Also the error messages at present can be a bit strange on the platform. We have just switched to the Blueshift 2.0 version and still improving on error messages and user warnings.

Hi Prodipta,



I am using demo_support_resistance.py script which you have covered and shared in blueshift-demo strategies.zip folder.



The only two changes I have done is to replace zipline to bluesshift and second one is as below:


px = price_data.minor_xs(security)

px = price_data.loc[:,security].values



Let me know if you need more details.



Regards,

Sagar C

I am not sure which zip file you refer to. I think best to pick up the updated version of the demo strategies from our repository - see here. All these demo strategies are updated to run on Blueshift 2.0.



I think the problem you are facing is because of a wrong subsetting of the pandas dataframe in your change. Using px = price_data.loc[:,security].values assumes "security" to be in the columns. However, the returned dataframe is a multi-index dataframe with securities as index levels (NOT in columns). The correct way to do the subsetting is px = price_data.xs(security). See the blueshift changelog on this which explains it. The updated strategy in the repo does it in the correct way and I see it runs fine as is, for the date range you specified. If you continue to have issues, please feel free to give us a shout.



The key takeaway is you need to change everywhere you are using "minor_xs(…)"  to "xs(…)".