I am new to QC. After reading the BootCamp, I would like to try to develope strategies by following the framework. Here is my test case. I would like to pass a variable to Alpha Model from the QCAlgorithm class, is it possible?
Here is my test code:
class QuantityTesting_Insight(QCAlgorithm):
isFirstOrder = True # variable I want to pass
def Initialize(self):
self.SetStartDate(2020, 1, 13) # Set Start Date
self.SetEndDate(2020, 1, 18) # Set End Date
self.SetCash(100000) # Set Strategy Cash
# user variables
# self.isFirstOrder = True
# Handle UniverseSettings
self.UniverseSettings.Resolution = Resolution.Minute
symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]
self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))
# Handle Alpha Model
self.SetAlpha(TestingAlpha())
# Handle Portfolio Model
self.SetPortfolioConstruction(MyEqualWeightingPortfolioConstructionModel())
self.SetExecution(ImmediateExecutionModel())
self.SetRiskManagement(NullRiskManagementModel())
class TestingAlpha(AlphaModel):
def __init__(self):
pass
# override
def Update(self, algorithm, data):
insights = []
if not isinstance(algorithm, QuantityTesting_Insight):
return insights
algorithm.__class__ = QuantityTesting_Insight
if not algorithm.isFirstOrder:
return insights
return insights
I have a variable named isFirstOrder, which is a boolean. When I cast the class back to QunatityTesting_Insight, I get error message, ′QuantityTest∈gInsight′objectlayoutd⇔ersom′QCAlgorithm′
I would like to ask if there a way to do this action? Or I should use other method to pass variable instead of using QCAlgorithm class? Thank you very much.
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!