Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
SMA calculation in pipeline

Hello all. I am trying to calculate a SMA of a calculated column in a pipeline but get an error message "NonWindowSafeInput: Can't compute windowed expression".

from quantopian.pipeline.data.user_5be5baf2fba49a6131414ae2 import suzano
from quantopian.pipeline.data.user_5be5baf2fba49a6131414ae2 import usdbrl
from quantopian.pipeline.data.user_5be5baf2fba49a6131414ae2 import pulp
from quantopian.pipeline.data.user_5be5baf2fba49a6131414ae2 import selic
from quantopian.pipeline.data.user_5be5baf2fba49a6131414ae2 import suz

from odo import odo

def make_pipeline():

suz_adr = suz.close.latest  
custo_BRL = suzano.custo_caixa_brl_ton.latest  
prod_TTM = suzano.producao_ttm_mil_ton.latest*1000  
divida_USD = suzano.div_liq_bi_usd.latest*1000000000  
qusdbrl = usdbrl.close.latest  
qpulp = pulp.ultimo.latest  
sselic = selic.selic.latest  
qselic = sselic/100  
shares = 1361260000  

tir = (qpulp-custo_BRL/qusdbrl)*prod_TTM*0.95/(suz_adr*shares+divida_USD)-qselic  
tir_med = SimpleMovingAverage(inputs = [tir], window_length=15)  
#fair = (((qpulp-custo_BRL/qusdbrl)*prod_TTM*0.95/(tir_med+qselic))-divida_USD)/shares  
#desconto = suz_adr/fair-1  

long = suz_adr >-100  

securities_to_trade = long

return Pipeline(columns={  
    #'fair':fair,  
    #'desconto':desconto,  
    #'selic':qselic,  
    #'pulp':qpulp,  
    #'long':long,  
    'suz':suz_adr,  
    'tir':tir  
},  
screen = securities_to_trade)

results = run_pipeline(make_pipeline(),'2017-09-05','2020-06-25')
results.tail()

4 responses

Try without .latest for everything you want to use as a factor input

Thanks for the reply. Removing ".latest" did not work as well as the operations can only be performed using one entry, and not a column. I got the follow error:

"TypeError: unsupported operand type(s) for /: 'BoundColumn' and 'BoundColumn'"

The mathematical operations you can do with imported factors directly are limited. You can use a custom factor for this, it should work. Of course I can't test it because it's your private data but here's what I would do:

Tentor, thank you so much. It worked fine.

Cheers