Back

Framework algorithms must specify a portfolio construction model using the 'PortfolioConstruction' property

I'm new to QC and I'm having an error that I can't make sense of. I've copied what was auto-generated by the framework selection wizard into my first script; the error is the title of this post.

main.py

from Alphas.RsiAlphaModel import RsiAlphaModel
from Execution.StandardDeviationExecutionModel import StandardDeviationExecutionModel
from Standards import StandardProfile

class MasterAlgo(QCAlgorithmFramework):


def Initialize(self):

std = StandardProfile(self)

# Securities traded
symbols = [ Symbol.Create("CRON", SecurityType.Equity, Market.USA) ]
self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) )

self.SetAlpha(RsiAlphaModel(60, Resolution.Minute))
self.SetExecution(StandardDeviationExecutionModel(60, 2, Resolution.Minute))


def OnOrderEvent(self, orderEvent):
if orderEvent.Status == OrderStatus.Filled:
# self.Debug("Purchased Stock: {0}".format(orderEvent.Symbol))
pass

 

Standards.py

from Risk.TrailingStopRiskManagementModel import TrailingStopRiskManagementModel
from Risk.MaximumDrawdownPercentPerSecurity import MaximumDrawdownPercentPerSecurity
from Portfolio.MeanVarianceOptimizationPortfolioConstructionModel import MeanVarianceOptimizationPortfolioConstructionModel

class StandardProfile():


def __init__(self, klass):
self.caller = klass
self.SetBroker
self.SetRiskManagement
self.SetTimeframes
self.SetBacktesting
self.SetSecurities


def SetBroker():
self.caller.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash)


def SetSecurities():
self.caller.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))


def SetRiskManagement():
trailing_stop = 0.10
max_drawdown = 0.05
self.caller.SetRiskManagement(
TrailingStopRiskManagementModel(trailing_stop),
MaximumDrawdownPercentPerSecurity(max_drawdown)
)
self.caller.SetPortfolioConstruction(MeanVarianceOptimizationPortfolioConstructionModel())
self.caller.Allocate = 0.25


def SetTimeframes():
self.caller.SetTimeZone(TimeZones.Toronto)
self.caller.UniverseSettings.Resolution = Resolution.Minute
self.caller.timeframes = {
1: None,
5: None,
15: None,
30: None,
60: None,
240: None,
390: None,
1950: None
}
for minutes, span in caller.timeframes.items():
self.caller.timeframes[minutes] = new(TradeBarConsolidator(TimeSpan.FromMinutes(minutes)))


def SetBacktesting():
self.caller.SetStartDate(2018, 1, 1)
self.caller.SetEndDate(2018, 12, 31)
self.caller.SetCash(20000)

 

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.


Cancel that; it was just my lack of knowledge on Python. The methods in `__init__` were never called without using `()` braces and further edits were required.

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