Error 'RangeIndex' object has no attribute 'year'

Course Name: Momentum Trading Strategies, Section No: 14, Unit No: 17, Unit type: Notebook

This error has occurred while running the year_groups = stocks_price.shift(90).groupby([stocks_price.index.year])

I am having the above attribute error.

Thanks

 

 

Hi Bhaumik,



I tried to run the mentioned notebook in the Quantra portal and it worked without error. I even tried downloading the required files (notebook + data_files) and ran it in a local environment similar to Quantra and it worked there too.



One issue I could think of is that the data is not converted to a datetime object and hence it is giving this error. 





Can you help me with the entire error output and I will try to resolve this one. 



By the way, just something additional, did you run it on a local environment similar to Quantra? 

And one final question is it the same data file or a data file that you have compiled?



This would help in resolving the error.



Thanks.

 

There is no error while running in Quantra portal.



Can you please let me know that whether the data is rquired has to be for 10 year.

Can I use data for 5 or less years for running the file,



Secondly can you please guide me for generating pickle file for selected data



Thanks



 

Problem solved it was Dataframe problem. 

Thanks

Hi Bhaumik,



It is great that your issue was resolved. Regarding your earlier question, you can use data with a time period of fewer than 5 years. However, I should add here that generally a longer backtesting period will help you understand better how your strategy reacts to different market regimes and events.



When it comes to pickle file, you will find this blog resource useful for creating and reading pickle files. Although, if your data file is smaller, I feel it would be better if you keep it in csv format itself.



Hope this helps.

Thanks.