Back

How to output to console from BaseData class

I see Debug(...) is a method of the QCAlorithm() class. And it looks like messages passed to Debug() are simply added to an ivar, _debugMessages, which is a list of strings.

I'm trying to output debugging and log messages from other classes, for example from a custom class derived from BaseData. How would you recommend outputting to QuantConnect's console or logs from a class derived from BaseData? Can messages be passed to a global variable for the algorithm?
Update Backtest








You could define a static variable in your algorithm that is your algorithm, for example:public static QCAlgorithm Instance;
Then in your Initialize() method:Instance = this;
Then you could use it from within your custom class by the following (assuming your algorithm's name is 'MyAlgorithm':MyAlgorithm.Instance.Log(...)
1

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.


Also for Debug messages only (not logging) you can use: Console.WriteLine("Message");
1

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.


Ok, thanks. I was going to try the Console.WriteLine(), but wasn't sure if it would do what I think it should do in QuantConnect. So I thought I'd ask. :-)
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