Hello !
Does someone knows why this algorithm is stuck and can help to fix it.
Thank you
from datetime import timedelta, datetime
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
from QuantConnect.Data.UniverseSelection import *
class HorizontalQuantumCompensator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 8, 10) # Set Start Date
self.SetCash(100000)
self.AddUniverseSelection
self.UniverseSettings.Resolution = Resolution.Daily
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw
self.SetAlpha(MOMAlphaModel())
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
self.SetExecution(ImmediateExecutionModel())
self.AddUniverseSelection(LiquidValueUniverseSelectionModel())
class LiquidValueUniverseSelectionModel(FundamentalUniverseSelectionModel):
def __init__(self):
super().__init__(True, None, None)
def SelectCoarse(self, algorithm, coarse):
sortedByDollarVolume = sorted([x for x in coarse if x.HasFundamentalData],key=lambda x: x.DollarVolume, reverse=True)
return [x.Symbol for x in sortedByDollarVolume[:200]]
class MOMAlphaModel(AlphaModel):
def __init__(self):
self.SMAS = []
self.SMAL = []
self.RSI = []
def OnSecuritiesChanged(self, algorithm, changes):
for security in changes.AddedSecurities:
symbol = security.Symbol
self.SMAS.append({"symbol":symbol, "indicator":algorithm.SMA(symbol, 20, Resolution.Daily)})
self.SMAL.append({"symbol":symbol, "indicator":algorithm.SMA(symbol, 50, Resolution.Daily)})
self.RSI.append({"symbol":symbol, "indicator":algorithm.RSI(symbol, 14, Resolution.Daily)})
def Update(self, algorithm, data):
for s in symbol:
SMA20 = self.SMAS.Current.Value
SMA50 = self.SMAS.Current.Value
RSI = self.RSI.Current.Value
if SMA20>SMA50 and RSI < 30 :
return Insight.Group(
[Insights.Price(self.SMA20.Symbol,timedelta(1),InsightDirection.Up)])
if SMA20<SMA50 and RSI > 70 :
return Insight.Group(
[Insights.Price(self.SMA20.Symbol,timedelta(1),InsightDirection.Down)])
Rahul Chowdhury
Hi Wawes,
You can create a SymbolData class to hold all the indicators for each symbol. Then you can create a dictionary keyed by symbol which holds our SymbolData objects. Organizing our indicators this way makes our code simpler.
In the Update method, cycle through the symbols in the dictionary and create insights for the symbols which meet the entry signals. Append those insights to our list of insights and finally return that list at the end of Update.
Wawes23
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!