org.akutan
Class EfficientFrontier

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by org.akutan.EfficientFrontier
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, java.lang.Runnable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, javax.swing.RootPaneContainer

public class EfficientFrontier
extends javax.swing.JApplet
implements java.awt.print.Printable, java.lang.Runnable, javax.swing.event.ChangeListener

Applet/Main class for Application that displays the results from the optimization code. Allows the user to select one or more assets and an optimization method and then uses the optimizer to compute the mean variance frontier and/or the efficient frontier and displays several views.

See Also:
Serialized Form

Nested Class Summary
static class EfficientFrontier.SampleData
          Little inner class value object we use to hold raw input data for a given month so we can use a single collection rather than several arrays.
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  org.jfree.chart.plot.XYPlot _areaPlot
           
protected  org.jfree.chart.plot.PiePlot _piePlot
           
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EfficientFrontier()
          Constructs
 
Method Summary
 void action(java.awt.event.ActionEvent event, java.lang.Object arg)
          Action handler for the buttons on the main control panel, these are Go and Clear.
 void constrain(java.awt.Container container, java.awt.Component component, int grid_x, int grid_y, int grid_width, int grid_height)
          helper method to set layout constraints when adding a component to a container.
 void constrain(java.awt.Container container, java.awt.Component component, int grid_x, int grid_y, int grid_width, int grid_height, int fill, int anchor, double weight_x, double weight_y, int top, int left, int bottom, int right)
          Helper method to apply layout constraint to a component as it's added to a container.
 void constrain(java.awt.Container container, java.awt.Component component, int grid_x, int grid_y, int grid_width, int grid_height, int top, int left, int bottom, int right)
          Helper method to set layout constraints when adding a component to a container.
protected  org.jfree.chart.JFreeChart createChart(org.jfree.data.xy.XYDataset xydataset)
          Called to create the Efficient Frontier chart on the main frame of the application.
protected  void createGui()
          Called to create the various charts and associated bits during initialization of the application.
protected  void createPath()
          Given the first optimization run, strips out any path information and draws the path in series 0 with shapes = CrossCircle so that one can see the path of the optimizer.
protected  org.jfree.chart.plot.PiePlot createPieChart()
          Called to create the pie chart frame and chart objects so they can be filled in when an optimization is run.
protected  void dumpPoints(java.util.List<SolvedPoint> points)
          Debug method to dump all the points on an efficient frontier to System.out.
protected  java.lang.String formatString(java.lang.String s)
          Helper method to format a string and squeeze out multiple spaces replacing them with just one.
protected  java.lang.String[] getAssets()
          Returns the names of the selected assets as an array.
protected  double getDouble(java.lang.String number)
          helper method to convert a string into a double and deal with any conversion exceptions.
protected  int getMonth(java.lang.String month)
          Helper method to return the month number given the three letter abbreviation for a month.
 java.lang.String getParameter(java.lang.String name)
          Wraps the logic for retrieving parameters so we can use the same code as an applet and as an application.
 void init()
          Initializes the application/applet, handles setting up the UI and loading the raw returns into memory.
protected  void loadReturnsFromFile(java.lang.String dataURLName, java.util.List<EfficientFrontier.SampleData> samplePoints)
          Reads the market data (monthly asset returns) from a .csv file and puts them into SampleData objects on a list.
static void main(java.lang.String[] args)
           
 void paint(java.awt.Graphics g)
          New paint method for graphics panel using jfreechart
 int print(java.awt.Graphics g, java.awt.print.PageFormat f, int page)
           
 void run()
          Used with SwingUtilities to cause a paint when a calculation has completed
 void setParameter(java.lang.String key, java.lang.String value)
          Sets a parameter for later access by getParameter method.
 void stateChanged(javax.swing.event.ChangeEvent changeevent)
          Called when the slider moves to update the area chart, the pie chart and the efficient frontier chart
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_areaPlot

protected org.jfree.chart.plot.XYPlot _areaPlot

_piePlot

protected org.jfree.chart.plot.PiePlot _piePlot
Constructor Detail

EfficientFrontier

public EfficientFrontier()
Constructs

Method Detail

setParameter

public void setParameter(java.lang.String key,
                         java.lang.String value)
Sets a parameter for later access by getParameter method. We use this so that we can make the app and applet initialize the same way.

Parameters:
key - Name of the parameter to be set
value - Value for the parameter

getParameter

public java.lang.String getParameter(java.lang.String name)
Wraps the logic for retrieving parameters so we can use the same code as an applet and as an application.

