trophy

Long Only, ETF Alpha Streams Competition with $27,500 Prize Pool

Back

Consolidation several sets of symbols

Hello, I recently started using Quantconnect but I have come to a severe stop since I'm not able to properly consolidate several symbols.

It gives me the following error when trying to backtest "During the algorithm initialization, the following exception has occurred: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the AddEquity method. Please checkout the API documentation. at Initialize in main.py:line 28 TypeError : No method matches given arguments for AddEquity"

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.


from Alphas.EmaCrossAlphaModel import EmaCrossAlphaModel

from Portfolio.BlackLittermanOptimizationPortfolioConstructionModel import BlackLittermanOptimizationPortfolioConstructionModel

from Execution.ImmediateExecutionModel import ImmediateExecutionModel

from Risk.NullRiskManagementModel import NullRiskManagementModel

from datetime import datetime, timedelta

class BasicTemplateFrameworkAlgorithm(QCAlgorithmFramework):

def Initialize(self):

# Set requested data resolution
self.UniverseSettings.Resolution = Resolution.Minute

self.SetStartDate(2019, 1, 1) #Set Start Date
self.SetEndDate(2019, 12, 12) #Set End Date
self.SetCash(7750) #Set Strategy Cash

self.UniverseSettings.Resolution = Resolution.Minute
tickers = ["TRVN", "AAPL", "BA", "TTP"]
symbols = [ Symbol.Create(x, SecurityType.Equity, Market.USA) for x in tickers ]
self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) )
self.AddEquity(tickers, Resolution.Minute)

thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=15))

# attach our event handler. The event handler is a function that will
# be called each time we produce a new consolidated piece of data.
thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler

# this call adds our 30-minute consolidator to
# the manager to receive updates from the engine
self.SubscriptionManager.AddConsolidator(tickers, thirtyMinuteConsolidator)

def ThirtyMinuteBarHandler(self, sender, bar):
self.Debug(str(self.Time) + " " + str(bar))
def OnData(self, data):
pass
thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=15))

# attach our event handler. The event handler is a function that will
# be called each time we produce a new consolidated piece of data.
thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler

# this call adds our 30-minute consolidator to
# the manager to receive updates from the engine
self.SubscriptionManager.AddConsolidator("TRVN", thirtyMinuteConsolidator)

def ThirtyMinuteBarHandler(self, sender, bar):
self.Debug(str(self.Time) + " " + str(bar))
def OnData(self, data):
pass
thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=15))

# attach our event handler. The event handler is a function that will
# be called each time we produce a new consolidated piece of data.
thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler

# this call adds our 30-minute consolidator to
# the manager to receive updates from the engine
self.SubscriptionManager.AddConsolidator(tickers, thirtyMinuteConsolidator)

def ThirtyMinuteBarHandler(self, sender, bar):
self.Debug(str(self.Time) + " " + str(bar))
def OnData(self, data):
pass

self.SetAlpha(EmaCrossAlphaModel(50, 200, Resolution.Minute))

self.SetPortfolioConstruction(BlackLittermanOptimizationPortfolioConstructionModel())

self.SetExecution(ImmediateExecutionModel())

self.SetRiskManagement(NullRiskManagementModel())




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

Code is as follows

0

Hi Tomas,

I've looked at the code you posted an noticed a number of things that will help with the issue you're encountering. First, when you use Universe Selection the symbols are automatically subscribed to and the self.AddEquity() call in the Initialize() method is unnecessary. Additionally, creating consolidators for multiple symbols in a Framework Algorithm is best done in the Alpha Model. I've attached a backtest in which I copied-and-pasted the EMACrossAlphaModel and added a section that builds these consolidators. This is done in the SymbolData class, which creates the Indicators for each symbol in the Alpha Model. With the added lines, the consolidators will be created and the indicators will be attached to the consolidators. Have a look at the backtest and hopefully this will help you design the algorithm. Additionally, I would recommend reading this forum post to see a discussion on the same topic.

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