Efficient Frontier

Summary

This demo illustrates how the JMSL Library can be used to easily create a Java™ application that computes an Efficient Frontier to aid in selecting a portfolio. The source data are bimonthly rates of return for three years.

Usage

Select a computation method of EWMA, SMA or AHP. Right click on the chart for a popup menu to save the chart as an image using ImagIO or JAI, or to save the data as a text file.

JMSL Library Math/Stat Classes

com.imsl.stat.Covariances - Correlation matrices of risk and return are calculated from the rates of return for the previous three years using methods: Covariances co1 = new Covariances(data1)w_fCorelations1 = co1.compute(Covariances.CORRELATION_MATRIX);

com.imsl.math.LinearProgramming - Several methods of this class are used to identify the upper and lower bounds of returns from an asset distribution (zf.setLowerBound(xlb); zf.setUpperBound(xub);). The optimal value of the objective function sets the upper and lower limits for feasible portfolio returns (double obj = zf.getOptimalValue();).

com.imsl.math.MinConGenLin - The asset correlations are used to develop an objective function. Values of each minimized general objective function are then used to relate associated risk in a portfolio to returns: results[i-(iMin+1)] = zf.getObjectiveValue();

com.imsl.stat.Summary - The methods of this class generate general statistics on the object. In this case the methods summary_x.update(expected_ret); double xa = summary_x.getMinimum();  and double xb = summary_x.getMaximum(); are used to define the range of the independent chart axis relative to the analysis.

JMSL Library Charting Classes

This application utilizes the com.imsl.chart.Data object to generate a basic line chart. The data values are displayed as a result of the following constructor and method: data = new Data(axis, expected_ret, results); data.setDataType(Data.DATA_TYPE_LINE);

Java Code

The Efficient Frontier analysis is the essence of this application. The Computer class source should be reviewed for details (link provided below).

This demo uses the Java Advanced Imaging (JAI) classes to create an image from the chart. In order to compile the code, the JAI jar files must be in your CLASSPATH. These files are distributed with JMSL and can be found in the jmsl/lib directory. Refer to the How To page for information regarding the CLASSPATH.

Link to Source Code

Efficient.java The Efficient class extends the JFrameChart class and implements java.awt.event.MouseListener. This class graphically displays the Efficient Frontier analysis results. In addition the tabular statistics for the information dialog are provided by this object.
Computer.java This class calculates correlation coefficients, constraints and performs the optimization analysis on the resulting objective functions.
InfoDialog.java This JDialog provides the model selection interface and displays the tabular data from the Efficient object.

Running This Demo

Two alternatives are available to run this demo:

1) Use the source code in your development environment as any other Java code. More information is available in the How To.

2) An executable jar file containing all of the demos referenced in this guide is included in the jmsl/lib directory. On Windows, you may double-click the file to run it if files with a ".jar" extension are properly registered with javaw.exe. Alternatively, for both Windows and UNIX environments, the jar file may be executed from the command line using java -jar gallery.jar.

As list of buttons, one for each demo, is created. Demos can be subsetted as they relate to specific areas (Math, Stat, Finance, Charting) by choosing the appropriate selection on the JComboBox. To run the Additional Demos, select Quick Start in the JComboBox.