Hi guys,
As the title suggests, in a Python class that does not inherit from QCAlgorithm base class, how should I do debugging?
Thanks!
QUANTCONNECT COMMUNITY
Hi guys,
As the title suggests, in a Python class that does not inherit from QCAlgorithm base class, how should I do debugging?
Thanks!
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.
Thomas Cheng
I understand that the Debug and Log methods are defined in QCAlgorithm class, therefore I tried the following:
class somerandomclass:
def __init__(self):
self.qca = QCAlgorithm()
self.Log("testing")
which does not work. Then I tried making 'somerandomclass' a inheried class:
class somerandomclass(QCAlgorithm):
def __init__(self):
self.Log("testing")
that does not work either (I tried to create a custom indicator and register it by following the tutorial). It produced error:
SystemError : <bound method 'RegisterIndicator'> returned a result with an error set
Any advice would be appreciated!
Jing Wu
Hi Thomas,
You could use the QC method in other classes like this
class A(object): def __init__(self, algo): self.algo = algo def log_time(self): self.algo.Log(str(self.algo.Time))
When you call the method in the class
A(self).log_time()
Thomas Cheng
Hi Jing Wu ,
Thanks for the reply.
In your example, when I construct the object of class A in a top level file (i.e. main.py), what should I substitute the 'algo' in the constructor with? Should I do the following?
obj_A = A(QCAlgorithm)
Thanks for the help!
Jing Wu
You need to pass the "self" in basic QCAlgorithm() class to create the instance of the class. Please see this example
Thomas Cheng
Jing Wu , I see. Thanks a lot!
Darwinps
Hi All,
I was trying to find some answers on how to do something like self.Log or self.Debug in AlphaModel classes.
This relatively old post is the closest thing I could find but still I could not get my problem solved.
Anybody had similar problem with solution?
Thanks in advance
Douglas Stridsberg
Hey - most functions (Update() and OnSecuritiesChanged()) in the AlphaModel class have the containing algorithm passed in via the algorithm parameter. Just use algorithm.Log or algorithm.Debug to do the debugging.
Darwinps
Ohhh my Gosh, that's so simple and working.
Thanks so much
Â
Thomas Cheng
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!