I created an ORB sample algorithm for 1 stock on 1 date. I have a spreadsheet of stocks and dates that I wanted to practice on before I worry about wiring up the selection process. My current program will take one stock and one date. How could I run this on an array of stocks and dates? I don't need to import from the spreadsheet if that is an issue.
Louis Szeto
Hi Jared
We can download and save the spreadsheet as a variable first. Assuming your spreadsheet is a .csv file, with columns of "Date" and "Stock_to_be_traded", each row as a data point:
Note that in live trading, Initialize will not be called subsequently. So, in order to fetch any update on the spreadsheet, we will need to put the 3 self.Download lines at the beginning of the Selection method.
Best
Louis
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.
Jared Millman
Hi Louis,
Thanks for the response. I am not worried about importing the spreadsheet. My question is, how do I run back tests on specific dates and specific symbols at the same time. I want to test if my code will work on a know set of dates and symbols. Currently I can only do one at a time. I don't know how to run for example:
2021-01-01 AMZN
2021-03-01 TSLA
2021-03-01 QQQ
Louis Szeto
Hi Jared
You may still use the above code snippet example, but using dataframe.groupby method to merge same date indexes:
Best
Louis
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.
Jared Millman
Thanks for the reply. That isn't the part I have an issue with.
The tutorials use a structure like below. You add equities and set a start date and end date. I don't see any way to loop over any of this? The only way I could see implementing it with a list of stocks and dates would be to add all symbols, add the max start date and end date, and return out of functions if the current date and symbol aren't in the list. That sounds like a bad way of doing things. The structure below doesn't look well suited for what I am trying to do.
Louis Szeto
Hi Jared
The AddEquity method is no longer needed as we have a Universe Selection method. That will return us its selected securities as the ActiveSecurities keys. So you may directly refer to my code snippets in the previous replies.
Best
Louis
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.
Jared Millman
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.
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!