def main(df): df = base1.main(df) lipt = get_lipt() df = df[lipt] sym = df['sym'].values[0] vol = pd.read_csv(os.path.join(base.dir_vol(), sym + ".csv")) d = {'Date': 'date'} for each in vol.columns[1:]: d[each] = 'ta_' + each vol = vol.rename(columns=d) vol = vol.fillna(0) dfDate = df[["date"]] vol = pd.merge(how='left', left=dfDate, right=vol, left_on='date', right_on='date') vol = vol.fillna(0) print df.shape[1] df = pd.merge(how='left', left=df, right=vol, left_on="date", right_on="date") print df.shape[1] return df
def main(df): def call(row): if np.isnan(row['IvCall10']): return -1 if row['IvCall10'] > row["IvCall10_shift1"] * 1.0: # and row['IvPut10'] < row['IvPut10_shift1'] *1.0 and \ return 1 return 0 df.reset_index(drop=True, inplace=True) sym = df.ix[0].loc['sym'] df_vol = pd.read_csv(os.path.join(base.dir_vol(), sym + ".csv")) d = {'Date':'date'} df_vol = df_vol.rename(columns=d) df_vol = df_vol[["date", "IvCall10", "IvPut10"]] df = pd.merge(how = 'left', left = df, right =df_vol, left_on = 'date', right_on = 'date') df.loc[:,"IvCall10_shift1"] = df["IvCall10"].shift(1) df.loc[:,"IvPut10_shift1"] = df["IvPut10"].shift(1) df.loc[:,"volume_shift1"] = df["volume"].shift(1) df.loc[:,"ta_sig_vol"] = df.apply(lambda row : call(row), axis = 1) del df["IvCall10"] del df["IvCall10_shift1"] del df["IvPut10"] del df["IvPut10_shift1"] del df["volume_shift1"] return df
def main(args): lsym = yeod_b.get_sp500Top100() dir_vol = base.dir_vol() for sym in lsym: file_vol_per_sym = os.path.join(dir_vol, sym + ".csv") if os.path.isfile(file_vol_per_sym): continue vol = download_vol(sym) with open(file_vol_per_sym, "w") as f: print >> f, vol