Back to Community
Crossover strategies, how to store yesterday values ?


Doing some crossover strategies. I am calling the pipeline on market open, everyday in my algorithm. I get some price results, technical indicators etc.

For convenience, it would be very nice to store all today values with yesterdays previous values in a neighbouring coulumn. It would be very nice to create filters that way. But how is that most easily done ? My favourite solution would be a generic solution, so I can use it to store yesterday value of high, low, close, open, SMA, EMA etc. to easy evaluate todays value. Maybe it is possible to export the value and store it in a vector in a custom class and recall that the day after ?

from quantopian.pipeline import Pipeline  
from quantopian.research import run_pipeline

# Used to find Factors in pipeline  
from import USEquityPricing  
from quantopian.pipeline.factors import CustomFactor  
from quantopian.pipeline.filters import Q500US

def make_pipeline():  
    base_universe = Q500US()  
    expensive = USEquityPricing.close.latest > 1700  
    return Pipeline(  
        screen = base_universe & expensive,  
            'close': USEquityPricing.close.latest,  
            'yesterdayvalue': ***Possibly call some class here that stored all the values (close, high, low etc.) from last pipeline run***  

results = run_pipeline(make_pipeline(), '2019-03-29', '2019-03-30')
results showing only latest close price

2019-03-29 00:00:00+00:00
Equity(16841 [AMZN]) 1773.67
Equity(19917 [BKNG]) 1729.31
2019-04-01 00:00:00+00:00
Equity(16841 [AMZN]) 1781.09
Equity(19917 [BKNG]) 1744.91

Wanted results showing latest close price and previous close price
2019-03-29 00:00:00+00:00
Equity(16841 [AMZN]) 1773.67 * closing value from 2019-03-28
Equity(19917 [BKNG]) 1729.31 * closing value from 2019-03-28
2019-04-01 00:00:00+00:00
Equity(16841 [AMZN]) 1781.09 1773.67
Equity(19917 [BKNG]) 1744.91 1729.31

Really stock on this, any inputs are appreciated ! Thanks

1 response