Back

Odd Alpha Logic? Or Maybe I'm Just Not Seeing Something

Hi, I'm looking at and copying this code to get some practice under my fingers, and something doesn't make sense to me:

EMACrossAlpha - QC Github

In this alpha, we're emitting an insight that let's us know if the Fast EMA is above the Slow (InsightDirection.Up) or if the Slow EMA is above the Fast EMA (InsightDirection.Down). 

Here's What I Don't Understand:

1) In the Alphas Update Method, we have this logic:, please see my comments:

for symbol, symbolData in self.symbolDataBySymbol.items():
if symbolData.Fast.IsReady and symbolData.Slow.IsReady:

if symbolData.FastIsOverSlow: # Check the boolean property of the SymbolData class
if symbolData.Slow > symbolData.Fast: # Why bother checking the boolean property then above? This is the same logic.
# And besides that, if FastIsOverSlow returned true to get here why would Slow be greater than Fast?
insights.append(Insight.Price(symbolData.Symbol, self.predictionInterval, InsightDirection.Down))

# Again, we're checking for SlowIsOverFast but then if Fast is over Slow on the next line?
elif symbolData.SlowIsOverFast:
if symbolData.Fast > symbolData.Slow:
insights.append(Insight.Price(symbolData.Symbol, self.predictionInterval, InsightDirection.Up))

# Why are we flipping this boolean here? Shouldn't this be done before we emit the insight. Check the values, flip the boolean flag, check the flag, emit the insight...
symbolData.FastIsOverSlow = symbolData.Fast > symbolData.Slow

 

2) In the BootCamp tutorial for EMACross, we create a class for SymbolData that contains an Update method for updating the moving values of the EMA's. Why do we not need that class method in this Alpha?
 

3) In any other alogorithm where we want to check the value of a moving average, we have to call access the value on the 'Current.Value" property. Why do we not need to do that in this Alpha? Example Below. 

self.SPYemaSlow.Current.Value > self.SPYemaFast.Current.Value:
# Do Something Here

 

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

In the Alpha model you linked to, the indicators are registered with the algorithm, which means they will be automatically updated with new data. The indicators are assigned to SymbolData attributes called Fast and Slow which are updated by the algorithm. When making the value comparisons, the code implicitly calls the current value of the indicators. Otherwise, we could use the Current.Value property to retrieve these values as well.

In the boot camp, we update the indicators manually since they're in the universe selection and we need to use historical data to do so. An update method is added so that we can update both of the indicator values manually in one easy method.

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.


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