Hi,
I have a test csv file with signals for each day that I want to trade with. After using fetch csv and universe_func, I was able to get the symbols into my universe.
However, when I run the program, I get the runtime error 'SIDData' object has no attribute 'price'. I need the current price of the security for part of the algorithm.
I followed the example of using fetcher to create custom universe. Does anyone know what I am doing wrong?
import pandas as pd
pd.set_printoptions(max_columns=10)
def initialize(context):
# import the custom CSV data file
fetch_csv("https://dl.dropboxusercontent.com/s/jk2aldddnstbduy/analyst action spy trade may 2014.csv",
pre_func=preview,
post_func=preview,
date_column='date',
universe_func=my_universe)
context.max_notional = 1000000.1
context.min_notional = -1000000.0
context.istraded = {}
# my_universe returns a set of securities that define your universe.
def my_universe(context, fetcher_data):
# fetcher_data is the data resulting from the CSV file from fetcher.
# set my_stocks to be every sid in the fetcher_data
my_stocks = set(fetcher_data['sid'])
# log the size of the universe for debugging
context.count = len(my_stocks)
print 'total universe size: {c}'.format(c=context.count)
# return the sids we identified earlier
return my_stocks
# see a snapshot of your CSV for debugging
def preview(df):
log.info(' %s ' % df.head())
return df
def handle_data(context,data):
# Convert to EST timezone
exchange_time = pd.Timestamp(get_datetime()).tz_convert('US/Eastern')
# loop over the stocks in universe
for stock in data:
print stock.symbol
print data[stock].price