Notebook
In [4]:
"""
Rotate between S&P 500, mid-cap value, small cap international, emerging markets, and intermediate treasuries
    Use momentum (short term moving average ratio to long term)
$10K initial, with IB fees
"""
bt = get_backtest('58a10bac98a6065defa8d7b0')
bt.create_full_tear_sheet()
100% Time: 0:00:01|###########################################################|
Entire data start date: 2008-07-01
Entire data end date: 2016-12-30


Backtest Months: 102
Performance statistics Backtest
annual_return 0.14
cum_returns_final 1.96
annual_volatility 0.16
sharpe_ratio 0.89
calmar_ratio 0.53
stability_of_timeseries 0.80
max_drawdown -0.26
omega_ratio 1.17
sortino_ratio 1.29
skew 0.03
kurtosis 4.38
tail_ratio 1.05
common_sense_ratio 1.19
gross_leverage 1.00
information_ratio 0.01
alpha 0.11
beta 0.26
Worst drawdown periods net drawdown in % peak date valley date recovery date duration
0 25.67 2014-09-05 2016-01-08 NaT NaN
1 13.40 2010-04-23 2010-05-20 2010-10-05 118
2 11.85 2009-06-01 2009-06-23 2009-08-03 46
3 10.64 2009-10-19 2009-10-30 2009-11-16 21
4 9.35 2012-03-19 2012-05-18 2012-12-20 199

[-0.019 -0.037]
/usr/local/lib/python2.7/dist-packages/numpy/lib/function_base.py:3834: RuntimeWarning: Invalid value encountered in percentile
  RuntimeWarning)
Stress Events mean min max
Lehmann 0.03% -1.77% 1.88%
US downgrade/European Debt Crisis 0.17% -1.46% 1.55%
Fukushima 0.17% -1.07% 2.03%
EZB IR Event -0.01% -1.54% 1.61%
Sept08 0.01% -1.77% 1.88%
2009Q1 -0.10% -1.40% 1.63%
2009Q2 0.46% -4.87% 7.01%
Flash Crash -0.43% -3.51% 5.12%
Apr14 0.04% -1.75% 0.99%
Oct14 -0.22% -2.00% 1.72%
Fall2015 -0.28% -3.33% 0.81%
GFC Crash 0.08% -2.04% 3.49%
Recovery 0.09% -4.87% 7.01%
New Normal 0.02% -4.13% 3.63%
Top 10 long positions of all time max
SCZ-35248 100.83%
IEF-23870 100.49%
EEM-24705 100.10%
IJJ-21770 100.00%
IVV-21513 99.97%
Top 10 short positions of all time max
Top 10 positions of all time max
SCZ-35248 100.83%
IEF-23870 100.49%
EEM-24705 100.10%
IJJ-21770 100.00%
IVV-21513 99.97%
All positions ever held max
SCZ-35248 100.83%
IEF-23870 100.49%
EEM-24705 100.10%
IJJ-21770 100.00%
IVV-21513 99.97%
In [3]:
import time
from datetime import datetime, timedelta

date = time.strftime("%Y-%m-%d")
#date = '2010-01-05'

import pandas as pd
import math as math
import numpy as np

def asset_momentum(assets, short_t, long_t):
    n = len(assets)
    i = -1
    best = 0
    for x in range(n):
        prices = get_pricing(symbols(assets[x]), start_date=(datetime.strptime(date, '%Y-%m-%d') - timedelta(days=300)), end_date=date, frequency = 'daily')
        st = prices['close_price'][-(short_t+1):-1].mean()
        lt = prices['close_price'][-(long_t+1):-1].mean()
        ratio = st/lt
        print assets[x] + '\n {:03.0f} Day: '.format(short_t) + '{:01.2f}'.format(st) + '\n {:03.0f} Day: '.format(long_t) + '{:01.2f}'.format(lt) + '\n Ratio: {:01.3f} '.format(ratio)
        if ratio > best:
            i = x
            best = ratio
    print '\nBest: ' + assets[i] + '\n'

tsp = ['IVV', #C Fund Equivalent - IVV (ISHARES CORE S&P 500 ETF)
       'IJR', #S Fund Equivalent - IJR (ISHARES CORE S&P SMALL-CAP ETF)
       'EFA', #I Fund Equivalent - EFA (ISHARES MSCI EAFE ETF)
       'AGG', #F Fund Equivalent - AGG (ISHARES CORE U.S. AGGREGATE BOND)
       'SHY'] #G Fund Equivalent - SHY (ISHARES 1-3 YEAR TREASURY BOND)
asset_momentum(tsp,20,180)

best = [  'IEF', #IEF (ISHARES 7-10 YEAR TREASURY BOND)
          'IVV', #IVV (ISHARES CORE S&P 500)
          'IJJ', #IJJ (ISHARES S&P MID-CAP 400 VALUE)
          'SCZ', #SCZ (ISHARES MSCI EAFE SMALL-CAP)
          'EEM'] #EEM (ISHARES MSCI EMERGING MARKETS)
asset_momentum(best,20,120)
IVV
 020 Day: 229.56
 180 Day: 217.43
 Ratio: 1.056 
IJR
 020 Day: 68.48
 180 Day: 62.72
 Ratio: 1.092 
EFA
 020 Day: 59.72
 180 Day: 57.40
 Ratio: 1.040 
AGG
 020 Day: 108.11
 180 Day: 109.69
 Ratio: 0.986 
SHY
 020 Day: 84.47
 180 Day: 84.61
 Ratio: 0.998 

Best: IJR

IEF
 020 Day: 104.98
 120 Day: 107.42
 Ratio: 0.977 
IVV
 020 Day: 229.56
 120 Day: 220.37
 Ratio: 1.042 
IJJ
 020 Day: 147.46
 120 Day: 138.44
 Ratio: 1.065 
SCZ
 020 Day: 51.78
 120 Day: 50.47
 Ratio: 1.026 
EEM
 020 Day: 37.27
 120 Day: 36.24
 Ratio: 1.028 

Best: IJJ

In [ ]: