org.akutan.drivers
Class DiversificationDriver

java.lang.Object
  extended by org.akutan.drivers.DiversificationDriver

public class DiversificationDriver
extends java.lang.Object

This class is a driver program which reads a file of industry sector returns from the Fama/French data and generates a sequence of portfolios using 60 month rolling returns. These portfolios are then evalutated on the basis of ex post return.

Since:
11 September 2007

Field Summary
protected  java.lang.String[] _assets
          Array of the asset class names for use on output
protected  cern.colt.matrix.DoubleMatrix2D _mktCaps
          Market Cap in some units for each sector for each month
protected  int[] _months
          Index of months to match up with the data (both returns and market caps)
protected  cern.colt.matrix.DoubleMatrix2D _returns
          Annualized returns stored as a decimal
 
Constructor Summary
DiversificationDriver()
          Constructs
 
Method Summary
 double computeOutOfSample(int ptr, double[] w)
          Computes the out of sample 1 month return
 double computeOutOfSample12(int ptr, double[] w)
          Computes the out of sample 12 month return for the next 12 month period starting with ptr.
 void dumpLastMktCap()
          For debugging dumps out the last line read from the file
 void dumpLastReturns()
          For debugging dumps out the last line read from the file
protected  void dumpPoints(java.util.List<SolvedPoint> points)
           
 cern.colt.matrix.DoubleMatrix1D evolve(int ptr, double[] aw)
          Evolves a portfolio one step into the future and computes new weights
 int[] getMonths()
          Getter for use in JUnit
 void loadData(java.lang.String fileName)
          Loads return data by asset and date
 void loadExcessFrontData(java.lang.String fileName)
          Loads return data by asset and date
 void loadFrontData(java.lang.String fileName)
          Loads return data by asset and date
 void loadMktCap(java.lang.String fileName)
          Loads market cap data
static void main(java.lang.String[] args)
           
protected  java.util.List<EfficientFrontier.SampleData> prepareEstimates(int start, int length, cern.colt.matrix.DoubleMatrix1D mu, cern.colt.matrix.DoubleMatrix2D V)
          Called to compute sample returns and variances for the period specified.
protected  void processResults(int start, int length, SolvedPoint sp)
          Called to porocess a point solution and see how it will do in out of sample testing.
protected  void runTest1(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest10(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest11(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest12(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest13(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest14(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest15(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest16(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest2(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest3(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest4(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest5(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest6(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest7(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  void runTest8(int start, int length)
          A Black-Litterman based momentum strategy ala the one Fabozzi uses in his book on Robust Portfolio managerment.
protected  void runTest9(int start, int length)
          For a given starting month, computes the mean and covariance for the window of size length.
protected  SolvedPoint sortResults(java.util.List<SolvedPoint> l)
          Sorts by sharpe ratio (note this didn't work so well in the past for some unknown reason.
protected  SolvedPoint sortResults10(java.util.List<SolvedPoint> l)
          Estimates the point with risk of 10% and returns the closest pt less than 10%
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_assets

protected java.lang.String[] _assets
Array of the asset class names for use on output


_months

protected int[] _months
Index of months to match up with the data (both returns and market caps)


_returns

protected cern.colt.matrix.DoubleMatrix2D _returns
Annualized returns stored as a decimal


_mktCaps

protected cern.colt.matrix.DoubleMatrix2D _mktCaps
Market Cap in some units for each sector for each month

Constructor Detail

DiversificationDriver

public DiversificationDriver()
Constructs

Method Detail

getMonths

public int[] getMonths()
Getter for use in JUnit

Returns:
Array of month ids (yyyymm) for the data

loadData

public void loadData(java.lang.String fileName)
Loads return data by asset and date

Parameters:
fileName - The name of the input file. It is expected to be a text file contaning columnar data, with a single line header of asset titles and the date in the first column from the left. Returns are specified in percent.

loadFrontData

public void loadFrontData(java.lang.String fileName)
                   throws java.lang.Exception
Loads return data by asset and date

Parameters:
fileName - The name of the input file. It is expected to be a text file contaning columnar data, with a single line header of asset titles and the date in the first column from the left. Returns are specified in percent.
Throws:
java.lang.Exception

loadExcessFrontData

public void loadExcessFrontData(java.lang.String fileName)
                         throws java.lang.Exception
Loads return data by asset and date

Parameters:
fileName - The name of the input file. It is expected to be a text file contaning columnar data, with a single line header of asset titles and the date in the first column from the left. Returns are specified in percent.
Throws:
java.lang.Exception

loadMktCap

public void loadMktCap(java.lang.String fileName)
Loads market cap data

Parameters:
fileName - The name of the input file. It is expected to be a text file containing columnar data, with a single line header of asset titles and the date in the first column from the left. Returns are specified in percent.

runTest1

protected void runTest1(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the return solver for the generation of an efficient frontier.

Parameters:
start - Starting index of window in instance data
length - Length of window

computeOutOfSample

public double computeOutOfSample(int ptr,
                                 double[] w)
Computes the out of sample 1 month return

Parameters:
ptr - Points to the out of sample month
w - The asset weights to use
Returns:
The out of sample 1 month return

computeOutOfSample12

public double computeOutOfSample12(int ptr,
                                   double[] w)
Computes the out of sample 12 month return for the next 12 month period starting with ptr.

Parameters:
ptr - Index in the instance data of the out of sample start month
w - Asset weights
Returns:
Returns the out of sample return

evolve

public cern.colt.matrix.DoubleMatrix1D evolve(int ptr,
                                              double[] aw)
Evolves a portfolio one step into the future and computes new weights

Parameters:
ptr - Points to the next time period returns
aw - Starting Asset weights
Returns:
Returns the ending asset weights for the specified step

prepareEstimates

protected java.util.List<EfficientFrontier.SampleData> prepareEstimates(int start,
                                                                        int length,
                                                                        cern.colt.matrix.DoubleMatrix1D mu,
                                                                        cern.colt.matrix.DoubleMatrix2D V)
Called to compute sample returns and variances for the period specified.

Parameters:
start - Starting period
length - Length in periods
mu - On return contains the arithmetic mean of the returns
V - On return contains the covariance matrix for the period
Returns:
List of period return data

runTest2

protected void runTest2(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes the actual mean, but the state variance to the StateReturnSolver for solution and generation of an efficient frontier.

Parameters:
start -
length -

runTest3

protected void runTest3(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the diversified solver for the generation of an efficient frontier.

Parameters:
start -
length -

runTest16

protected void runTest16(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the diversified solver for the generation of an efficient frontier.

Parameters:
start -
length -

runTest11

protected void runTest11(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the entropy solver for the generation of an efficient frontier.

Parameters:
start -
length -

runTest4

protected void runTest4(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the state preference solver and converts back to mean variance space before it solves for maximum sharpe ratio portfolio.

Parameters:
start -
length -

runTest5

protected void runTest5(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the state preference solver and solves for maximum sharpe ratio portfolio in state space. Note this case turns out to be not that interesting as the maximum sharpe ratio portfolio in state space is very close to the minimum variance portfolio.

Parameters:
start -
length -

runTest6

protected void runTest6(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the spherical shrinkage solver.

Parameters:
start -
length -

runTest7

protected void runTest7(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then we just use a cap weighted portfolio and see how it works going forwards. This should be the lowest turnover portfolio.

Parameters:
start -
length -

runTest8

protected void runTest8(int start,
                        int length)
A Black-Litterman based momentum strategy ala the one Fabozzi uses in his book on Robust Portfolio managerment. We use the summary statistics from the last 9 months as the forecast views and apply them to the equlibrium to determine our asset forecasts.

Parameters:
start -
length -

dumpPoints

protected void dumpPoints(java.util.List<SolvedPoint> points)

runTest9

protected void runTest9(int start,
                        int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes the actual mean, but the state variance to the StateReturnSolver for solution and generation of an efficient frontier. We use buckets of size 2, so we'll have 5 buckets of 2 rather than 10 buckets of 1 as we did in test 1.

Parameters:
start -
length -

runTest10

protected void runTest10(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the Simulated Annealing solver for generating the efficient frontier subject to cardinality and minimum investment constraints

Parameters:
start -
length -

runTest13

protected void runTest13(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Uses a diffuse a prior.

Parameters:
start -
length -

runTest12

protected void runTest12(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the Simulated Annealing solver for generating the efficient frontier subject to cardinality and minimum investment constraints

Parameters:
start -
length -

runTest14

protected void runTest14(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the return solver for the generation of an efficient frontier.

Parameters:
start - Starting index of window in instance data
length - Length of window

runTest15

protected void runTest15(int start,
                         int length)
For a given starting month, computes the mean and covariance for the window of size length. Then passes it along to the return solver for the generation of an efficient frontier.

Parameters:
start - Starting index of window in instance data
length - Length of window

sortResults10

protected SolvedPoint sortResults10(java.util.List<SolvedPoint> l)
Estimates the point with risk of 10% and returns the closest pt less than 10%

Parameters:
l - List of points on the efficient frontier
Returns:
The best fit point

sortResults

protected SolvedPoint sortResults(java.util.List<SolvedPoint> l)
Sorts by sharpe ratio (note this didn't work so well in the past for some unknown reason.

Parameters:
l - List of points on the efficient frontier in order of return from least to greatest.
Returns:
List of points on the efficient frontier in sharpe ratio order.

processResults

protected void processResults(int start,
                              int length,
                              SolvedPoint sp)
Called to porocess a point solution and see how it will do in out of sample testing.

Parameters:
start - Starting index of the out of sample area for evaluation
length - Length of the window for the sample
sp - Starting point to evolve with the data

dumpLastReturns

public void dumpLastReturns()
For debugging dumps out the last line read from the file


dumpLastMktCap

public void dumpLastMktCap()
For debugging dumps out the last line read from the file


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Parameters:
args -
Throws:
java.lang.Exception