Back

Error: "Cannot get managed object

Hello, so I'm pretty new here but so far I like what I see quite a bit, however I'm having trouble figuring out how the framework works.

I'm currently trying to implement a rotational etf strategy, however I keep getting this erro that I have no idea how to deal with:

Runtime Error: TypeError : Cannot get managed object
at OnData in main.py:line 34
TypeError : Cannot get managed object

I simply have no idea what this means. What is the managed object in question?
What's really strange is that even when I change my code around to simply add spaces around line 34, it still tells me that the error is on line 34 even if line 34 is blank.

Here is my code so far. Any help would be greatly appreciated.Thanks in advance!

import numpy as np


class RegionalETFrotationAlgorithm(QCAlgorithm):


def Initialize(self):


self.SetStartDate(2013,10, 7) #Set Start Date
self.SetEndDate(2013,10,11) #Set End Date
self.SetCash(100000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.tickers = ["MDY", "IEV", "EEM", "ILF", "EPP"]
self.AddEquity("EDV", Resolution.Daily)
self.AddEquity("SPY", Resolution.Daily)
self.growth = []
for ticker in self.tickers:
self.AddEquity(ticker, Resolution.Daily)
dictionary = {"symbol":ticker, "momentum":self.MOMP(ticker,90, Resolution.Daily) }
self.growth.append(dictionary)



def OnData(self, data):


for ticker in self.tickers:
self.AddEquity(ticker)
dictionary = {"symbol":ticker, "momentum":self.MOMP(ticker,90, Resolution.Daily) }
self.growth.append(dictionary)

bestEtf = self.bestEtf()
if bestEtf['momentum'] > 0:
if self.Portfolio.Invested:
Liquidate()
self.SetHoldings(bestEtf['symbol'], 1)
else:
if self.Portfolio.Invested:
Liquidate()
self.SetHoldings("EDV", 1)




def bestEtf(self):
current = self.growth

while len(current)>1:
if current[0]['momentum'] >= current[1]['momentum']:
del current[1]
else:
del current[0]
return current[0]

Update Backtest







Unfortunately, I was not able to replicate the error you've been receiving. When taking the copying and trying to run the algorithm I ran into many other issues as well. I recommend looking at this sample code that implements an ETF Global Rotation algorithm. It seems to be very similar to what is being attempted and the code will provide you with good structure. Two notable issues are that Liquidate is a property of QCAlgorithm so the proper line method call should be self.Liquidate(), and self.Portfolio is a dictionary so in order to use .Invested, a symbol needs to be called i.e. self.Portfolio["IBM"].Invested.

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.


Thank you very much. I figured out all the issues and got it working. The issue was that it was returning the MOMP type rather than an integer, so I had to return the integer by using MOMP.Current.Value.

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