Hi. total newbie here, so probably doing something obviously wrong.
I am importing a predefined universe via fetch, then attempting to filter down that universe based on some signals. when i apply the pipeline, the size of the universe grows. is there a way to apply the filter to just the existing universe? I'm having some issues with fetch as well, so this is just a working sample with dummy data.
def initialize(context):
#set universe to the contents of our file
fetch_csv(
'https://dl.dropboxusercontent.com/u/169032081/SP500.csv',
date_column = 'date', universe_func=my_universe, date_format = '%M/%D/%Y')
#setup filter
pipe = Pipeline()
pipe = attach_pipeline(pipe, name='my_pipeline')
sma_1 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=1)
sma_8 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=8)
sma_20 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=20)
dollar_volume = AvgDailyDollarVolumeTraded(window_length=7)
pipe.add(sma_1, 'sma_1')
pipe.add(sma_8, 'sma_8')
pipe.add(sma_20, 'sma_20')
pipe.add(dollar_volume, 'dollar_volume')
pipe.set_screen( (sma_8>sma_20) & (sma_1>sma_20) & (dollar_volume>400000.0) )
# my_universe returns a set of securities that define your universe passed to the fetcher function
def my_universe(context, fetcher_data):
# limit universe to securities that meet our uptrend filter
# set my_stocks to be every security in the fetcher_data
my_stocks = set(fetcher_data['sid'])
return my_stocks
# The handle_data function is run every bar.
def handle_data(context,data):
pass
def before_trading_start(context, data):
if len(data) > 0:
# limit universe to securities that meet our filter
log.debug('pre-filter universe size {c}'.format(c=len(data)))
sids = pipeline_output('my_pipeline')
log.debug('post-filter universe size {c}'.format(c=len(sids)))
update_universe(sids)
record(universe_size = len(data))
logs show:
2013-10-02before_trading_start:56DEBUGpre-filter universe size 494
2013-10-02before_trading_start:58DEBUGpost-filter universe size 3223
any ideas? the call to update_universe(sids) is also failing, which i suspect is related