Back

Switch Symbol Once throughout entire algorithm

As you can see in my algorithm, I have the symbol listed many times. When I want to backtest another symbol, I have to change them all which takes up unnecessary amounts of time. Does anyone know how to place something in the code where you only have to switch the symbol once and it will work throughout the entire code? For example place the equity in self.equities and then can I write equity instead of the symbol throughout the code? Thanks.

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

My suggestion:

self.security = self.AddEquity("AMZN", Resolution.Minute)
self.symbol = security.Symbol

Then you have both a Symbol (string) and a security (Security object) as a handle to yourdesired stock. Some QC functions want one, some another. I like to have a handle to both.
 Or you can just grab "self.security" and then refer to its ".Symbol" string value everywhere.For example in your Consolidate method you might do: self.Consolidate(self.symbol, Resolution.Daily, self.TradeBarHandler)or alternatively self.Consolidate(self.security.Symbol, Resolution.Daily, self.TradeBarHandler)I prefer the former. BTW , you have a semicolon at the end of your python line. Thismay be an unintended carryover from a c# code copy. I'm surprised it compiled for you.Happy programming!
 
1

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