Esempio n. 1
0
    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
Esempio n. 2
0
            '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
    rets.plot(figsize=[20,12])
Esempio n. 3
0

    try:
        # Get the strongest 5 in momentum
        mom = returns_6m.T.sum(axis=1)
        selected_indices = mom[mom>0].order().tail(len(mom) /2).index
#         selected_indices = mom.index
#         selected_indices = mom[mom > 0 ].index
        selected_returns = returns_60d[selected_indices]

        weights = minimize_vol(selected_returns.T)
#         weights = minimize_vol(returns_60d.T)
        # Rebalance portfolio accordingly
        for stock, weight in zip(selected_returns.columns, weights):
            order_target_percent(stock, weight)
    except :
        # Sometimes this error is thrown
        # ValueError: Rank(A) < p or Rank([P; A; G]) < n
        pass


# Instantinate algorithm
algo = TradingAlgorithm(initialize=initialize,
                        handle_data=handle_data)
# Run algorithm
results = algo.run(dp.dropna())
ret_ports = pd.DataFrame()
ret_ports[5] = results.portfolio_value
ret_ports.plot(figsize=[20,10])

print results
Esempio n. 4
0
        '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
    rets.plot(figsize=[20, 12])

    print 'done!'