changes to build script to increase java heap memory
[IRC.git] / Robust / src / Benchmarks / Scheduling / JGFMonteCarlo / PriceStock.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  * Class to do the work in the Application demonstrator, in particular
26  * the pricing of the stock path generated by Monte Carlo.  The run
27  * method will generate a single sequence with the required statistics,
28  * estimate its volatility, expected return rate and final stock price
29  * value.
30  *
31  * @author H W Yau
32  * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $
33  */
34 public class PriceStock{
35
36     //------------------------------------------------------------------------
37     // Instance variables.
38     //------------------------------------------------------------------------
39     /**
40      * The Monte Carlo path to be generated.
41      */
42     private MonteCarloPath mcPath;
43     /**
44      * String identifier for a given task.
45      */
46     private String taskHeader;
47     /**
48      * Random seed from which the Monte Carlo sequence is started.
49      */
50     private long randomSeed;
51     /**
52      * Initial stock price value.
53      */
54     private float pathStartValue;
55     /**
56      * Object which represents the results from a given computation task.
57      */
58     private ToResult result;
59     private float expectedReturnRate;
60     private float volatility;
61     private float volatility2;
62     private float finalStockPrice;
63     private float[] pathValue;
64
65     //------------------------------------------------------------------------
66     // Constructors.
67     //------------------------------------------------------------------------
68     /**
69      * Default constructor.
70      */
71     public PriceStock() {
72         this.taskHeader = "";
73         this.randomSeed=-1;
74         this.pathStartValue=(float)0.0;
75         this.expectedReturnRate=(float)0.0;
76         this.volatility=(float)0.0;
77         this.volatility2=(float)0.0;
78         this.finalStockPrice=(float)0.0;
79
80         mcPath = new MonteCarloPath();
81     }
82     //------------------------------------------------------------------------
83     // Methods.
84     //------------------------------------------------------------------------
85     //------------------------------------------------------------------------
86     // Methods which implement the Slaveable interface.
87     //------------------------------------------------------------------------
88     /**
89      * Method which is passed in the initialisation data common to all tasks,
90      * and then unpacks them for use by this object.
91      *
92      * @param obj Object representing data which are common to all tasks.
93      */
94     public void setInitAllTasks(AppDemoRunner obj) {
95         mcPath.set_name(obj.name);
96         mcPath.set_startDate(obj.startDate);
97         mcPath.set_endDate(obj.endDate);
98         mcPath.set_dTime(obj.dTime);
99         mcPath.set_returnDefinition(obj.returnDefinition);
100         mcPath.set_expectedReturnRate(obj.expectedReturnRate);
101         mcPath.set_volatility(obj.volatility);
102         int nTimeSteps = obj.nTimeSteps;
103         mcPath.set_nTimeSteps(nTimeSteps);
104         this.pathStartValue = obj.pathStartValue;
105         mcPath.set_pathStartValue(pathStartValue);
106         mcPath.set_pathValue(new float[nTimeSteps]);
107         mcPath.set_fluctuations(new float[nTimeSteps]);
108     }
109     /**
110      * Method which is passed in the data representing each task, which then
111      * unpacks it for use by this object.
112      *
113      * @param obj Object representing the data which defines a given task.
114      */
115     public void setTask(String header, long randomSeed) {
116         this.taskHeader     = header;
117         this.randomSeed     = randomSeed;
118     }
119     /**
120      * The business end.  Invokes the necessary computation routine, for a
121      * a given task.
122      */
123     public void run() {
124         mcPath.computeFluctuationsGaussian(randomSeed);
125         //System.printI(0xa0);
126         mcPath.computePathValue(pathStartValue);
127         //System.printI(0xa1);
128         RatePath rateP = new RatePath(mcPath);
129         //System.printI(0xa2);
130         ReturnPath returnP = rateP.getReturnCompounded();
131         //System.printI(0xa3);
132         returnP.estimatePath();
133         //System.printI(0xa4);
134         expectedReturnRate = returnP.get_expectedReturnRate();
135         volatility = returnP.get_volatility();
136         volatility2 = returnP.get_volatility2();
137         finalStockPrice = rateP.getEndPathValue();
138         pathValue = mcPath.get_pathValue();
139         //System.printI(0xa5);
140     }
141     /*
142      * Method which returns the results of a computation back to the caller.
143      *
144      * @return An object representing the computed results.
145      */
146     public ToResult getResult() {
147         String resultHeader = "Result of task with Header="+taskHeader+": randomSeed="+randomSeed+": pathStartValue="+(int)pathStartValue;
148         ToResult res = new ToResult(resultHeader,expectedReturnRate,volatility,
149                 volatility2,finalStockPrice,pathValue);
150         return res;
151     }
152 }