Back to Community
How to debug in a right way

Hello guys, I am new to Quantopian and started to code on Quantopian recently. Currently I always feel frustrated when my code dosen't run and I am trying to figure out where goes wrong: There is no clue or hint at all except from a "backtest error" message, saying "Something went wrong starting a full backtest". So my question is how to debug in a right way? Thanks,


5 responses

First off, welcome!

It's best to not 'Run Full Backtest' until one has all the bugs out. Click on 'Build Algorithm' instead. This runs the algorithm but allows for interactive debugging. There is a pretty powerful debugger built into the IDE that allows one to step through the code, inspect variables, set breakpoints, and set conditional breakpoints. Take a look at the documentation .

A lot of simple errors can be found just by looking at the line number indicated in the error message. The line numbers are sometimes misleading though. Often the previous line is what is causing the problem. Also, the number sometimes just points to the calling function and the real problem is at a line inside the function.

Hope that helps.

Dan, thank you so much. I got it.

Also, just post your code to the forum and ask for help. If you think you have some "secret sauce" just cut it out and replace it with some trivial code.

Personally, I don't use the debugger, but I do use print to see what's going on, if something isn't making sense.

Hi, I'm new to Quantopian and Python.
Firstly thank you in advance to anyone whom can help me with this rather simple problem.
I've just trying to figure out how to echo or print back the variables from calculations into the log or the debugger using the IDE. I can use the debugger to get information out of objects, but not the variables.

It's just a modification of - Pipeline Tutorial - Lesson 12 1.
The code is as follows:

def make_pipeline():  
    Create our pipeline.  

    # Base universe set to the QTradableStocksUS.  
    base_universe = QTradableStocksUS()

    # 10-day close price average.  
    mean_5 = SimpleMovingAverage(  

    # 30-day close price average.  
    mean_14 = ExponentialWeightedMovingAverage(  
    percent_difference = (mean_5 - mean_14) / mean_14  
    # Filter to select securities to short.  
    shorts =  
    # print shorts  
    # Filter to select securities to long.  
    longs = percent_difference.bottom(75)

    # Filter for all securities that we want to trade.  
    securities_to_trade = (shorts | longs)

    return Pipeline(  
            'longs': longs,  
            'shorts': shorts  

I am trying

print make_pipeline.mean_14  

among a dozen other variations.

It would be nice to see what the values are on each iteration of the function and which stock they go with.



Some sort of a resolution in a roundabouts sort of a way.
I added:

    return Pipeline(  
            'longs': longs,  
            'shorts': shorts,  
            'mean_5': mean_5  # This line here.  

into the return statement. Then in the IDE I use the debugger as explained in
placing a break point in a later function where I use

pipe_results = pipeline_output('my_pipeline')  

In the white and yellow window of the debugger I type:


and I get a columned output showing the variables (properties)
shorts and

Does anyone have a way to print a variable (property) to the log as it iterates each instance?