Created on Nov 22, 2012 @author: alex ''' import pandas as pd import matplotlib.pylab as plt import statsmodels.api as sm from scipy import stats import numpy as np from datetime import datetime as dt from functions import efa # Clean up data import foundation as fd fx_data = fd.getFxRates() fx_data = fx_data[['Currency', 'SPOT']] # Subsetting data into foreign currencies foreign = fx_data.ix[fx_data.Currency != 'USD',:] foreign = foreign.set_index('Currency', append = True) foreign = foreign.groupby(level = 1).apply(lambda x: x.fillna(method = 'ffill',limit = 30 )) foreign['spot_rets'] = foreign.groupby(level = 1).SPOT.pct_change() TI = pd.DataFrame() for name, rets in foreign.groupby(level = 1).spot_rets: if TI.empty: TI = pd.DataFrame(index = [i[0] for i in rets.index]) TI[name] = rets.values else: TI = TI.join(pd.Series(rets.values, index = [i[0] for i in rets.index], name = name))
import numpy as np import pandas as pd import scipy as stats import foundation as fd from functions import efa fxData=fd.getFxRates() fxData = fxData[fxData.Currency!='USD'] fxData = fxData.reset_index() fxData = fxData[['Date','Currency', 'SPOT']].set_index(['Currency','Date']) fxData = fxData.groupby(level = 0).apply(lambda x: x.fillna(method = 'ffill',limit = 30 )) emafxData = fxData.groupby(level = 0).SPOT.apply(lambda x: efa(x,0.97,300)) fxData = fxData.groupby(level = 0).SPOT.values signal = fxData - emafxData print signal