Back

How to use Log/Debug/Error/Quit etc .. in any Python class?

Hi guys,

As the title suggests, in a Python class that does not inherit from QCAlgorithm base class, how should I do debugging?

Thanks!

Update Backtest







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!

0

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()
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.


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!

0

You need to pass the "self" in basic QCAlgorithm() class to create the instance of the class. Please see this example

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.


Jing Wu , I see. Thanks a lot!

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