Quantopian Migration

Logging and Plotting

Logging

In QuantConnect, the self.Debug() method is the equivalent of the log.info() function in Quantopian. Debug output is viewable via the QuantConnect Terminal Console.

Output to the console via self.Debug() is rate-limited. If you need long-term storage of your logs and don't want to overflow the console, consider using self.Log() instead. An example comparing logging between Quantopian and QuantConnect is shown below.

Quantopian

def initialize(context):
    log.info("Hello, console!")

QuantConnect

class MyLoggingAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.Debug("Hello, console!")
        self.Log("Hello, backtesting logs!")

Logging via self.Log() has daily limits in QuantConnect. On the free tier, users are limited to 10KB of logs per day for your account/organization. To increase this limit, you can upgrade your account to a different tier. Calls to self.Debug() will also count towards the 10KB log limit, but are always outputted to the Terminal Console regardless of your daily log limit.

To view pricing and upgrade your account, visit the Organization Pricing page.

You can view the logs generated via self.Log() for a backtest by first accessing a backtest, and clicking the "Logs" tab near the bottom of the page. To download the logs, you can click the "Download Logs" link to download a text file containing your backtest's logs.

Plotting

In Quantopian, plotting/charting is done with the record(series1_name=scalar_value, series2_name=scalar_value, ...) function. In QuantConnect, plotting is accessible via the self.Plot("chart name", "series name", scalar_value) method.

Plotting multiple series in one function call is possible in Quantopian. However, in QuantConnect, a separate call is needed for each series requiring an update. All series with the same chart name will appear on the same window/pane. New charts can be created by calling self.Plot() method with a unique chart name.

An example of plotting in Quantopian vs. QuantConnect is shown below. The QuantConnect code will create two charts, one named "Chart1" with two series of data, and another named "Chart2" with one series of data. Note that you can also use self.Plot("series name", value) to place the custom series on the same chart as the equity curve.

Quantopian

import numpy as np
from quantopian.algorithm import record

    def initialize(context):
        context.i = 0

    def handle_data(context, data):
        context.i += 0.25

        record(
            Series1=np.sin(context.i),
            Series2=np.cos(context.i),
            Series3=np.tan(context.i)
        )

QuantConnect

import numpy as np
        
class Algorithm(QCAlgorithm):
    def Initialize(self):
        self.i = 0

    def OnData(self, data):
        self.i += 0.25

        self.Plot('Chart1', 'Series1', np.sin(self.i))
        self.Plot('Chart1', 'Series2', np.cos(self.i))
        self.Plot('Chart2', 'Chart2 Series1', np.tan(self.i))

For more information on plotting in QuantConnect, visit the Charting documentation page.

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page helpful?

Contribute to the documentation: