AAII-SV-CIMI Documentation AAII-SV-CIMI/20170327backtestLags/


20170327backtestLags


 
 
docit
index
/Users/katherinepaseman/Documents/projects/_Websites/paseman_AAII-SV-CIMI Website/docit.py

#===========================================================================================================
# Copyright (c) 2006-2015 Paseman & Associates (www.paseman.com).  All rights reserved.
#===========================================================================================================

 
Modules
       
importlib
os
pydoc
shutil

 
Functions
       
docit(template, note, filenames, target)
#===========================================================================================================
# create documentation.html and backup .py files
genIndex(title, body, target)
#===========================================================================================================
# create index.html

 
Data
        imgTemplate = '<br><br><h2 id=\'%s\'>%s</h2>\n<img border="0" width="820" src="%s.png"><br>\n'
template = '<html>\n<head>\n<title>%s %s</title>\n\n<script type...1>%s %s</h1><br><h2>%s</h2><br>%s</body>\n</html>\n'
 
 
20170327backtestLags
index
/Users/katherinepaseman/Documents/projects/_Websites/paseman_AAII-SV-CIMI Website/20170327backtestLags.py

# -*- coding: utf-8 -*-
#===========================================================================================================
# Copyright (c) 2006-2017 Paseman & Associates (www.paseman.com).  All rights reserved.
#===========================================================================================================

 
Modules
       
numpy
pandas
matplotlib.pyplot

 
Functions
       
determineBestLagAndPortfolio(portfolios, lags, plotPath=False)
#===========================================================================================================
determineBestTBillRate(pathname, target, portfolioname, priceTickers, lagName, lags, plotPath=False)
Given a portfolio and lag structure, which Risk free interest rate gives the best results?
flatten lambda l
search()

 
Data
        body = '\nThis routine figures out the best of two portfo...X,NAESX,FGOVX_lag18 128090.753962\n'
imgTemplate = '<br><br><h2 id=\'%s\'>%s</h2>\n<img border="0" width="820" src="%s.png"><br>\n'
template = '<html>\n<head>\n<title>%s %s</title>\n\n<script type...1>%s %s</h1><br><h2>%s</h2><br>%s</body>\n</html>\n'
 
 
DualMomentumUtilities
index
/Users/katherinepaseman/Documents/projects/_Websites/paseman_AAII-SV-CIMI Website/DualMomentumUtilities.py

#===========================================================================================================
# Not copyrighted, howver please attribute to Paseman & Associates (www.paseman.com). 
#===========================================================================================================
 
This module is standalone.
It is used primarily by the DualMomeentum programs

 
Modules
       
numpy
pandas
matplotlib.pyplot
re

 
Functions
       
idxToReturnCum(df, columnName)
#===========================================================================================================
loadTickers(path, tickers, index_col=0)
#===========================================================================================================
pct_change(srcColumn, periods)
pandas builtin 'pct_change' function takes a scaler 'periods' argument.
We iwsh it would take a column 'periods' argument,
Ideally df[srcColumn].pct_change(periods=periodsColumn).
 
This pct_change takes a column as the periods input, applying its value to each row.
E.g. df['VFINXlag'] = pct_change(df['VFINX'],periods=df['lag'])
http://stackoverflow.com/questions/42773199/error-in-variable-shift-in-pandas
pct_changeCompounded(srcColumn, periods)
Compound each position by the value in the periods slot
pjlAbsoluteMomentum(stocks, bills, lag=12)
p5 ThreeMomentumAlgorithms.pdf Peter James Lingane, February 3, 2017
p8 AAII 2017_final.pdf Peter James Lingane, February 11, 2017
Absolute Momentum compares the 12 month returns of US stocks and T - bills.
Assume series are numpy arrays, equal length, ascending and already lagged
Note: stocks[1:]/stocks[:-1] - 1 > bills[1:]/bills[:-1] - 1
==
stocks[1:]/stocks[:-1] > bills[1:]/bills[:-1]
pjlFundX(serieses, lags=[1, 3, 6, 12])
p6 ThreeMomentumAlgorithms.pdf Peter James Lingane, February 3, 2017
p9 AAII 2017_final.pdf Peter James Lingane, February 11, 2017
The FundX timer tests the average of the 1,3,6 and 12 month returns of US stocks.
If the sum (and average) are less than zero. The recommendation is to hold bonds.
pvDuelMomentum(args)
pvDuelMomentum - calculates DuelMomentum as described by Portfolio Visualizer's Tuomo Lampinen
(See pvRelativeMomentum above)
type(args) == <class 'pandas.core.series.Series'>;
args.index  is a list of keys; args.values is a list of values
US and foreign stock funds are passed first (args.values[:-2]);
cash fund is passed next to last. (args.values[-2])
TBill is passed last. (args.values[-1])
 
Usage: df['DM'] = df[['VFINXlag','NAESXlag','FGOVXlag','TBILL 12M']].apply(pvDuelMomentum,axis=1).shift(1)
 
Treasury Bill-6 Month
http://www.data360.org/dsg.aspx?Data_Set_Group_Id=243&page=4&count=100
3 Month Treasury Maturity Constant Rate
http://www.data360.org/dsg.aspx?Data_Set_Group_Id=2525
 
https://www.federalreserve.gov/datadownload/Build.aspx?rel=H15  TB Y1 Monthly
pvRelativeMomentum(args)
From Portfolio Visualizer's Tuomo Lampinen's example
Column F is "12-month time series momentum - VFINX 12M"
Column G is "12-month time series momentum - NAESX 12M"
Column H is "12-month time series momentum - TBILL 12M"
Cell I15 is Relative Momentum =IF(F14>=G14,"VFINX","NAESX")
Cell J15 is Dual Momentum =IF(MAX(F14:G14)>=H14,I15,"Out-of-market")
 
Usage: df['Relative Momentum'] = df[['VFINXlag','NAESXlag']].apply(pvRelativeMomentum,axis=1).shift(1)
pvgDuelMomentum(args)
GoldDuelMomentum - deduces DuelMomentum from Portfolio Visulaizer Output file
by comparing zeroth column entry to the rest of the passed columns.
results - lists column names which match the return passed in the zeroth column
setAxis()
E.g. df[['VFINX1','NAESX1','FGOVX1']].plot(ax=setAxis(),title="Plot 1")