Back

LEAN: how to get any custom output to file, using Python self.Log or self.Debug

Hi, I cannot get any output using LEAN. Ive search the forum. The main related question implies I need to set my own log handler but doesn't describe how to. It's very difficult to debug the algo script without it.

www.quantconnect.com/forum/discussion/1470/can-not-access-log-file/p1

I know there are two files log.txt and name_of_algo-log.txt in the Debug dir, but has no Logged text using either of the methods in the title, in both initialize and OnData.

 

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.


Hi john smitherson ,

Happy to see you did some research in the forum. It gave us a chance to close old threads. Thanks!

We don't need to copy the Python scripts to Launcher/bin/Debug folder since we set the algorithm location with config.json file:

"algorithm-location": "../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py",

it goes back three directories because the executable is found in Lean/Launcher/bin/Debug and the script in Lean/Algorithm.Python, therefore it goes to the root directory (Lean/).

In the online IDE, when we hit "Build", it runs a compiler that creates the pyc files before the algorithm is executed. In this process, we add headers with imports such as:

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *

QCAlgorithm class comes from QuantConnect.Algorithm module/namespace. Thus all algorithms need, at least, the commands of the code snippet above.

If the algorithm needs to import classes that are not in those namespaces, we can find them in the code. For example, take PythonData for algorithms with custom data, we can see that it belongs to QuantConnect.Python namespace, consequently we need to add the following import:

from QuantConnect.Python import PythonData

as we can verify in the CustomDataBitcoinAlgorithm.py.

You can add all the imports as the QuantConnect Cloud compiler does. It will have an impact on the time it takes for loading the algorithm, but it shouldn't take too long.

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