3 /**************************************************************************
5 * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
9 * Java Grande Benchmarking Project *
13 * Edinburgh Parallel Computing Centre *
15 * email: epcc-javagrande@epcc.ed.ac.uk *
17 * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
19 * This version copyright (c) The University of Edinburgh, 2001. *
20 * All rights reserved. *
22 **************************************************************************/
26 * Code, a test-harness for invoking and driving the Applications
27 * Demonstrator classes.
31 * <li>Very long delay prior to connecting to the server.</li>
32 * <li>Some text output seem to struggle to get out, without
33 * the user tapping ENTER on the keyboard!</li>
37 * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:20 $
39 public class AppDemo {
43 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
47 public float JGFavgExpectedReturnRateMC;
50 //------------------------------------------------------------------------
51 // Instance variables.
52 //------------------------------------------------------------------------
54 * The number of time-steps which the Monte Carlo simulation should
57 public int nTimeStepsMC;
59 * The number of Monte Carlo simulations to run.
65 * The default duration between time-steps, in units of a year.
69 * Flag to determine whether initialisation has already taken place.
71 private boolean initialised;
73 * Variable to determine which deployment scenario to run.
77 public Vector results;
80 public float pathStartValue;
81 float avgExpectedReturnRateMC;
82 float avgVolatilityMC;
88 public ToInitAllTasks initAllTasks;
90 public AppDemo(int nTimeStepsMC, int nRunsMC, int group) {
91 this.JGFavgExpectedReturnRateMC = (float)0.0;
94 this.nTimeStepsMC = nTimeStepsMC;
95 this.nRunsMC = nRunsMC;
97 this.initialised = false;
99 this.dTime = (float)1.0/(float)365.0;
100 this.pathStartValue = (float)100.0;
101 this.avgExpectedReturnRateMC = (float)0.0;
102 this.avgVolatilityMC = (float)0.0;
106 this.avgMCrate = new RatePath(this.nTimeStepsMC, "MC", 19990109, 19991231, this.dTime);
108 this.initAllTasks = null;
111 * Single point of contact for running this increasingly bloated
112 * class. Other run modes can later be defined for whether a new rate
113 * should be loaded in, etc.
114 * Note that if the <code>hostname</code> is set to the string "none",
115 * then the demonstrator runs in purely serial mode.
119 * Initialisation and Run methods.
121 public void initSerial() {
123 // Measure the requested path rate.
124 //System.printI(0xf0);
125 RatePath rateP = new RatePath();
126 //System.printI(0xf1);
127 //rateP.dbgDumpFields();
128 ReturnPath returnP = rateP.getReturnCompounded();
129 //System.printI(0xf2);
130 returnP.estimatePath();
131 //System.printI(0xf3);
132 //returnP.dbgDumpFields();
133 float expectedReturnRate = returnP.get_expectedReturnRate();
134 float volatility = returnP.get_volatility();
135 initAllTasks = new ToInitAllTasks(returnP, nTimeStepsMC, pathStartValue);
137 //System.printI(0xf4);
141 //------------------------------------------------------------------------
143 * Method for doing something with the Monte Carlo simulations.
144 * It's probably not mathematically correct, but shall take an average over
145 * all the simulated rate paths.
147 * @exception DemoException thrown if there is a problem with reading in
150 boolean processResults(Vector returnMCs) {
151 for(int i = 0; i < returnMCs.size(); i++) {
152 ToResult returnMC = (ToResult)returnMCs.elementAt(i);
153 avgMCrate.inc_pathValue(returnMC.get_pathValue());
154 avgExpectedReturnRateMC += returnMC.get_expectedReturnRate();
155 avgVolatilityMC += returnMC.get_volatility();
159 if(this.counter == this.group) {
160 avgMCrate.inc_pathValue((float)1.0/((float)nRunsMC));
161 avgExpectedReturnRateMC /= nRunsMC;
162 avgVolatilityMC /= nRunsMC;
163 JGFavgExpectedReturnRateMC = avgExpectedReturnRateMC;
166 return (this.counter == this.group);
169 //------------------------------------------------------------------------
170 // Accessor methods for class AppDemo.
171 // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
172 //------------------------------------------------------------------------
174 * Accessor method for private instance variable <code>nTimeStepsMC</code>.
176 * @return Value of instance variable <code>nTimeStepsMC</code>.
178 public int get_nTimeStepsMC() {
179 return(this.nTimeStepsMC);
182 * Set method for private instance variable <code>nTimeStepsMC</code>.
184 * @param nTimeStepsMC the value to set for the instance variable <code>nTimeStepsMC</code>.
186 public void set_nTimeStepsMC(int nTimeStepsMC) {
187 this.nTimeStepsMC = nTimeStepsMC;
190 * Accessor method for private instance variable <code>nRunsMC</code>.
192 * @return Value of instance variable <code>nRunsMC</code>.
194 public int get_nRunsMC() {
195 return(this.nRunsMC);
198 * Set method for private instance variable <code>nRunsMC</code>.
200 * @param nRunsMC the value to set for the instance variable <code>nRunsMC</code>.
202 public void set_nRunsMC(int nRunsMC) {
203 this.nRunsMC = nRunsMC;
206 * Accessor method for private instance variable <code>results</code>.
208 * @return Value of instance variable <code>results</code>.
210 public Vector get_results() {
211 return(this.results);
214 * Set method for private instance variable <code>results</code>.
216 * @param results the value to set for the instance variable <code>results</code>.
218 public void set_results(Vector results) {
219 this.results = results;
221 //------------------------------------------------------------------------