Back

S&P500 Sector Rotation Strategy

Just found this platform and would like to "test" some trading ideas using only the 11 S&P500 sectors.  From the Sample Library I found this code:

for symbol in self.symbols:
            self.AddEquity(symbol, Resolution.Daily)
            self.data[symbol] = self.MOM(symbol, period, Resolution.Daily)

What kind of structure does the self.MOM create?  Is self.data a python series with the symbol being the index?

Also: what does "kvp" do in the following loop (its not defined anywhere in the example):

for kvp in self.Portfolio:

  security_hold = kvp.Value

Appreciate all comments to explain what is happening.  Thanks ...

Mike

 

 

 

 

 

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.


Hey Mike Reichard ! Welcome to QuantConnect!

self.MOM(symbol, period, Resolution.Daily)

is creating a daily momentum indicator for the current symbol in the loop. You can learn more about how indicators are created in our documentation

self.data is a dictionary that holds the momentum indicator for each relevant symbol and it is also indexed by the Symbol. This allows us to easily access the momentum indicator for the symbol we care about.

self.Portfolio carries different properties about our portfolio, such as how much we have invested in total through all our securities and how much total profit we've made. We can also access Portfolio data specific to a symbol by indexing self.Portfolio[symbol]. In the for loop, kvp refers to the key-value-pairs which index our self.Portfolio. The key, in this case, is the symbol with which we are indexing and the value refers to the Portfolio data for that specific symbol. security_hold is set to the value of the kvp, which means it is set to the Portfolio data for that symbol. Learn more about how Portfolio objects work here.

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.


Thanks. That was an wonderful explanation! Have a great day!
0

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