Change tabbing for everything....
[IRC.git] / Robust / src / Benchmarks / Scheduling / JGFMonteCarlo / AppDemo.java
1 /** Banboo Version  **/
2
3 /**************************************************************************
4  *                                                                         *
5  *         Java Grande Forum Benchmark Suite - Thread Version 1.0          *
6  *                                                                         *
7  *                            produced by                                  *
8  *                                                                         *
9  *                  Java Grande Benchmarking Project                       *
10  *                                                                         *
11  *                                at                                       *
12  *                                                                         *
13  *                Edinburgh Parallel Computing Centre                      *
14  *                                                                         *
15  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
16  *                                                                         *
17  *      Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk)     *
18  *                                                                         *
19  *      This version copyright (c) The University of Edinburgh, 2001.      *
20  *                         All rights reserved.                            *
21  *                                                                         *
22  **************************************************************************/
23
24
25 /**
26  * Code, a test-harness for invoking and driving the Applications
27  * Demonstrator classes.
28  *
29  * <p>To do:
30  * <ol>
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>
34  * </ol>
35  *
36  * @author H W Yau
37  * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:20 $
38  */
39 public class AppDemo {
40     flag merge;
41     flag validate;
42     
43     //------------------------------------------------------------------------
44     // Class variables.
45     //------------------------------------------------------------------------
46
47     public float JGFavgExpectedReturnRateMC;
48
49     public int Serial;
50     //------------------------------------------------------------------------
51     // Instance variables.
52     //------------------------------------------------------------------------
53     /**
54      * The number of time-steps which the Monte Carlo simulation should
55      * run for.
56      */
57     public int nTimeStepsMC;
58     /**
59      * The number of Monte Carlo simulations to run.
60      */
61     public int nRunsMC;
62     
63     public int group;
64     /**
65      * The default duration between time-steps, in units of a year.
66      */
67     private float dTime;
68     /**
69      * Flag to determine whether initialisation has already taken place.
70      */
71     private boolean initialised;
72     /**
73      * Variable to determine which deployment scenario to run.
74      */
75     private int runMode;
76
77     public Vector results;
78
79     PriceStock psMC;
80     public float pathStartValue;
81     float avgExpectedReturnRateMC;
82     float avgVolatilityMC;
83     
84     int counter;
85
86     RatePath avgMCrate;
87     
88     public ToInitAllTasks initAllTasks;
89
90     public AppDemo(int nTimeStepsMC, int nRunsMC, int group) {
91         this.JGFavgExpectedReturnRateMC = (float)0.0;
92         this.Serial = 1;
93
94         this.nTimeStepsMC   = nTimeStepsMC;
95         this.nRunsMC        = nRunsMC;
96         this.group          = group;
97         this.initialised    = false;
98
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;
103         
104         this.counter = 0;
105         
106         this.avgMCrate = new RatePath(this.nTimeStepsMC, "MC", 19990109, 19991231, this.dTime);
107         
108         this.initAllTasks = null;
109     }
110     /**
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.
116      */
117
118     /**
119      * Initialisation and Run methods.
120      */
121     public void initSerial() { 
122         //
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);
136         this.counter = 0;
137         //System.printI(0xf4);
138         return;
139     }
140
141     //------------------------------------------------------------------------
142     /**
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.
146      *
147      * @exception DemoException thrown if there is a problem with reading in
148      *            any values.
149      */
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();
156         }
157
158         this.counter++;
159         if(this.counter == this.group) {
160             avgMCrate.inc_pathValue((float)1.0/((float)nRunsMC));
161             avgExpectedReturnRateMC /= nRunsMC;
162             avgVolatilityMC         /= nRunsMC;
163             JGFavgExpectedReturnRateMC = avgExpectedReturnRateMC;
164         }
165         
166         return (this.counter == this.group);
167     }
168     //
169     //------------------------------------------------------------------------
170     // Accessor methods for class AppDemo.
171     // Generated by 'makeJavaAccessor.pl' script.  HWY.  20th January 1999.
172     //------------------------------------------------------------------------
173     /**
174      * Accessor method for private instance variable <code>nTimeStepsMC</code>.
175      *
176      * @return Value of instance variable <code>nTimeStepsMC</code>.
177      */
178     public int get_nTimeStepsMC() {
179         return(this.nTimeStepsMC);
180     }
181     /**
182      * Set method for private instance variable <code>nTimeStepsMC</code>.
183      *
184      * @param nTimeStepsMC the value to set for the instance variable <code>nTimeStepsMC</code>.
185      */
186     public void set_nTimeStepsMC(int nTimeStepsMC) {
187         this.nTimeStepsMC = nTimeStepsMC;
188     }
189     /**
190      * Accessor method for private instance variable <code>nRunsMC</code>.
191      *
192      * @return Value of instance variable <code>nRunsMC</code>.
193      */
194     public int get_nRunsMC() {
195         return(this.nRunsMC);
196     }
197     /**
198      * Set method for private instance variable <code>nRunsMC</code>.
199      *
200      * @param nRunsMC the value to set for the instance variable <code>nRunsMC</code>.
201      */
202     public void set_nRunsMC(int nRunsMC) {
203         this.nRunsMC = nRunsMC;
204     }
205     /**
206      * Accessor method for private instance variable <code>results</code>.
207      *
208      * @return Value of instance variable <code>results</code>.
209      */
210     public Vector get_results() {
211         return(this.results);
212     }
213     /**
214      * Set method for private instance variable <code>results</code>.
215      *
216      * @param results the value to set for the instance variable <code>results</code>.
217      */
218     public void set_results(Vector results) {
219         this.results = results;
220     }
221     //------------------------------------------------------------------------
222 }
223