Hi,
I am trying a really basic MACD Alpha model using the algo framework and I see some errors in insights time compared to Yahoo finance or spreadsheet calculated MACD. Maybe I am just beginning and missing something really obvious, can you help me to make it work ?
I checked that Resolution was daily for both Alpha model and Yahoo finance.
I tried both MovingAverageType.Simple and MovingAverageType.Exponential in addAlpha arguments.
Example of insights
https://drive.google.com/file/d/16qplL_BKu9bWZ3O3Uy30-f-n_VoTmY-8/view?usp=sharing
Example of yahoo finance MACD
https://drive.google.com/file/d/16qplL_BKu9bWZ3O3Uy30-f-n_VoTmY-8/view?usp=sharing
from Alphas.MacdAlphaModel import MacdAlphaModel
class PrototypeV0(QCAlgorithm):
def Initialize(self):
self.UniverseSettings.Resolution = Resolution.Minute
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw
self.SetStartDate(2017, 2, 15)
self.SetCash(100000)
symbols = [ Symbol.Create("TSLA", SecurityType.Equity, Market.USA)]
self.AddAlpha(MacdAlphaModel(12, 26, 9, MovingAverageType.Exponential, Resolution.Daily))
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel() )
self.SetExecution( ImmediateExecutionModel() )
self.SetRiskManagement(TrailingStopRiskManagementModel(0.05))
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
# if not self.Portfolio.Invested:
# self.SetHoldings("SPY", 1)
Alexandre Catarino
Hi Etienne RAINAUT ,
You haven't said why the insights are wrong in your opinion. We couldn't open the links from Google Drive.
The MACD Alpha Model emits InsightDirection.Up when the ratio between the MACD.Signal and the security prime is greater than bounceThresholdPercent (value of 0.01):
normalized_signal = sd.MACD.Signal.Current.Value / sd.Security.Price
if normalized_signal > self.bounceThresholdPercent:
direction = InsightDirection.Up
elif normalized_signal < -self.bounceThresholdPercent:
direction = InsightDirection.Down
P.S.: Please do not create duplicates in the community forum and support@quantconnect.com.
Etienne RAINAUT
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!