Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Syntax Error where I see none
...
SMA_200 = fact.SimpleMovingAverage(inputs=[dat.USEquityPricing.close], window_length=200, mask=uni)  
...
...
200_diff = ((SMA_200 - dat.USEquityPricing.close)/SMA_200)  

When the algorithm is built (every once in a while I do this purely for the purpose of checking for syntax, run-time errors, etc.), it returns a syntax error on line 46 (which is the declaration of 200_diff). I don't see why that poses an error, and I would guess that it has something to do with the data types the two consist of. Vaguely similar calculations, however, do not pose syntax errors. Ex.: is_small_cap = (3000000 <= dat.Fundamentals.market_cap.latest <= 2000000000) does not present an error.

Hopefully, another set of eyes can figure out what's causing this, as I cannot. Thanks in advance.
I included the lines that would be the most helpful in solving this, but I can definitely respond with more if need be.

3 responses

I can help only to some degree here.

I've seen issues like that at times including errors for code that only existed in the past and isn't there anymore, forcing a theory: Maybe algos are pieced together on build from changes and that process becomes confused sometimes, but I don't know. Creating a new algo seemed to help.

One thing I do know. This sort of thing will only honor one of them:

price_filter = ( price_low < prices.latest < price_high )
is_small_cap = (3000000 <= dat.Fundamentals.market_cap.latest <= 2000000000)

So you'll want to separate them out for both to take effect. That's been my experience. Then it is fine.
m is the mask:

m   = (dat.Fundamentals.market_cap.latest <= 2000000000)  # is_small_cap  
m & = (3000000 <= dat.Fundamentals.market_cap.latest)  

@Blue Seahawk
Tried creating a new algo and copy/pasting the code into it and nothing changed. Oh well. For the time being I've just deleted that portion and I'll just put the calculations somewhere else in the code. Thank you.

This may help,

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.data import Fundamentals  
from quantopian.pipeline import Pipeline, filters  
# -------------------------------------------------------------------  
STK_SET, UB, LB = filters.QTradableStocksUS(), 2000000000, 300000000  
# -------------------------------------------------------------------  
def initialize(context):  
    market_cap = Fundamentals.market_cap.latest  
    small_cap = (STK_SET & (market_cap < UB ) & (market_cap > LB))  
    attach_pipeline(Pipeline(columns = {'market_cap': market_cap}, screen = small_cap) , 'market_cap_pipe')

def before_trading_start(context, data):  
    stocks = pipeline_output('market_cap_pipe').index  
    MC = pipeline_output('market_cap_pipe').market_cap

    small_cap_MC = 0  
    for stock in stocks:  
        small_cap_MC += MC[stock] 

    print (small_cap_MC, len(stocks))  
    record(small_cap_MC = small_cap_MC)