import java.awt.*; import java.util.*; /** Program: Movie Purpose: @author: Paul Garrett, garrett@math.umn.edu @version: Mon Apr 5 12:16:04 CDT 1999 */ /* * Idea is to emulate graphical ticker-tape effect * for several "stocks", using Brownian-motion model * Both "drift" and "volatility" are user-configurable * * * "geometric brownian motion" * S(t) = S(t-1) * exp(mu + 0.5*sigma*Z) * mu = "drift" * sigma = "volatility" * * Z is from a (0,1) normal random variable * * "In equities markets, volatilities are commonly in the * range 0.06 (i.e., 6%) annualized (i.e., after having been * multiplied by sqrt(260), for 260 trading days in a year) * in quiet markets to 1 (100%) annualized or higher in crazy markets." */ /* * Don't save data produced, just initial conditions, including "seed"! * It's reproducible! */ public class Movie extends java.applet.Applet implements Runnable { final int height = 320, width = 580; final Color background_color = new Color(0xbaaaaa), foreground_color = new Color(0x503030); final int days = 260; // number of increments visible?!? final int num = 3; // number of different entitites double[] mu = new double[num]; // "drift" double[] sigma = new double[num]; // "volatility" long seed = 0; // as default Color[] color = new Color[num]; // for graphs Label[] mu_L = new Label[num]; Label[] sigma_L = new Label[num]; Label seed_L = new Label("seed ="); //__EDIT__number-of-days!? displayed!? Random pRNG; // Gaussian random variable output long current_time; TextField time_TF = new TextField(8); Label time_L = new Label("time = "); Thread timer; Graphics osg; // for off-screen drawing, to avoid flicker Image osi; TextField[] mu_TF = new TextField[num]; TextField[] sigma_TF = new TextField[num]; TextField seed_TF = new TextField(8); // for the pRNG Button stopB = new Button("stop"); Button goB = new Button("go"); Button clearB = new Button("clear graphics"); Button showB = new Button("show data"); Button hideB = new Button("hide data"); Panel p = new Panel(); final int RUNNING = -3; // now draw previous 260 days (or however many) final int STOPPED = -4; // with some indeterminate amount drawn/computed...?! int theState = STOPPED; // to tell paint() what to do Vector[] price = new Vector[num]; /****************************/ public void init() { setBackground(background_color); setForeground(foreground_color); pRNG = new Random(0); color = new Color[num]; mu = new double[num]; sigma = new double[num]; // price = new double[num, color[0] = Color.red; color[1] = Color.blue; color[2] = Color.yellow; mu_L[0] = new Label("red mu ="); mu_L[1] = new Label("blue mu ="); mu_L[2] = new Label("yellow mu ="); sigma_L[0] = new Label("red sigma ="); sigma_L[1] = new Label("blue sigma ="); sigma_L[2] = new Label("yellow sigma ="); for (int i=0; i days) { price[i].removeElementAt(0); } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { int x1, x2; double y1, y2; osg.setColor( background_color ); osg.fillRect(0,0,550,320); osg.setColor( Color.gray ); //__EDIT__? for (int i=-8; i<20; i++) { if (i%2 == 0) { osg.setColor( Color.black ); if (i<0) { osg.drawString(""+(100+10*i), 5, 320-100-10*i+3); } else { osg.drawString(""+(100+10*i), 0, 320-100-10*i+3); } osg.drawLine(25, 320-100-10*i, 545, 320-100-10*i); } else { osg.setColor( Color.gray ); osg.drawLine(25, 320-100-10*i, 545, 320-100-10*i); } } osg.setColor( Color.black ); osg.drawLine(25, 320-99, 545, 320-99); for (int i=0; i