Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Debugger Issue: is the namespace restricted in the debugger?

I'm experiencing unusual behavior in the debugger. Are there namespace restrictions in the debugger or more generally restrictions on assigning variables there?

It took like 10 attempts to get prices50 saved. Then when I went to get the moving average I ran into the following

> ma50 = prices50.mean()  
> ma50  
NameError: name 'ma50' is not defined  
> ma = prices50.mean()  
> ma  
ma: Series  

In general, it seems like the debugger doesn't 'like' variable names that include an underscore or numbers. Can someone point me in the right direction?

4 responses

Hi Michael,

Thanks for posting. I was unable to reproduce your issue based on the variable names you've given here. I tried using the debugger on this code:

import numpy as np  
import pandas as pd

def initialize(context):  
    prices50 = pd.Series(np.random.randn(50))  
    return None  

with an interrupt on the return None line. Does the assignment ma50 = prices50.mean() work for you with this skeleton code? Also, if you could provide me with some more details of your original situation, that would help me to solve the problem.

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

I think I figured it out.

And to clarify- my question was about assigning variables in the REPL environment of the debugger. I believe I was trying to inspect and play with the result of the context.ma50 = ma50 = prices50.mean() call when this happened.

Put a breakpoint on that line. Then, in the debugger manually try to assign the variable ma50 = prices50.mean() and print(ma50). And do the same for ma200. Then you should see it.

I guess the debugger must reserve variable names that are going to be assigned but haven't been assigned yet


def initialize(context):  
    context.security_list = [symbol('SPY')]  
    # Rebalance every day, 1 hour after market open.  
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open())  
    # Record tracking variables at the end of each day.  
    schedule_function(my_record_vars, date_rules.every_day(), time_rules.market_close())  


def before_trading_start(context, data):

    prices200 = data.history(context.security_list, 'price', 200, '1d')  
    prices50 = prices200[-50:]  
    context.ma50 = ma50 = prices50.mean()  
    context.ma200 = ma200 = prices200.mean()

You're right; the debugger reserves variable names that are going to be assigned later. Would you rather this isn't the case? If so I could put in a feature request for you.

:) Assuming that this was an intentional design decision- then I don't have nearly the information on the benefit trade-off of having it versus not having it to make that decision. And really, now that I understand that it's not a hard change for me.

I guess, to avoid confusion of future users, attempts to assign the variable should throw an informative exception instead of appearing like the assignment is successful- as it is now.