Can some one help with this fetcher problem i am having?
I am doing 2 different fetches very similar in nature, Except for the name of the columns and format of the dates in the second table
Yet, the first one works, while the second doesn't.
Any ideas?
def fix_datecol(df):
# reformat date column into string format
df['TRADE_DATE'] = df['TRADE_DATE'].apply(lambda x: str(x))
log.info('\nfix_datecol %s ' % df.head())
return df
def fix_datecol1(df):
# reformat date column into string format
log.info('\nfix_datecol1 %s ' % df.head())
return df
def rename_col(df):
#rename cols to what handle_data expects
df = df.rename(columns={'United States': 'price'})
# df = df.rename(columns={'CPI':'price'})
df = df.fillna(method='ffill')
df = df[['price', 'sid']]
log.info('\nrename_col %s ' % df.head())
return df
def rename_col1(df):
#rename cols to what handle_data expects
df = df.rename(columns={'Value': 'price'})
df = df.fillna(method='ffill')
df = df[['price', 'sid']]
log.info('\nrename_col1 %s ' % df.head())
return df
# Put any initialization logic here. The context object will be passed to
# the other methods in your algorithm.
def initialize(context):
fetch_csv( 'https://dl.dropboxusercontent.com/u/169032081/US_monthly_series_inflation_idx.csv',
symbol='Inflation_Index',
date_column = 'TRADE_DATE',
date_format = '%Y%m%d',
pre_func=fix_datecol,
post_func=rename_col)
fetch_csv('https://www.quandl.com/api/v1/datasets/FRED/CPIAUCSL.csv',
symbol='Consumer_Price_Index',
date_column='Date',
date_format='%Y-%m-%d',
pre_func=fix_datecol1,
post_func=rename_col1)
context.stock = sid(8554)
# pass
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
# Implement your algorithm logic here.
# data[sid(X)] holds the trade event data for that security.
# context.portfolio holds the current portfolio state.
# Place orders with the order(SID, amount) method.
# TODO: implement your own logic here.
# print "Inflation_Index=%s, USCPI=%s"%(data['Inflation_Index']['price'],data['USCPI']['price'])
log.info('\n %s ' % data['Inflation_Index'])
log.info('\n %s ' % data['Consumer_Price_Index'])
log.info('\n %s ' % data['Inflation_Index']['price'])
log.info('\n %s ' % data['Consumer_Price_Index']['price'])
record(Inflation_Index=data['Inflation_Index']['price'],
Infaltion_Index2=data['Consumer_Price_Index']['price'])
order(context.stock,10)