org.akutan.blacklitterman.gui
Class BLApplet

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.blacklitterman.gui.BLApplet
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.RootPaneContainer, org.jfree.chart.ChartMouseListener

public class BLApplet
extends javax.swing.JApplet
implements java.awt.print.Printable, java.lang.Runnable, org.jfree.chart.ChartMouseListener

Applet/Main class for Application that displays the results from a Black-Litterman model. Given some weights and a covariance matrix which the user can edit, the applet displays the weights in a pie chart, then shows the distributions for the various asset returns, and also can display an efficient frontier given the posterior returns and variances.

Since:
February 2007
See Also:
Serialized Form

Nested Class Summary
 
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  java.util.Map<java.lang.String,java.lang.Integer> _assetMap
          Map of asset names for easy access
protected  org.jfree.chart.plot.CategoryPlot _histPlot
          Displays the computed returns
protected  org.jfree.chart.plot.CategoryPlot _histPlot2
          Displays the computed weights
protected  org.jfree.chart.plot.PiePlot _piePlot
          Displays the equilibrium weights
 
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
BLApplet()
          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 chartMouseClicked(org.jfree.chart.ChartMouseEvent event)
          We want to handle these events by opening a BayesianDialog object for the right asset.
 void chartMouseMoved(org.jfree.chart.ChartMouseEvent event)
          We can ignore these messages
 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.plot.CategoryPlot createBarChart()
           
protected  org.jfree.chart.plot.CategoryPlot createBarChart2()
          Called to create the pie chart frame and chart objects so they can be filled in when an optimization is run.
protected  void createGui()
          Called to create the various charts and associated bits during initialization of the application.
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.
 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()
          To start with we will use the He-Litterman data and allow the user to modify the sampling distribution returns (not the covariances) and also to specify views.
static void main(java.lang.String[] args)
          Allows us to run as an application or an applet
 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 setDefaults()
          Called to reset the assets, weights and covariances to the He-Litterman 1992 data which is the default for this app.
 void setParameter(java.lang.String key, java.lang.String value)
          Sets a parameter for later access by getParameter method.
protected  void updateBarChart(java.lang.String[] assets, cern.colt.matrix.DoubleMatrix1D returns)
           
protected  void updateBarChart(java.lang.String[] assets, cern.colt.matrix.DoubleMatrix1D returns, cern.colt.matrix.DoubleMatrix1D viewReturns)
           
protected  void updateBarChart2(java.lang.String[] assets, cern.colt.matrix.DoubleMatrix1D weights)
           
protected  void updateGui()
           
 
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

_piePlot

protected org.jfree.chart.plot.PiePlot _piePlot
Displays the equilibrium weights


_histPlot2

protected org.jfree.chart.plot.CategoryPlot _histPlot2
Displays the computed weights


_histPlot

protected org.jfree.chart.plot.CategoryPlot _histPlot
Displays the computed returns


_assetMap

protected java.util.Map<java.lang.String,java.lang.Integer> _assetMap
Map of asset names for easy access

Constructor Detail

BLApplet

public BLApplet()
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

setDefaults

public void setDefaults()
Called to reset the assets, weights and covariances to the He-Litterman 1992 data which is the default for this app.


chartMouseClicked

public void chartMouseClicked(org.jfree.chart.ChartMouseEvent event)
We want to handle these events by opening a BayesianDialog object for the right asset.

Specified by:
chartMouseClicked in interface org.jfree.chart.ChartMouseListener

chartMouseMoved

public void chartMouseMoved(org.jfree.chart.ChartMouseEvent event)
We can ignore these messages

Specified by:
chartMouseMoved in interface org.jfree.chart.ChartMouseListener

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()
To start with we will use the He-Litterman data and allow the user to modify the sampling distribution returns (not the covariances) and also to specify views.

Overrides:
init in class java.applet.Applet

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 -

run

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

Specified by:
run in interface java.lang.Runnable

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.


updateGui

protected void updateGui()

createBarChart

protected org.jfree.chart.plot.CategoryPlot createBarChart()

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

createBarChart2

protected org.jfree.chart.plot.CategoryPlot createBarChart2()
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

updateBarChart2

protected void updateBarChart2(java.lang.String[] assets,
                               cern.colt.matrix.DoubleMatrix1D weights)

updateBarChart

protected void updateBarChart(java.lang.String[] assets,
                              cern.colt.matrix.DoubleMatrix1D returns)

updateBarChart

protected void updateBarChart(java.lang.String[] assets,
                              cern.colt.matrix.DoubleMatrix1D returns,
                              cern.colt.matrix.DoubleMatrix1D viewReturns)

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Allows us to run as an application or an applet

Parameters:
args -
Throws:
java.lang.Exception