Overrides:
getParameter in class java.applet.Applet
Parameters:
name - Name of the parameter for which the value is to be returned
Returns:
Current value of the parameter

loadReturnsFromFile

protected void loadReturnsFromFile(java.lang.String dataURLName,
                                   java.util.List<EfficientFrontier.SampleData> samplePoints)
Reads the market data (monthly asset returns) from a .csv file and puts them into SampleData objects on a list.

Parameters:
dataURLName -
samplePoints -

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat f,
                 int page)
Specified by:
print in interface java.awt.print.Printable

init

public void init()
Initializes the application/applet, handles setting up the UI and loading the raw returns into memory. Computes the statistics and saves them for later use by the various optimizers.

Overrides:
init in class java.applet.Applet

getMonth

protected int getMonth(java.lang.String month)
Helper method to return the month number given the three letter abbreviation for a month.

Parameters:
month -
Returns:
The integer month (1-12) for the name specified.

createPieChart

protected org.jfree.chart.plot.PiePlot createPieChart()
Called to create the pie chart frame and chart objects so they can be filled in when an optimization is run.

Returns:
PiePlot the created PiePlot

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent changeevent)
Called when the slider moves to update the area chart, the pie chart and the efficient frontier chart

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
changeevent - The slider event

createChart

protected org.jfree.chart.JFreeChart createChart(org.jfree.data.xy.XYDataset xydataset)
Called to create the Efficient Frontier chart on the main frame of the application.

Parameters:
xydataset - Dataset of risk vs return data for points on the efficient frontier
Returns:
Chart of standard risk/return space populated with the data in the dataset

getDouble

protected double getDouble(java.lang.String number)
helper method to convert a string into a double and deal with any conversion exceptions.

Parameters:
number - String to be converted into a double
Returns:
The double represented by the string

formatString

protected java.lang.String formatString(java.lang.String s)
Helper method to format a string and squeeze out multiple spaces replacing them with just one.

Parameters:
s - String to be cleaned
Returns:
Cleaned string

constrain

public void constrain(java.awt.Container container,
                      java.awt.Component component,
                      int grid_x,
                      int grid_y,
                      int grid_width,
                      int grid_height,
                      int fill,
                      int anchor,
                      double weight_x,
                      double weight_y,
                      int top,
                      int left,
                      int bottom,
                      int right)
Helper method to apply layout constraint to a component as it's added to a container.

Parameters:
container -
component -
grid_x -
grid_y -
grid_width -
grid_height -
fill -
anchor -
weight_x -
weight_y -
top -
left -
bottom -
right -

constrain

public void constrain(java.awt.Container container,
                      java.awt.Component component,
                      int grid_x,
                      int grid_y,
                      int grid_width,
                      int grid_height)
helper method to set layout constraints when adding a component to a container. Defaluts the insets and weights to be 0.

Parameters:
container -
component -
grid_x -
grid_y -
grid_width -
grid_height -

constrain

public void constrain(java.awt.Container container,
                      java.awt.Component component,
                      int grid_x,
                      int grid_y,
                      int grid_width,
                      int grid_height,
                      int top,
                      int left,
                      int bottom,
                      int right)
Helper method to set layout constraints when adding a component to a container. Defaults the weights to be 0.

Parameters:
container -
component -
grid_x -
grid_y -
grid_width -
grid_height -
top -
left -
bottom -
right -

dumpPoints

protected void dumpPoints(java.util.List<SolvedPoint> points)
Debug method to dump all the points on an efficient frontier to System.out.

Parameters:
points -

action

public void action(java.awt.event.ActionEvent event,
                   java.lang.Object arg)
Action handler for the buttons on the main control panel, these are Go and Clear. The Go button will start the optimization and the Clear button will clear all the charts and list boxes.

Parameters:
event -
arg -

getAssets

protected java.lang.String[] getAssets()
Returns the names of the selected assets as an array.

Returns:
String Array of selected assets for this optimization.

run

public void run()
Used with SwingUtilities to cause a paint when a calculation has completed

Specified by:
run in interface java.lang.Runnable

createPath

protected void createPath()
Given the first optimization run, strips out any path information and draws the path in series 0 with shapes = CrossCircle so that one can see the path of the optimizer. Need to turn this on via options somehow.


paint

public void paint(java.awt.Graphics g)
New paint method for graphics panel using jfreechart

Overrides:
paint in class java.awt.Container
Parameters:
g -

createGui

protected void createGui()
Called to create the various charts and associated bits during initialization of the application.


main

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