def getData(self, tickers) : settings = Settings() dp = TimeSeries(settings).get_agg_ETF_data(tickers) dp = dp.fillna(method='pad', axis=0) dp = dp.fillna(method='bfill', axis=0) dp = dp.dropna() dp = dp.reindex_axis(['open', 'high', 'low', 'close', 'volume', 'price'], axis=2) return dp
import Data.StockDataManager as sm import Data.TimeSeries as ts settings = sm.Settings() tmgr = sm.TaskManager(settings) data = ts.TimeSeries(settings).get_stock_series(['000001'], start='2012-01-01', fields=['close']) price = data['close'] import pyhht.emd as emd import numpy as np imfs = emd.EMD(np.array(price))
result = ts.adfuller(x) # Calculate the half-life of reversion price = pd.Series(x) lagged_price = price.shift(1).fillna(method="bfill") delta = price - lagged_price beta = np.polyfit(lagged_price, delta, 1)[0] #Use price(t-1) to predicate delta. half_life = (-1 * np.log(2) / beta) return result[0], result[1], half_life from Data.StockDataManager import * from Data.TimeSeries import * if __name__ == "__main__": tickers = ['GOOG/NYSE_SPY'] settings = Settings() dp = TimeSeries(settings).get_agg_ETF_data(tickers) df = dp[:, :, 'price'] #df.plot(figsize=[20,12]) n = df.copy() # n['scaling'] = scaling(df, 50) # n['centering'] = centering(df, 50) n['normalization'] = Normalization(df.values, 50) n['regnormal'] = RegularNormalization(df.values, 50) n.plot() print 'done!'
'GOOG/NYSE_VWO', # Vanguard Emerging Market Stock ETF #'GOOG/NYSE_VNQ', # Vanguard MSCI US Reits 'GOOG/NYSE_IYR', # iShares U.S. Real Estate ETF 'GOOG/NYSE_RWX', # SPDR DJ Wilshire Intl Real Estate ETF 'GOOG/NYSEARCA_TLT', # 20 Years Treasury ETF 'GOOG/NYSEARCA_TLH', # 15-20 Years Treasury 'GOOG/AMEX_GSG', # GSCI Commodity-Indexed Trust Fund 'GOOG/NYSEARCA_GLD' # SPDR Gold ETF ] settings = Settings() dp = TimeSeries(settings).get_agg_data(tickers) dp = dp.fillna(method='pad', axis=0) dp = dp.fillna(method='bfill', axis=0) dp = dp[:,:,:] dp[:, :,'price'].plot(figsize=[20,10]) df_rets = dp[:,:,'price'].pct_change().dropna()
'GOOG/NYSEARCA_XLI', 'GOOG/NYSEARCA_XLK', 'GOOG/NYSEARCA_XLP', 'GOOG/NYSEARCA_XLU', 'GOOG/NYSEARCA_XLV', 'GOOG/NYSEARCA_XLY' ] bm_tickers = [ 'GOOG/NYSE_SPY', 'GOOG/NYSEARCA_TLT', 'GOOG/NYSEARCA_GLD' #gold ] settings = Settings() dp = TimeSeries(settings).get_agg_data(sector_tickers+bm_tickers) dp = dp.fillna(method='pad', axis=0) dp = dp.fillna(method='bfill', axis=0) dp = dp[:,'2000-01-01'::,:] dp = dp.dropna() rets = pd.DataFrame() rets[1] = Momentum_Sector_Rotation(dp).run_trading().portfolio_value #rets[1] = Portfolio1(dp).run_trading().portfolio_value #rets[2] = Portfolio2(dp).run_trading().portfolio_value # rets[3] = Portfolio3(dp).run_trading().portfolio_value # rets[4] = Portfolio4(dp).run_trading().portfolio_value # rets[5] = Portfolio5(dp).run_trading().portfolio_value #
] sector_tickers = [ 'GOOG/NYSEARCA_XLB', 'GOOG/NYSEARCA_XLE', 'GOOG/NYSEARCA_XLF', 'GOOG/NYSEARCA_XLI', 'GOOG/NYSEARCA_XLK', 'GOOG/NYSEARCA_XLP', 'GOOG/NYSEARCA_XLU', 'GOOG/NYSEARCA_XLV', 'GOOG/NYSEARCA_XLY' ] bm_tickers = [ 'GOOG/NYSE_SPY', 'GOOG/NYSEARCA_TLT', 'GOOG/NYSEARCA_GLD' #gold ] settings = Settings() dp = TimeSeries(settings).get_agg_data(sector_tickers + bm_tickers) dp = dp.fillna(method='pad', axis=0) dp = dp.fillna(method='bfill', axis=0) dp = dp[:, '2000-01-01'::, :] dp = dp.dropna() rets = pd.DataFrame() rets[1] = Momentum_Sector_Rotation(dp).run_trading().portfolio_value #rets[1] = Portfolio1(dp).run_trading().portfolio_value #rets[2] = Portfolio2(dp).run_trading().portfolio_value # rets[3] = Portfolio3(dp).run_trading().portfolio_value # rets[4] = Portfolio4(dp).run_trading().portfolio_value # rets[5] = Portfolio5(dp).run_trading().portfolio_value # # rets[6] = Portfolio6(dp).run_trading().portfolio_value # rets[7] = Momentum(dp).run_trading().portfolio_vlaue