I'm sorry for the constant back and forth and appreciate your willingness to help, but I might not be getting something.
The following test shows the data is overwritten by update_universe().
This is the output to the console. Notice "VVUS" is in the first period but not in the subsequent period.
2015-01-05 PRINT [u'ATRS' u'CTIC' u'CUR' u'SNTA' u'VVUS']
2015-01-06 PRINT [u'ATRS' u'BPTH' u'CTIC' u'CUR' u'SNTA']
2015-01-07 PRINT [u'ATRS' u'BPTH' u'CTIC' u'CUR' u'SNTA']
If I hold a position in "VVUS", it will then remain in data in subsequent periods
2015-01-05 PRINT [u'ATRS' u'CTIC' u'CUR' u'SNTA' u'VVUS']
2015-01-06 PRINT [u'ATRS' u'BPTH' u'CTIC' u'CUR' u'SNTA' u'VVUS']
2015-01-07 PRINT [u'ATRS' u'BPTH' u'CTIC' u'CUR' u'SNTA' u'VVUS']
Test Setting and Code:
From 2015-01-04 to 2015-01-07 with $5,000 initial capital (daily data)
Hold no positions:
import numpy as np
# Put any initialization logic here. The context object will be passed to
# the other methods in your algorithm.
def initialize(context):
pass
def before_trading_start(context, data):
fundamental_df = get_fundamentals(
query(fundamentals.valuation.market_cap)
.filter(fundamentals.asset_classification.morningstar_sector_code == 206)
.filter(fundamentals.valuation.market_cap / fundamentals.valuation.shares_outstanding >= 2.0)
.filter(fundamentals.valuation.market_cap / fundamentals.valuation.shares_outstanding <= 2.10)
.order_by(fundamentals.valuation.market_cap.desc())
.limit(5)
)
context.stocklist = list(fundamental_df.columns.values)
update_universe(context.stocklist)
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
print(np.sort([x.symbol for x in data]))
for s in data:
if s.symbol == 'VVUS':
pass
Hold a position:
import numpy as np
# Put any initialization logic here. The context object will be passed to
# the other methods in your algorithm.
def initialize(context):
pass
def before_trading_start(context, data):
fundamental_df = get_fundamentals(
query(fundamentals.valuation.market_cap)
.filter(fundamentals.asset_classification.morningstar_sector_code == 206)
.filter(fundamentals.valuation.market_cap / fundamentals.valuation.shares_outstanding >= 2.0)
.filter(fundamentals.valuation.market_cap / fundamentals.valuation.shares_outstanding <= 2.10)
.order_by(fundamentals.valuation.market_cap.desc())
.limit(5)
)
context.stocklist = list(fundamental_df.columns.values)
update_universe(context.stocklist)
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
print(np.sort([x.symbol for x in data]))
for s in data:
if s.symbol == 'VVUS':
order(s, 1)