+package Fibheaps;
+
public class FibHeap {
public int degree;
public TaggedTree ttree;
public Vector forest;
-
+
public FibHeap() {
this.degree = 0;
this.ttree = null;
this.forest = null;
}
-
+
public FibHeap(int degree,
- TaggedTree ttree,
- Vector forest) {
+ TaggedTree ttree,
+ Vector forest) {
this.degree = degree;
this.ttree = ttree;
this.forest = forest;
}
-
+
public boolean isEmpty() {
return this.degree == 0;
}
-
+
public int minFH() {
return this.ttree.tree.root;
}
-
+
public FibHeap insertFH(int x) {
TaggedTree tt = new TaggedTree(0, new Tree(x, null));
FibHeap fh = new FibHeap(1, tt, null);
-
+
return this.meldFH(fh);
}
-
+
public FibHeap meldFH(FibHeap fh) {
if(this.isEmpty()) {
return fh;
return new FibHeap(fh.degree+this.degree, root, forest);
}
}
-
+
private void insert(Vector a,
- TaggedTree tt) {
+ TaggedTree tt) {
int index = tt.degree;
if(a.elementAt(index) == null) {
a.setElementAt(tt.tree, index);
insert(a, itt);
}
}
-
+
private FibHeap getMin_t(Vector a,
- int mini,
- Tree mint,
- Vector b,
- int i,
- int d) {
+ int mini,
+ Tree mint,
+ Vector b,
+ int i,
+ int d) {
if(i >= d) {
return new FibHeap(this.degree-1, new TaggedTree(mini, mint), b);
} else {
}
}
}
-
+
private int locallog(int n) {
if(n == 1) {
return 0;
return 1 + locallog(n/2);
}
}
-
+
public FibHeap deleteMinFH() {
if(this.isEmpty()) {
// error here
return getMin_t(a, d, test, new Vector(), 0, d);
}
}
-
+
private Vector combine(int index,
- Vector ts,
- Vector next,
- Vector rest) {
+ Vector ts,
+ Vector next,
+ Vector rest) {
if(ts.size() == 0) {
return startup(index+1, next, rest);
} else if (ts.size() == 1) {
return combine(index, nts, next, rest);
}
}
-
+
private Vector startup(int index,
- Vector ts,
- Vector rest) {
+ Vector ts,
+ Vector rest) {
if(ts.size() == 0) {
if(rest.size() == 0) {
return new Vector();
}
}
}
-
+
private FibHeap chooseMin(FibHeap fh,
- TaggedTree tt) {
+ TaggedTree tt) {
FibHeap rfh = null;
if(fh.ttree.tree.root <= tt.tree.root) {
fh.forest.insertElementAt(tt, 0);
}
return rfh;
}
-
+
public FibHeap deleteMinFH_t() {
if(this.isEmpty()) {
// error here
na.addElement(a.elementAt(i));
}
Vector vvec = startup(0, ts, na);
-
+
// getMin()
TaggedTree rtt = (TaggedTree)vvec.elementAt(0);
FibHeap rfh = new FibHeap(this.degree-1, rtt, new Vector());
+package Fibheaps;
+
// the fibheap class
-public class TestRunner {
+public class TestRunner extends Thread {
public TestRunner() {}
int threadnum = 62;
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner();
- tr.run();
+ tr.start();
}
}
}
+package Fibheaps;
+
// the bionomial class
public class Tree {
public int root;
public Vector v_trees;
-
+
public Tree() {
this.root = 0;
this.v_trees = null;
}
-
+
public Tree(int root,
- Vector trees) {
+ Vector trees) {
this.root = root;
this.v_trees = trees;
}
public class TaggedTree {
public int degree;
public Tree tree;
-
+
public TaggedTree() {
this.degree = 0;
this.tree = null;
}
-
+
public TaggedTree(int degree,
- Tree tree) {
+ Tree tree) {
this.degree = degree;
this.tree = tree;
}
-
+
public Vector getChildren() {
Vector rst = new Vector();
Vector v = tree.v_trees;
--- /dev/null
+package GCBench;
+
+public class Node {
+ Node left, right;
+ int i, j;
+ Node(Node l, Node r) { left = l; right = r; }
+ Node() { }
+}
+package GCBench;
+
//This is adapted from a benchmark written by John Ellis and Pete Kovac
//of Post Communications.
//It was modified by Hans Boehm of Silicon Graphics.
//- Results are sensitive to locking cost, but we dont
//check for proper locking
-public class TestRunner extends Thread {
+public class TestRunner extends Thread {
public static final int kStretchTreeDepth = 16; // about 4Mb
public static final int kLongLivedTreeDepth = 14; // about 1Mb
System.out.println((int)(array[1000]*1000000));
}
}
-
- class Node {
- Node left, right;
- int i, j;
- Node(Node l, Node r) { left = l; right = r; }
- Node() { }
- }
-
+
public static void main(String[] args) {
int threadnum = 62;
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner();
- tr.run();
+ tr.start();
}
}
} // class JavaGC
+package JGFMonteCarlo;
/**************************************************************************
* *
* </ol>
*
* @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
*/
public class AppDemo {
-class AppDemoRunner {
+package JGFMonteCarlo;
+
+public class AppDemoRunner extends Thread {
public String header;
public String name;
results.addElement(ps.getResult());
}
}
+
public static void main(String[] args) {
int datasize = 10000; //should be times of 2
int nruns = 62 * 62; //16 * 16;
for(int i = 0; i < group; i++) {
AppDemoRunner adr = new AppDemoRunner(i, nruns, group, ad);
- adr.run();
+ adr.start();
}
}
}
\ No newline at end of file
-/** Banboo Version **/
+package JGFMonteCarlo;
/**************************************************************************
* *
* </ol>
*
* @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
*/
public class MonteCarloPath extends PathId {
- //------------------------------------------------------------------------
- // Instance variables.
- //------------------------------------------------------------------------
- /**
- * Random fluctuations generated as a series of random numbers with
- * given distribution.
- */
- public float[] fluctuations;
- /**
- * The path values from which the random fluctuations are used to update.
- */
- public float[] pathValue;
- /**
- * Integer flag for determining how the return was calculated, when
- * used to calculate the mean drift and volatility parameters.
- */
- public int returnDefinition;
- /**
- * Value for the mean drift, for use in the generation of the random path.
- */
- public float expectedReturnRate;
- /**
- * Value for the volatility, for use in the generation of the random path.
- */
- public float volatility;
- /**
- * Number of time steps for which the simulation should act over.
- */
- public int nTimeSteps;
- /**
- * The starting value for of the security.
- */
- public float pathStartValue;
- //------------------------------------------------------------------------
- // Constructors.
- //------------------------------------------------------------------------
- /**
- * Default constructor. Needed by the HPT library to start create
- * new instances of this class. The instance variables for this should
- * then be initialised with the <code>setInitAllTasks()</code> method.
- */
- public MonteCarloPath() {
- super();
- this.expectedReturnRate = (float)0.0;
- this.volatility = (float)0.0;
- this.pathStartValue = (float)0.0;
- this.returnDefinition=1;
- this.nTimeSteps=0;
- }
+ //------------------------------------------------------------------------
+ // Instance variables.
+ //------------------------------------------------------------------------
+ /**
+ * Random fluctuations generated as a series of random numbers with
+ * given distribution.
+ */
+ public float[] fluctuations;
+ /**
+ * The path values from which the random fluctuations are used to update.
+ */
+ public float[] pathValue;
+ /**
+ * Integer flag for determining how the return was calculated, when
+ * used to calculate the mean drift and volatility parameters.
+ */
+ public int returnDefinition;
+ /**
+ * Value for the mean drift, for use in the generation of the random path.
+ */
+ public float expectedReturnRate;
+ /**
+ * Value for the volatility, for use in the generation of the random path.
+ */
+ public float volatility;
+ /**
+ * Number of time steps for which the simulation should act over.
+ */
+ public int nTimeSteps;
+ /**
+ * The starting value for of the security.
+ */
+ public float pathStartValue;
+ //------------------------------------------------------------------------
+ // Constructors.
+ //------------------------------------------------------------------------
+ /**
+ * Default constructor. Needed by the HPT library to start create
+ * new instances of this class. The instance variables for this should
+ * then be initialised with the <code>setInitAllTasks()</code> method.
+ */
+ public MonteCarloPath() {
+ super();
+ this.expectedReturnRate = (float)0.0;
+ this.volatility = (float)0.0;
+ this.pathStartValue = (float)0.0;
+ this.returnDefinition=1;
+ this.nTimeSteps=0;
+ }
+ /**
+ * Constructor, using the <code>ReturnPath</code> object to initialise
+ * the necessary instance variables.
+ *
+ * @param returnPath Object used to define the instance variables in
+ * this object.
+ * @param nTimeSteps The number of time steps for which to generate the
+ * random path.
+ * @exception DemoException Thrown if there is a problem initialising the
+ * object's instance variables.
+ */
+ public MonteCarloPath(ReturnPath returnPath,
+ int nTimeSteps) {
/**
- * Constructor, using the <code>ReturnPath</code> object to initialise
- * the necessary instance variables.
- *
- * @param returnPath Object used to define the instance variables in
- * this object.
- * @param nTimeSteps The number of time steps for which to generate the
- * random path.
- * @exception DemoException Thrown if there is a problem initialising the
- * object's instance variables.
- */
- public MonteCarloPath(ReturnPath returnPath,
- int nTimeSteps) {
- /**
- * These instance variables are members of PathId class.
- */
- this.expectedReturnRate = (float)0.0;
- this.volatility = (float)0.0;
- this.pathStartValue = (float)0.0;
- this.returnDefinition=1;
-
- copyInstanceVariables(returnPath);
- this.nTimeSteps = nTimeSteps;
- this.pathValue = new float[nTimeSteps];
- this.fluctuations = new float[nTimeSteps];
- }
- /**
- * Constructor, where the <code>PathId</code> objects is used to ease
- * the number of instance variables to pass in.
- *
- * @param pathId Object used to define the identity of this Path.
- * @param returnDefinition How the statistic variables were defined,
- * according to the definitions in
- * <code>ReturnPath</code>'s two class variables
- * <code>COMPOUNDED</code> and
- * <code>NONCOMPOUNDED</code>.
- * @param expectedReturnRate The measured expected return rate for which to generate.
- * @param volatility The measured volatility for which to generate.
- * @param nTimeSteps The number of time steps for which to generate.
- * @exception DemoException Thrown if there is a problem initialising the
- * object's instance variables.
+ * These instance variables are members of PathId class.
*/
- public MonteCarloPath(PathId pathId,
- int returnDefinition,
- float expectedReturnRate,
- float volatility,
- int nTimeSteps) {
- /**
- * These instance variables are members of PathId class.
- * Invoking with this particular signature should point to the
- * definition in the PathId class.
- */
- this.pathStartValue = (float)0.0;
-
- copyInstanceVariables(pathId);
- this.returnDefinition = returnDefinition;
- this.expectedReturnRate = expectedReturnRate;
- this.volatility = volatility;
- this.nTimeSteps = nTimeSteps;
- this.pathValue = new float[nTimeSteps];
- this.fluctuations = new float[nTimeSteps];
- }
+ this.expectedReturnRate = (float)0.0;
+ this.volatility = (float)0.0;
+ this.pathStartValue = (float)0.0;
+ this.returnDefinition=1;
+
+ copyInstanceVariables(returnPath);
+ this.nTimeSteps = nTimeSteps;
+ this.pathValue = new float[nTimeSteps];
+ this.fluctuations = new float[nTimeSteps];
+ }
+ /**
+ * Constructor, where the <code>PathId</code> objects is used to ease
+ * the number of instance variables to pass in.
+ *
+ * @param pathId Object used to define the identity of this Path.
+ * @param returnDefinition How the statistic variables were defined,
+ * according to the definitions in
+ * <code>ReturnPath</code>'s two class variables
+ * <code>COMPOUNDED</code> and
+ * <code>NONCOMPOUNDED</code>.
+ * @param expectedReturnRate The measured expected return rate for which to generate.
+ * @param volatility The measured volatility for which to generate.
+ * @param nTimeSteps The number of time steps for which to generate.
+ * @exception DemoException Thrown if there is a problem initialising the
+ * object's instance variables.
+ */
+ public MonteCarloPath(PathId pathId,
+ int returnDefinition,
+ float expectedReturnRate,
+ float volatility,
+ int nTimeSteps) {
/**
- * Constructor, for when the user wishes to define each of the instance
- * variables individually.
- *
- * @param name The name of the security which this Monte Carlo path
- * should represent.
- * @param startDate The date when the path starts, in 'YYYYMMDD' format.
- * @param endDate The date when the path ends, in 'YYYYMMDD' format.
- * @param dTime The interval in the data between successive data points
- * in the generated path.
- * @param returnDefinition How the statistic variables were defined,
- * according to the definitions in
- * <code>ReturnPath</code>'s two class variables
- * <code>COMPOUNDED</code> and
- * <code>NONCOMPOUNDED</code>.
- * @param expectedReturnRate The measured mean drift for which to generate.
- * @param volatility The measured volatility for which to generate.
- * @param nTimeSteps The number of time steps for which to generate.
+ * These instance variables are members of PathId class.
+ * Invoking with this particular signature should point to the
+ * definition in the PathId class.
*/
- public MonteCarloPath(String name,
- int startDate,
- int endDate,
- float dTime,
- int returnDefinition,
- float expectedReturnRate,
- float volatility,
- int nTimeSteps) {
- /**
- * These instance variables are members of PathId class.
- */
- this.name = name;
- this.startDate = startDate;
- this.endDate = endDate;
- this.dTime = dTime;
- this.returnDefinition = returnDefinition;
- this.expectedReturnRate = expectedReturnRate;
- this.volatility = volatility;
- this.nTimeSteps = nTimeSteps;
- this.pathValue = new float[nTimeSteps];
- this.fluctuations = new float[nTimeSteps];
- }
+ this.pathStartValue = (float)0.0;
- //------------------------------------------------------------------------
- // Methods.
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- // Accessor methods for class MonteCarloPath.
- // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
- //------------------------------------------------------------------------
+ copyInstanceVariables(pathId);
+ this.returnDefinition = returnDefinition;
+ this.expectedReturnRate = expectedReturnRate;
+ this.volatility = volatility;
+ this.nTimeSteps = nTimeSteps;
+ this.pathValue = new float[nTimeSteps];
+ this.fluctuations = new float[nTimeSteps];
+ }
+ /**
+ * Constructor, for when the user wishes to define each of the instance
+ * variables individually.
+ *
+ * @param name The name of the security which this Monte Carlo path
+ * should represent.
+ * @param startDate The date when the path starts, in 'YYYYMMDD' format.
+ * @param endDate The date when the path ends, in 'YYYYMMDD' format.
+ * @param dTime The interval in the data between successive data points
+ * in the generated path.
+ * @param returnDefinition How the statistic variables were defined,
+ * according to the definitions in
+ * <code>ReturnPath</code>'s two class variables
+ * <code>COMPOUNDED</code> and
+ * <code>NONCOMPOUNDED</code>.
+ * @param expectedReturnRate The measured mean drift for which to generate.
+ * @param volatility The measured volatility for which to generate.
+ * @param nTimeSteps The number of time steps for which to generate.
+ */
+ public MonteCarloPath(String name,
+ int startDate,
+ int endDate,
+ float dTime,
+ int returnDefinition,
+ float expectedReturnRate,
+ float volatility,
+ int nTimeSteps) {
/**
- * Accessor method for private instance variable <code>fluctuations</code>.
- *
- * @return Value of instance variable <code>fluctuations</code>.
- * @exception DemoException thrown if instance variable <code>fluctuations</code>
- * is undefined.
+ * These instance variables are members of PathId class.
*/
- /*public float[] get_fluctuations() {
+ this.name = name;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ this.dTime = dTime;
+ this.returnDefinition = returnDefinition;
+ this.expectedReturnRate = expectedReturnRate;
+ this.volatility = volatility;
+ this.nTimeSteps = nTimeSteps;
+ this.pathValue = new float[nTimeSteps];
+ this.fluctuations = new float[nTimeSteps];
+ }
+
+ //------------------------------------------------------------------------
+ // Methods.
+ //------------------------------------------------------------------------
+ //------------------------------------------------------------------------
+ // Accessor methods for class MonteCarloPath.
+ // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
+ //------------------------------------------------------------------------
+ /**
+ * Accessor method for private instance variable <code>fluctuations</code>.
+ *
+ * @return Value of instance variable <code>fluctuations</code>.
+ * @exception DemoException thrown if instance variable <code>fluctuations</code>
+ * is undefined.
+ */
+ /*public float[] get_fluctuations() {
return(this.fluctuations);
}*/
- /**
- * Set method for private instance variable <code>fluctuations</code>.
- *
- * @param fluctuations the value to set for the instance variable
- * <code>fluctuations</code>.
- */
- public void set_fluctuations(float[] fluctuations) {
- this.fluctuations = fluctuations;
- }
- /**
- * Accessor method for private instance variable <code>pathValue</code>.
- *
- * @return Value of instance variable <code>pathValue</code>.
- * @exception DemoException thrown if instance variable <code>pathValue</code>
- * is undefined.
- */
- /*public float[] get_pathValue() {
+ /**
+ * Set method for private instance variable <code>fluctuations</code>.
+ *
+ * @param fluctuations the value to set for the instance variable
+ * <code>fluctuations</code>.
+ */
+ public void set_fluctuations(float[] fluctuations) {
+ this.fluctuations = fluctuations;
+ }
+ /**
+ * Accessor method for private instance variable <code>pathValue</code>.
+ *
+ * @return Value of instance variable <code>pathValue</code>.
+ * @exception DemoException thrown if instance variable <code>pathValue</code>
+ * is undefined.
+ */
+ /*public float[] get_pathValue() {
return(this.pathValue);
}*/
- /**
- * Set method for private instance variable <code>pathValue</code>.
- *
- * @param pathValue the value to set for the instance variable <code>pathValue</code>.
- */
- public void set_pathValue(float[] pathValue) {
- this.pathValue = pathValue;
- }
- /**
- * Accessor method for private instance variable <code>returnDefinition</code>.
- *
- * @return Value of instance variable <code>returnDefinition</code>.
- * @exception DemoException thrown if instance variable <code>returnDefinition</code>
- * is undefined.
- */
- /*public int get_returnDefinition() {
+ /**
+ * Set method for private instance variable <code>pathValue</code>.
+ *
+ * @param pathValue the value to set for the instance variable <code>pathValue</code>.
+ */
+ public void set_pathValue(float[] pathValue) {
+ this.pathValue = pathValue;
+ }
+ /**
+ * Accessor method for private instance variable <code>returnDefinition</code>.
+ *
+ * @return Value of instance variable <code>returnDefinition</code>.
+ * @exception DemoException thrown if instance variable <code>returnDefinition</code>
+ * is undefined.
+ */
+ /*public int get_returnDefinition() {
return(this.returnDefinition);
}*/
- /**
- * Set method for private instance variable <code>returnDefinition</code>.
- *
- * @param returnDefinition the value to set for the instance variable
- * <code>returnDefinition</code>.
- */
- public void set_returnDefinition(int returnDefinition) {
- this.returnDefinition = returnDefinition;
- }
- /**
- * Accessor method for private instance variable <code>expectedReturnRate</code>.
- *
- * @return Value of instance variable <code>expectedReturnRate</code>.
- * @exception DemoException thrown if instance variable <code>expectedReturnRate</code>
- * is undefined.
- */
- /*public float get_expectedReturnRate() {
+ /**
+ * Set method for private instance variable <code>returnDefinition</code>.
+ *
+ * @param returnDefinition the value to set for the instance variable
+ * <code>returnDefinition</code>.
+ */
+ public void set_returnDefinition(int returnDefinition) {
+ this.returnDefinition = returnDefinition;
+ }
+ /**
+ * Accessor method for private instance variable <code>expectedReturnRate</code>.
+ *
+ * @return Value of instance variable <code>expectedReturnRate</code>.
+ * @exception DemoException thrown if instance variable <code>expectedReturnRate</code>
+ * is undefined.
+ */
+ /*public float get_expectedReturnRate() {
return(this.expectedReturnRate);
}*/
- /**
- * Set method for private instance variable <code>expectedReturnRate</code>.
- *
- * @param expectedReturnRate the value to set for the instance variable
- * <code>expectedReturnRate</code>.
- */
- public void set_expectedReturnRate(float expectedReturnRate) {
- this.expectedReturnRate = expectedReturnRate;
- }
- /**
- * Accessor method for private instance variable <code>volatility</code>.
- *
- * @return Value of instance variable <code>volatility</code>.
- * @exception DemoException thrown if instance variable <code>volatility</code>
- * is undefined.
- */
- /*public float get_volatility() {
+ /**
+ * Set method for private instance variable <code>expectedReturnRate</code>.
+ *
+ * @param expectedReturnRate the value to set for the instance variable
+ * <code>expectedReturnRate</code>.
+ */
+ public void set_expectedReturnRate(float expectedReturnRate) {
+ this.expectedReturnRate = expectedReturnRate;
+ }
+ /**
+ * Accessor method for private instance variable <code>volatility</code>.
+ *
+ * @return Value of instance variable <code>volatility</code>.
+ * @exception DemoException thrown if instance variable <code>volatility</code>
+ * is undefined.
+ */
+ /*public float get_volatility() {
return(this.volatility);
}*/
- /**
- * Set method for private instance variable <code>volatility</code>.
- *
- * @param volatility the value to set for the instance variable
- * <code>volatility</code>.
- */
- public void set_volatility(float volatility) {
- this.volatility = volatility;
- }
- /**
- * Accessor method for private instance variable <code>nTimeSteps</code>.
- *
- * @return Value of instance variable <code>nTimeSteps</code>.
- * @exception DemoException thrown if instance variable <code>nTimeSteps</code>
- * is undefined.
- */
- /*public int get_nTimeSteps() {
+ /**
+ * Set method for private instance variable <code>volatility</code>.
+ *
+ * @param volatility the value to set for the instance variable
+ * <code>volatility</code>.
+ */
+ public void set_volatility(float volatility) {
+ this.volatility = volatility;
+ }
+ /**
+ * Accessor method for private instance variable <code>nTimeSteps</code>.
+ *
+ * @return Value of instance variable <code>nTimeSteps</code>.
+ * @exception DemoException thrown if instance variable <code>nTimeSteps</code>
+ * is undefined.
+ */
+ /*public int get_nTimeSteps() {
return(this.nTimeSteps);
}*/
- /**
- * Set method for private instance variable <code>nTimeSteps</code>.
- *
- * @param nTimeSteps the value to set for the instance variable
- * <code>nTimeSteps</code>.
- */
- public void set_nTimeSteps(int nTimeSteps) {
- this.nTimeSteps = nTimeSteps;
- }
- /**
- * Accessor method for private instance variable <code>pathStartValue</code>.
- *
- * @return Value of instance variable <code>pathStartValue</code>.
- * @exception DemoException thrown if instance variable <code>pathStartValue</code>
- * is undefined.
- */
- /*public float get_pathStartValue() {
+ /**
+ * Set method for private instance variable <code>nTimeSteps</code>.
+ *
+ * @param nTimeSteps the value to set for the instance variable
+ * <code>nTimeSteps</code>.
+ */
+ public void set_nTimeSteps(int nTimeSteps) {
+ this.nTimeSteps = nTimeSteps;
+ }
+ /**
+ * Accessor method for private instance variable <code>pathStartValue</code>.
+ *
+ * @return Value of instance variable <code>pathStartValue</code>.
+ * @exception DemoException thrown if instance variable <code>pathStartValue</code>
+ * is undefined.
+ */
+ /*public float get_pathStartValue() {
return(this.pathStartValue);
}*/
- /**
- * Set method for private instance variable <code>pathStartValue</code>.
- *
- * @param pathStartValue the value to set for the instance variable
- * <code>pathStartValue</code>.
- */
- public void set_pathStartValue(float pathStartValue) {
- this.pathStartValue = pathStartValue;
- }
- //------------------------------------------------------------------------
- /**
- * Method for copying the suitable instance variable from a
- * <code>ReturnPath</code> object.
- *
- * @param obj Object used to define the instance variables which
- * should be carried over to this object.
- * @exception DemoException thrown if there is a problem accessing the
- * instance variables from the target objetct.
- */
- private void copyInstanceVariables(ReturnPath obj) {
- //
- // Instance variables defined in the PathId object.
- this.name = obj.name;
- this.startDate = obj.startDate;
- this.endDate = obj.endDate;
- this.dTime = obj.dTime;
- //
- // Instance variables defined in this object.
- this.returnDefinition = obj.returnDefinition;
- this.expectedReturnRate = obj.expectedReturnRate;
- this.volatility = obj.volatility;
- }
+ /**
+ * Set method for private instance variable <code>pathStartValue</code>.
+ *
+ * @param pathStartValue the value to set for the instance variable
+ * <code>pathStartValue</code>.
+ */
+ public void set_pathStartValue(float pathStartValue) {
+ this.pathStartValue = pathStartValue;
+ }
+ //------------------------------------------------------------------------
+ /**
+ * Method for copying the suitable instance variable from a
+ * <code>ReturnPath</code> object.
+ *
+ * @param obj Object used to define the instance variables which
+ * should be carried over to this object.
+ * @exception DemoException thrown if there is a problem accessing the
+ * instance variables from the target objetct.
+ */
+ private void copyInstanceVariables(ReturnPath obj) {
+ //
+ // Instance variables defined in the PathId object.
+ this.name = obj.name;
+ this.startDate = obj.startDate;
+ this.endDate = obj.endDate;
+ this.dTime = obj.dTime;
+ //
+ // Instance variables defined in this object.
+ this.returnDefinition = obj.returnDefinition;
+ this.expectedReturnRate = obj.expectedReturnRate;
+ this.volatility = obj.volatility;
+ }
- /**
- * Method for returning a RatePath object from the Monte Carlo data
- * generated.
- *
- * @return a <code>RatePath</code> object representing the generated
- * data.
- * @exception DemoException thrown if there was a problem creating
- * the RatePath object.
- */
- public RatePath getRatePath() {
- return(new RatePath(this));
+ /**
+ * Method for returning a RatePath object from the Monte Carlo data
+ * generated.
+ *
+ * @return a <code>RatePath</code> object representing the generated
+ * data.
+ * @exception DemoException thrown if there was a problem creating
+ * the RatePath object.
+ */
+ public RatePath getRatePath() {
+ return(new RatePath(this));
+ }
+ /**
+ * Method for calculating the sequence of fluctuations, based around
+ * a Gaussian distribution of given mean and variance, as defined
+ * in this class' instance variables. Mapping from Gaussian
+ * distribution of (0,1) to (mean-drift,volatility) is done via
+ * Ito's lemma on the log of the stock price.
+ *
+ * @param randomSeed The psuedo-random number seed value, to start off a
+ * given sequence of Gaussian fluctuations.
+ * @exception DemoException thrown if there are any problems with
+ * the computation.
+ */
+ public boolean computeFluctuationsGaussian(long randomSeed) {
+ int ntimesteps = this.nTimeSteps;
+ int length = this.fluctuations.length;
+ if( ntimesteps > length ) {
+ return false;
}
- /**
- * Method for calculating the sequence of fluctuations, based around
- * a Gaussian distribution of given mean and variance, as defined
- * in this class' instance variables. Mapping from Gaussian
- * distribution of (0,1) to (mean-drift,volatility) is done via
- * Ito's lemma on the log of the stock price.
- *
- * @param randomSeed The psuedo-random number seed value, to start off a
- * given sequence of Gaussian fluctuations.
- * @exception DemoException thrown if there are any problems with
- * the computation.
- */
- public boolean computeFluctuationsGaussian(long randomSeed) {
- int ntimesteps = this.nTimeSteps;
- int length = this.fluctuations.length;
- if( ntimesteps > length ) {
- return false;
- }
- float[] flucts = this.fluctuations;
- float expectedreturnrate = this.expectedReturnRate;
- float vol = this.volatility;
- float dtime = this.dTime;
-
- //
- // First, make use of the passed in seed value.
- MyRandom rnd;
- float v1,v2, r;
- v1 = (float)0.0;
- v2 = (float)0.0;
- if( randomSeed == -1 ) {
- rnd = new MyRandom(0, v1, v2);
- } else {
- rnd = new MyRandom((int)randomSeed, v1, v2);
- }
-
- //
- // Determine the mean and standard-deviation, from the mean-drift and volatility.
- float mean = (expectedreturnrate-(float)0.5*vol*vol)*dtime;
- float sd = vol*Math.sqrtf(dtime);
- float gauss, meanGauss=(float)0.0, variance=(float)0.0;
- for( int i=0; i < ntimesteps; i += 2 ) {
- r = rnd.seed();
- gauss = r*rnd.v1;
- meanGauss+= gauss;
- variance+= gauss*gauss;
- //
- // Now map this onto a general Gaussian of given mean and variance.
- flucts[i] = mean + sd*gauss;
- // dbgPrintln("gauss="+gauss+" fluctuations="+fluctuations[i]);
-
- gauss = r*rnd.v2;
- meanGauss+= gauss;
- variance+= gauss*gauss;
- //
- // Now map this onto a general Gaussian of given mean and variance.
- flucts[i+1] = mean + sd*gauss;
- }
- meanGauss/=(float)ntimesteps;
- variance /=(float)ntimesteps;
- // dbgPrintln("meanGauss="+meanGauss+" variance="+variance);
+ float[] flucts = this.fluctuations;
+ float expectedreturnrate = this.expectedReturnRate;
+ float vol = this.volatility;
+ float dtime = this.dTime;
+
+ //
+ // First, make use of the passed in seed value.
+ MyRandom rnd;
+ float v1,v2, r;
+ v1 = (float)0.0;
+ v2 = (float)0.0;
+ if( randomSeed == -1 ) {
+ rnd = new MyRandom(0, v1, v2);
+ } else {
+ rnd = new MyRandom((int)randomSeed, v1, v2);
}
- /**
- * Method for calculating the sequence of fluctuations, based around
- * a Gaussian distribution of given mean and variance, as defined
- * in this class' instance variables. Mapping from Gaussian
- * distribution of (0,1) to (mean-drift,volatility) is done via
- * Ito's lemma on the log of the stock price. This overloaded method
- * is for when the random seed should be decided by the system.
- *
- * @exception DemoException thrown if there are any problems with
- * the computation.
- */
- public void computeFluctuationsGaussian() {
- computeFluctuationsGaussian((long)-1);
+
+ //
+ // Determine the mean and standard-deviation, from the mean-drift and volatility.
+ float mean = (expectedreturnrate-(float)0.5*vol*vol)*dtime;
+ float sd = vol*Math.sqrtf(dtime);
+ float gauss, meanGauss=(float)0.0, variance=(float)0.0;
+ for( int i=0; i < ntimesteps; i += 2 ) {
+ r = rnd.seed();
+ gauss = r*rnd.v1;
+ meanGauss+= gauss;
+ variance+= gauss*gauss;
+ //
+ // Now map this onto a general Gaussian of given mean and variance.
+ flucts[i] = mean + sd*gauss;
+ // dbgPrintln("gauss="+gauss+" fluctuations="+fluctuations[i]);
+
+ gauss = r*rnd.v2;
+ meanGauss+= gauss;
+ variance+= gauss*gauss;
+ //
+ // Now map this onto a general Gaussian of given mean and variance.
+ flucts[i+1] = mean + sd*gauss;
}
- /**
- * Method for calculating the corresponding rate path, given the
- * fluctuations and starting rate value.
- *
- * @param startValue the starting value of the rate path, to be
- * updated with the precomputed fluctuations.
- * @exception DemoException thrown if there are any problems with
- * the computation.
- */
- public void computePathValue(float startValue) {
- float[] pathvalue = this.pathValue;
- float[] flucts = this.fluctuations;
- int length = this.nTimeSteps;
- pathvalue[0] = startValue;
- if( returnDefinition == 1 |
- returnDefinition == 2) {
- for(int i=1; i < length; i++ ) {
- //System.printI((int)(flucts[i] * 10000));
- pathvalue[i] = pathvalue[i-1] * Math.expf(flucts[i]);
- }
- }
+ meanGauss/=(float)ntimesteps;
+ variance /=(float)ntimesteps;
+ // dbgPrintln("meanGauss="+meanGauss+" variance="+variance);
+ }
+ /**
+ * Method for calculating the sequence of fluctuations, based around
+ * a Gaussian distribution of given mean and variance, as defined
+ * in this class' instance variables. Mapping from Gaussian
+ * distribution of (0,1) to (mean-drift,volatility) is done via
+ * Ito's lemma on the log of the stock price. This overloaded method
+ * is for when the random seed should be decided by the system.
+ *
+ * @exception DemoException thrown if there are any problems with
+ * the computation.
+ */
+ public void computeFluctuationsGaussian() {
+ computeFluctuationsGaussian((long)-1);
+ }
+ /**
+ * Method for calculating the corresponding rate path, given the
+ * fluctuations and starting rate value.
+ *
+ * @param startValue the starting value of the rate path, to be
+ * updated with the precomputed fluctuations.
+ * @exception DemoException thrown if there are any problems with
+ * the computation.
+ */
+ public void computePathValue(float startValue) {
+ float[] pathvalue = this.pathValue;
+ float[] flucts = this.fluctuations;
+ int length = this.nTimeSteps;
+ pathvalue[0] = startValue;
+ if( returnDefinition == 1 |
+ returnDefinition == 2) {
+ for(int i=1; i < length; i++ ) {
+ //System.printI((int)(flucts[i] * 10000));
+ pathvalue[i] = pathvalue[i-1] * Math.expf(flucts[i]);
+ }
}
+ }
}
+package JGFMonteCarlo;
+
public class MyRandom {
- public int iseed;
- public float v1,v2;
+ public int iseed;
+ public float v1,v2;
- public MyRandom(int iseed, float v1, float v2) {
- this.iseed = iseed;
- this.v1 = v1;
- this.v2 = v2;
- }
+ public MyRandom(int iseed, float v1, float v2) {
+ this.iseed = iseed;
+ this.v1 = v1;
+ this.v2 = v2;
+ }
- public float update() {
- float rand;
- float scale= (float)4.656612875e-10;
+ public float update() {
+ float rand;
+ float scale= (float)4.656612875e-10;
- int is1,is2,iss2;
- int imult= 16807;
- int imod = 2147483647;
- int seed = this.iseed;
+ int is1,is2,iss2;
+ int imult= 16807;
+ int imod = 2147483647;
+ int seed = this.iseed;
- if (seed<=0) {
- iseed = seed = 1;
- }
+ if (seed<=0) {
+ iseed = seed = 1;
+ }
- is2 = seed % 32768;
- is1 = seed / 32768;
- iss2 = is2 * imult;
- is2 = iss2 % 32768;
- is1 = (is1 * imult + iss2 / 32768) % (65536);
+ is2 = seed % 32768;
+ is1 = seed / 32768;
+ iss2 = is2 * imult;
+ is2 = iss2 % 32768;
+ is1 = (is1 * imult + iss2 / 32768) % (65536);
- iseed = seed = (is1 * 32768 + is2) % imod;
+ iseed = seed = (is1 * 32768 + is2) % imod;
- rand = scale * seed;
+ rand = scale * seed;
- return rand;
+ return rand;
- }
+ }
- public float seed() {
+ public float seed() {
- float s,u1,u2,r;
- s = (float)1.0;
- //do {
- u1 = update();
- u2 = update();
+ float s,u1,u2,r;
+ s = (float)1.0;
+ //do {
+ u1 = update();
+ u2 = update();
- v1 = (float)2.0 * u1 - (float)1.0;
- v2 = (float)2.0 * u2 - (float)1.0;
- s = v1*v1 + v2*v2;
- //} while (s >= (float)1.0);
- s = s - (int)s;
- //System.printI(0xb4);
- r = Math.sqrtf((float)(-2.0*Math.logf(s))/(float)s);
- //System.printI(0xb5);
- return r;
+ v1 = (float)2.0 * u1 - (float)1.0;
+ v2 = (float)2.0 * u2 - (float)1.0;
+ s = v1*v1 + v2*v2;
+ //} while (s >= (float)1.0);
+ s = s - (int)s;
+ //System.printI(0xb4);
+ r = Math.sqrtf((float)(-2.0*Math.logf(s))/(float)s);
+ //System.printI(0xb5);
+ return r;
- }
+ }
}
-/** Banboo Version **/
+package JGFMonteCarlo;
/**************************************************************************
-* *
-* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
-* *
-* produced by *
-* *
-* Java Grande Benchmarking Project *
-* *
-* at *
-* *
-* Edinburgh Parallel Computing Centre *
-* *
-* email: epcc-javagrande@epcc.ed.ac.uk *
-* *
-* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
-* *
-* This version copyright (c) The University of Edinburgh, 2001. *
-* All rights reserved. *
-* *
-**************************************************************************/
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
+ * *
+ * This version copyright (c) The University of Edinburgh, 2001. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
/**
- * Base class for all the security objects, namely in terms of
- * providing a consistent means of identifying each such object.
- * Also provides some methods for writing out debug messages.
- *
- * @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
- */
+ * Base class for all the security objects, namely in terms of
+ * providing a consistent means of identifying each such object.
+ * Also provides some methods for writing out debug messages.
+ *
+ * @author H W Yau
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
+ */
public class PathId {
//------------------------------------------------------------------------
// Instance variables.
//------------------------------------------------------------------------
/**
- * Simple string name.
- */
+ * Simple string name.
+ */
public String name;
/**
- * The start date for the path, in YYYYMMDD format.
- */
+ * The start date for the path, in YYYYMMDD format.
+ */
public int startDate;
/**
- * The end date for the path, in YYYYMMDD format.
- */
+ * The end date for the path, in YYYYMMDD format.
+ */
public int endDate;
/**
- * The change in time between two successive data values.
- */
+ * The change in time between two successive data values.
+ */
public float dTime;
//------------------------------------------------------------------------
// Constructors.
//------------------------------------------------------------------------
/**
- * Default constructor.
- */
+ * Default constructor.
+ */
public PathId() {
this.startDate=0;
this.endDate=0;
}
/**
- * Another constructor.
- *
- * @param name The name for the security to record.
- */
+ * Another constructor.
+ *
+ * @param name The name for the security to record.
+ */
public PathId(String name) {
this.name = name;
this.startDate=0;
// Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
//------------------------------------------------------------------------
/**
- * Accessor method for private instance variable <code>name</code>.
- *
- * @return Value of instance variable <code>name</code>.
- * @exception DemoException thrown if instance variable <code>name</code> is undefined.
- */
+ * Accessor method for private instance variable <code>name</code>.
+ *
+ * @return Value of instance variable <code>name</code>.
+ * @exception DemoException thrown if instance variable <code>name</code> is undefined.
+ */
/*public String get_name() {
return(this.name);
}*/
/**
- * Set method for private instance variable <code>name</code>.
- *
- * @param name the value to set for the instance variable <code>name</code>.
- */
+ * Set method for private instance variable <code>name</code>.
+ *
+ * @param name the value to set for the instance variable <code>name</code>.
+ */
public void set_name(String name) {
this.name = name;
}
/**
- * Accessor method for private instance variable <code>startDate</code>.
- *
- * @return Value of instance variable <code>startDate</code>.
- * @exception DemoException thrown if instance variable <code>startDate</code> is undefined.
- */
+ * Accessor method for private instance variable <code>startDate</code>.
+ *
+ * @return Value of instance variable <code>startDate</code>.
+ * @exception DemoException thrown if instance variable <code>startDate</code> is undefined.
+ */
/*public int get_startDate() {
return(this.startDate);
}*/
/**
- * Set method for private instance variable <code>startDate</code>.
- *
- * @param startDate the value to set for the instance variable <code>startDate</code>.
- */
+ * Set method for private instance variable <code>startDate</code>.
+ *
+ * @param startDate the value to set for the instance variable <code>startDate</code>.
+ */
public void set_startDate(int startDate) {
this.startDate = startDate;
}
/**
- * Accessor method for private instance variable <code>endDate</code>.
- *
- * @return Value of instance variable <code>endDate</code>.
- * @exception DemoException thrown if instance variable <code>endDate</code> is undefined.
- */
+ * Accessor method for private instance variable <code>endDate</code>.
+ *
+ * @return Value of instance variable <code>endDate</code>.
+ * @exception DemoException thrown if instance variable <code>endDate</code> is undefined.
+ */
/*public int get_endDate() {
return(this.endDate);
}*/
/**
- * Set method for private instance variable <code>endDate</code>.
- *
- * @param endDate the value to set for the instance variable <code>endDate</code>.
- */
+ * Set method for private instance variable <code>endDate</code>.
+ *
+ * @param endDate the value to set for the instance variable <code>endDate</code>.
+ */
public void set_endDate(int endDate) {
this.endDate = endDate;
}
/**
- * Accessor method for private instance variable <code>dTime</code>.
- *
- * @return Value of instance variable <code>dTime</code>.
- * @exception DemoException thrown if instance variable <code>dTime</code> is undefined.
- */
+ * Accessor method for private instance variable <code>dTime</code>.
+ *
+ * @return Value of instance variable <code>dTime</code>.
+ * @exception DemoException thrown if instance variable <code>dTime</code> is undefined.
+ */
/*public float get_dTime() {
return(this.dTime);
}*/
/**
- * Set method for private instance variable <code>dTime</code>.
- *
- * @param dTime the value to set for the instance variable <code>dTime</code>.
- */
+ * Set method for private instance variable <code>dTime</code>.
+ *
+ * @param dTime the value to set for the instance variable <code>dTime</code>.
+ */
public void set_dTime(float dTime) {
this.dTime = dTime;
}
//------------------------------------------------------------------------
/**
- * Clone the instance variables in this class, from another instance
- * of this class.
- *
- * @param obj the PathId object from which to copy.
- * @exception DemoException thrown if the values to be copied contain
- * any undefined objects.
- */
+ * Clone the instance variables in this class, from another instance
+ * of this class.
+ *
+ * @param obj the PathId object from which to copy.
+ * @exception DemoException thrown if the values to be copied contain
+ * any undefined objects.
+ */
public void copyInstanceVariables(PathId obj) {
this.name = obj.name;
this.startDate = obj.startDate;
this.dTime = obj.dTime;
}
/**
- * Dumps the contents of the fields, to standard-out, for debugging.
- */
+ * Dumps the contents of the fields, to standard-out, for debugging.
+ */
public void dbgDumpFields() {
-// dbgPrintln("name=" +this.name);
-// dbgPrintln("startDate="+this.startDate);
-// dbgPrintln("endDate=" +this.endDate);
-// dbgPrintln("dTime=" +this.dTime);
+ // dbgPrintln("name=" +this.name);
+ // dbgPrintln("startDate="+this.startDate);
+ // dbgPrintln("endDate=" +this.endDate);
+ // dbgPrintln("dTime=" +this.dTime);
}
}
-/** Banboo Version **/
+package JGFMonteCarlo;
/**************************************************************************
* *
* value.
*
* @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
*/
public class PriceStock{
- //------------------------------------------------------------------------
- // Instance variables.
- //------------------------------------------------------------------------
- /**
- * The Monte Carlo path to be generated.
- */
- public MonteCarloPath mcPath;
- /**
- * String identifier for a given task.
- */
- //private String taskHeader;
- /**
- * Random seed from which the Monte Carlo sequence is started.
- */
- public long randomSeed;
- /**
- * Initial stock price value.
- */
- public float pathStartValue;
- /**
- * Object which represents the results from a given computation task.
- */
- public ToResult result;
- public float expectedReturnRate;
- public float volatility;
- public float volatility2;
- public float finalStockPrice;
- public float[] pathValue;
+ //------------------------------------------------------------------------
+ // Instance variables.
+ //------------------------------------------------------------------------
+ /**
+ * The Monte Carlo path to be generated.
+ */
+ public MonteCarloPath mcPath;
+ /**
+ * String identifier for a given task.
+ */
+ //private String taskHeader;
+ /**
+ * Random seed from which the Monte Carlo sequence is started.
+ */
+ public long randomSeed;
+ /**
+ * Initial stock price value.
+ */
+ public float pathStartValue;
+ /**
+ * Object which represents the results from a given computation task.
+ */
+ public ToResult result;
+ public float expectedReturnRate;
+ public float volatility;
+ public float volatility2;
+ public float finalStockPrice;
+ public float[] pathValue;
- //------------------------------------------------------------------------
- // Constructors.
- //------------------------------------------------------------------------
- /**
- * Default constructor.
- */
- public PriceStock() {
- //this.taskHeader = "";
- this.randomSeed=-1;
- this.pathStartValue=(float)0.0;
- this.expectedReturnRate=(float)0.0;
- this.volatility=(float)0.0;
- this.volatility2=(float)0.0;
- this.finalStockPrice=(float)0.0;
+ //------------------------------------------------------------------------
+ // Constructors.
+ //------------------------------------------------------------------------
+ /**
+ * Default constructor.
+ */
+ public PriceStock() {
+ //this.taskHeader = "";
+ this.randomSeed=-1;
+ this.pathStartValue=(float)0.0;
+ this.expectedReturnRate=(float)0.0;
+ this.volatility=(float)0.0;
+ this.volatility2=(float)0.0;
+ this.finalStockPrice=(float)0.0;
- mcPath = new MonteCarloPath();
- }
- //------------------------------------------------------------------------
- // Methods.
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- // Methods which implement the Slaveable interface.
- //------------------------------------------------------------------------
- /**
- * Method which is passed in the initialisation data common to all tasks,
- * and then unpacks them for use by this object.
- *
- * @param obj Object representing data which are common to all tasks.
- */
- public void setInitAllTasks(AppDemoRunner obj) {
- mcPath.name = obj.name;
- mcPath.startDate = obj.startDate;
- mcPath.endDate = obj.endDate;
- mcPath.dTime = obj.dTime;
- mcPath.returnDefinition = obj.returnDefinition;
- mcPath.expectedReturnRate = obj.expectedReturnRate;
- mcPath.volatility = obj.volatility;
- int nTimeSteps = obj.nTimeSteps;
- mcPath.nTimeSteps = nTimeSteps;
- this.pathStartValue = obj.pathStartValue;
- mcPath.pathStartValue = pathStartValue;
- mcPath.pathValue = new float[nTimeSteps];
- mcPath.fluctuations = new float[nTimeSteps];
- }
- /**
- * Method which is passed in the data representing each task, which then
- * unpacks it for use by this object.
- *
- * @param obj Object representing the data which defines a given task.
- */
- public void setTask(/*String header, */long randomSeed) {
- //this.taskHeader = header;
- this.randomSeed = randomSeed;
- }
- /**
- * The business end. Invokes the necessary computation routine, for a
- * a given task.
- */
- public void run() {
- mcPath.computeFluctuationsGaussian(randomSeed);
- mcPath.computePathValue(pathStartValue);
- RatePath rateP = new RatePath(mcPath);
- ReturnPath returnP = rateP.getReturnCompounded();
- returnP.estimatePath();
- expectedReturnRate = returnP.expectedReturnRate;
- volatility = returnP.volatility;
- volatility2 = returnP.volatility2;
- finalStockPrice = rateP.getEndPathValue();//pathValue[rateP.pathValue.length-1];
- pathValue = mcPath.pathValue;
- }
- /*
- * Method which returns the results of a computation back to the caller.
- *
- * @return An object representing the computed results.
- */
- public ToResult getResult() {
- //String resultHeader = "Result of task with Header="+taskHeader+": randomSeed="+randomSeed+": pathStartValue="+(int)pathStartValue;
- ToResult res = new ToResult(/*resultHeader,*/
- expectedReturnRate,
- volatility,
- volatility2,
- finalStockPrice,
- pathValue);
- return res;
- }
+ mcPath = new MonteCarloPath();
+ }
+ //------------------------------------------------------------------------
+ // Methods.
+ //------------------------------------------------------------------------
+ //------------------------------------------------------------------------
+ // Methods which implement the Slaveable interface.
+ //------------------------------------------------------------------------
+ /**
+ * Method which is passed in the initialisation data common to all tasks,
+ * and then unpacks them for use by this object.
+ *
+ * @param obj Object representing data which are common to all tasks.
+ */
+ public void setInitAllTasks(AppDemoRunner obj) {
+ mcPath.name = obj.name;
+ mcPath.startDate = obj.startDate;
+ mcPath.endDate = obj.endDate;
+ mcPath.dTime = obj.dTime;
+ mcPath.returnDefinition = obj.returnDefinition;
+ mcPath.expectedReturnRate = obj.expectedReturnRate;
+ mcPath.volatility = obj.volatility;
+ int nTimeSteps = obj.nTimeSteps;
+ mcPath.nTimeSteps = nTimeSteps;
+ this.pathStartValue = obj.pathStartValue;
+ mcPath.pathStartValue = pathStartValue;
+ mcPath.pathValue = new float[nTimeSteps];
+ mcPath.fluctuations = new float[nTimeSteps];
+ }
+ /**
+ * Method which is passed in the data representing each task, which then
+ * unpacks it for use by this object.
+ *
+ * @param obj Object representing the data which defines a given task.
+ */
+ public void setTask(/*String header, */long randomSeed) {
+ //this.taskHeader = header;
+ this.randomSeed = randomSeed;
+ }
+ /**
+ * The business end. Invokes the necessary computation routine, for a
+ * a given task.
+ */
+ public void run() {
+ mcPath.computeFluctuationsGaussian(randomSeed);
+ mcPath.computePathValue(pathStartValue);
+ RatePath rateP = new RatePath(mcPath);
+ ReturnPath returnP = rateP.getReturnCompounded();
+ returnP.estimatePath();
+ expectedReturnRate = returnP.expectedReturnRate;
+ volatility = returnP.volatility;
+ volatility2 = returnP.volatility2;
+ finalStockPrice = rateP.getEndPathValue();//pathValue[rateP.pathValue.length-1];
+ pathValue = mcPath.pathValue;
+ }
+ /*
+ * Method which returns the results of a computation back to the caller.
+ *
+ * @return An object representing the computed results.
+ */
+ public ToResult getResult() {
+ //String resultHeader = "Result of task with Header="+taskHeader+": randomSeed="+randomSeed+": pathStartValue="+(int)pathStartValue;
+ ToResult res = new ToResult(/*resultHeader,*/
+ expectedReturnRate,
+ volatility,
+ volatility2,
+ finalStockPrice,
+ pathValue);
+ return res;
+ }
}
-/** Banboo Version **/
+package JGFMonteCarlo;
/**************************************************************************
* *
* </ol>
*
* @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
*/
public class RatePath extends PathId {
- //------------------------------------------------------------------------
- // Class variables.
- //------------------------------------------------------------------------
- /**
- * Class variable to represent the minimal date, whence the stock prices
- * appear. Used to trap any potential problems with the data.
- */
- public int MINIMUMDATE;
- /**
- * Class variable for defining what is meant by a small number, small enough
- * to cause an arithmetic overflow when dividing. According to the
- * Java Nutshell book, the actual range is +/-4.9406564841246544E-324
- */
- public float EPSILON;
+ //------------------------------------------------------------------------
+ // Class variables.
+ //------------------------------------------------------------------------
+ /**
+ * Class variable to represent the minimal date, whence the stock prices
+ * appear. Used to trap any potential problems with the data.
+ */
+ public int MINIMUMDATE;
+ /**
+ * Class variable for defining what is meant by a small number, small enough
+ * to cause an arithmetic overflow when dividing. According to the
+ * Java Nutshell book, the actual range is +/-4.9406564841246544E-324
+ */
+ public float EPSILON;
- //------------------------------------------------------------------------
- // Instance variables.
- //------------------------------------------------------------------------
- /**
- * An instance variable, for storing the rate's path values itself.
- */
- public float[] pathValue;
- /**
- * An instance variable, for storing the corresponding date of the datum,
- * in 'YYYYMMDD' format.
- */
- public int[] pathDate;
- /**
- * The number of accepted values in the rate path.
- */
- public int nAcceptedPathValue;
+ //------------------------------------------------------------------------
+ // Instance variables.
+ //------------------------------------------------------------------------
+ /**
+ * An instance variable, for storing the rate's path values itself.
+ */
+ public float[] pathValue;
+ /**
+ * An instance variable, for storing the corresponding date of the datum,
+ * in 'YYYYMMDD' format.
+ */
+ public int[] pathDate;
+ /**
+ * The number of accepted values in the rate path.
+ */
+ public int nAcceptedPathValue;
- //------------------------------------------------------------------------
- // Constructors.
- //------------------------------------------------------------------------
- /**
- * Constructor, where the user specifies the directory and filename in
- * from which the data should be read.
- *
- * @param String dirName
- * @param String filename
- * @exception DemoException thrown if there is a problem reading in
- * the data file.
- */
- public RatePath() {
- this.MINIMUMDATE = 19000101;
- this.EPSILON= (float)10.0 * (float)(4.9E-324);
- this.nAcceptedPathValue = 0;
- readRatesFile();
- }
- /**
- * Constructor, for when the user specifies simply an array of values
- * for the path. User must also include information for specifying
- * the other characteristics of the path.
- *
- * @param pathValue the array containing the values for the path.
- * @param name the name to attach to the path.
- * @param startDate date from which the path is supposed to start, in
- * 'YYYYMMDD' format.
- * @param startDate date from which the path is supposed to end, in
- * 'YYYYMMDD' format.
- * @param dTime the time interval between successive path values, in
- * fractions of a year.
- */
- public RatePath(float[] pathValue,
- String name,
- int startDate,
- int endDate,
- float dTime) {
- this.MINIMUMDATE = 19000101;
- this.EPSILON= (float)10.0 * (float)(4.9E-324);
-
- this.name = name;
- this.startDate = startDate;
- this.endDate = endDate;
- this.dTime = dTime;
- this.pathValue = pathValue;
- this.nAcceptedPathValue = pathValue.length;
- }
- /**
- * Constructor, for use by the Monte Carlo generator, when it wishes
- * to represent its findings as a RatePath object.
- *
- * @param mc the Monte Carlo generator object, whose data are to
- * be copied over.
- * @exception DemoException thrown if there is an attempt to access
- * an undefined variable.
- */
- public RatePath(MonteCarloPath mc) {
- this.MINIMUMDATE = 19000101;
- this.EPSILON= (float)10.0 * (float)(4.9E-324);
+ //------------------------------------------------------------------------
+ // Constructors.
+ //------------------------------------------------------------------------
+ /**
+ * Constructor, where the user specifies the directory and filename in
+ * from which the data should be read.
+ *
+ * @param String dirName
+ * @param String filename
+ * @exception DemoException thrown if there is a problem reading in
+ * the data file.
+ */
+ public RatePath() {
+ this.MINIMUMDATE = 19000101;
+ this.EPSILON= (float)10.0 * (float)(4.9E-324);
+ this.nAcceptedPathValue = 0;
+ readRatesFile();
+ }
+ /**
+ * Constructor, for when the user specifies simply an array of values
+ * for the path. User must also include information for specifying
+ * the other characteristics of the path.
+ *
+ * @param pathValue the array containing the values for the path.
+ * @param name the name to attach to the path.
+ * @param startDate date from which the path is supposed to start, in
+ * 'YYYYMMDD' format.
+ * @param startDate date from which the path is supposed to end, in
+ * 'YYYYMMDD' format.
+ * @param dTime the time interval between successive path values, in
+ * fractions of a year.
+ */
+ public RatePath(float[] pathValue,
+ String name,
+ int startDate,
+ int endDate,
+ float dTime) {
+ this.MINIMUMDATE = 19000101;
+ this.EPSILON= (float)10.0 * (float)(4.9E-324);
+
+ this.name = name;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ this.dTime = dTime;
+ this.pathValue = pathValue;
+ this.nAcceptedPathValue = pathValue.length;
+ }
+ /**
+ * Constructor, for use by the Monte Carlo generator, when it wishes
+ * to represent its findings as a RatePath object.
+ *
+ * @param mc the Monte Carlo generator object, whose data are to
+ * be copied over.
+ * @exception DemoException thrown if there is an attempt to access
+ * an undefined variable.
+ */
+ public RatePath(MonteCarloPath mc) {
+ this.MINIMUMDATE = 19000101;
+ this.EPSILON= (float)10.0 * (float)(4.9E-324);
- //
- // Fields pertaining to the parent PathId object:
- this.name = mc.name;
- this.startDate = mc.startDate;
- this.endDate = mc.endDate;
- this.dTime = mc.dTime;
- //
- // Fields pertaining to RatePath object itself.
- pathValue=mc.pathValue;
- nAcceptedPathValue=mc.nTimeSteps;
- //
- // Note that currently the pathDate is neither declared, defined,
- // nor used in the MonteCarloPath object.
- pathDate=new int[nAcceptedPathValue];
+ //
+ // Fields pertaining to the parent PathId object:
+ this.name = mc.name;
+ this.startDate = mc.startDate;
+ this.endDate = mc.endDate;
+ this.dTime = mc.dTime;
+ //
+ // Fields pertaining to RatePath object itself.
+ pathValue=mc.pathValue;
+ nAcceptedPathValue=mc.nTimeSteps;
+ //
+ // Note that currently the pathDate is neither declared, defined,
+ // nor used in the MonteCarloPath object.
+ pathDate=new int[nAcceptedPathValue];
+ }
+ /**
+ * Constructor, for when there is no actual pathValue with which to
+ * initialise.
+ *
+ * @param pathValueLegth the length of the array containing the values
+ * for the path.
+ * @param name the name to attach to the path.
+ * @param startDate date from which the path is supposed to start, in
+ * 'YYYYMMDD' format.
+ * @param startDate date from which the path is supposed to end, in
+ * 'YYYYMMDD' format.
+ * @param dTime the time interval between successive path values, in
+ * fractions of a year.
+ */
+ public RatePath(int pathValueLength,
+ String name,
+ int startDate,
+ int endDate,
+ float dTime) {
+ this.MINIMUMDATE = 19000101;
+ this.EPSILON= (float)10.0 * (float)(4.9E-324);
+
+ this.name = name;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ this.dTime = dTime;
+ this.pathValue = new float[pathValueLength];
+ this.nAcceptedPathValue = pathValue.length;
+ }
+ //------------------------------------------------------------------------
+ // Methods.
+ //------------------------------------------------------------------------
+ /**
+ * Routine to update this rate path with the values from another rate
+ * path, via its pathValue array.
+ *
+ * @param operandPath the path value array to use for the update.
+ * @exception DemoException thrown if there is a mismatch between the
+ * lengths of the operand and target arrays.
+ */
+ public boolean inc_pathValue(float[] operandPath) {
+ int length = this.pathValue.length;
+ if( length != operandPath.length ) {
+ return false;
}
- /**
- * Constructor, for when there is no actual pathValue with which to
- * initialise.
- *
- * @param pathValueLegth the length of the array containing the values
- * for the path.
- * @param name the name to attach to the path.
- * @param startDate date from which the path is supposed to start, in
- * 'YYYYMMDD' format.
- * @param startDate date from which the path is supposed to end, in
- * 'YYYYMMDD' format.
- * @param dTime the time interval between successive path values, in
- * fractions of a year.
- */
- public RatePath(int pathValueLength,
- String name,
- int startDate,
- int endDate,
- float dTime) {
- this.MINIMUMDATE = 19000101;
- this.EPSILON= (float)10.0 * (float)(4.9E-324);
-
- this.name = name;
- this.startDate = startDate;
- this.endDate = endDate;
- this.dTime = dTime;
- this.pathValue = new float[pathValueLength];
- this.nAcceptedPathValue = pathValue.length;
+ float[] pathvalue = this.pathValue;
+ for(int i=0; i<length; i++ ) {
+ pathvalue[i] += operandPath[i];
}
- //------------------------------------------------------------------------
- // Methods.
- //------------------------------------------------------------------------
- /**
- * Routine to update this rate path with the values from another rate
- * path, via its pathValue array.
- *
- * @param operandPath the path value array to use for the update.
- * @exception DemoException thrown if there is a mismatch between the
- * lengths of the operand and target arrays.
- */
- public boolean inc_pathValue(float[] operandPath) {
- int length = this.pathValue.length;
- if( length != operandPath.length ) {
- return false;
- }
- float[] pathvalue = this.pathValue;
- for(int i=0; i<length; i++ ) {
- pathvalue[i] += operandPath[i];
- }
- return true;
+ return true;
+ }
+ /**
+ * Routine to scale this rate path by a constant.
+ *
+ * @param scale the constant with which to multiply to all the path
+ * values.
+ * @exception DemoException thrown if there is a mismatch between the
+ * lengths of the operand and target arrays.
+ */
+ public boolean inc_pathValue(float scale) {
+ float[] pathvalue = this.pathValue;
+ if( pathvalue==null ) {
+ return false;
}
- /**
- * Routine to scale this rate path by a constant.
- *
- * @param scale the constant with which to multiply to all the path
- * values.
- * @exception DemoException thrown if there is a mismatch between the
- * lengths of the operand and target arrays.
- */
- public boolean inc_pathValue(float scale) {
- float[] pathvalue = this.pathValue;
- if( pathvalue==null ) {
- return false;
- }
- int length = this.pathValue.length;
- for(int i=0; i<length; i++ ) {
- pathvalue[i] *= scale;
- }
- return true;
+ int length = this.pathValue.length;
+ for(int i=0; i<length; i++ ) {
+ pathvalue[i] *= scale;
}
- //------------------------------------------------------------------------
- // Accessor methods for class RatePath.
- // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
- //------------------------------------------------------------------------
- /**
- * Accessor method for private instance variable <code>pathValue</code>.
- *
- * @return Value of instance variable <code>pathValue</code>.
- * @exception DemoException thrown if instance variable <code>pathValue</code> is undefined.
- */
- /*public float[] get_pathValue() {
+ return true;
+ }
+ //------------------------------------------------------------------------
+ // Accessor methods for class RatePath.
+ // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
+ //------------------------------------------------------------------------
+ /**
+ * Accessor method for private instance variable <code>pathValue</code>.
+ *
+ * @return Value of instance variable <code>pathValue</code>.
+ * @exception DemoException thrown if instance variable <code>pathValue</code> is undefined.
+ */
+ /*public float[] get_pathValue() {
return(this.pathValue);
}*/
- /**
- * Set method for private instance variable <code>pathValue</code>.
- *
- * @param pathValue the value to set for the instance variable <code>pathValue</code>.
- */
- public void set_pathValue(float[] pathValue) {
- this.pathValue = pathValue;
- }
- /**
- * Accessor method for private instance variable <code>pathDate</code>.
- *
- * @return Value of instance variable <code>pathDate</code>.
- * @exception DemoException thrown if instance variable <code>pathDate</code> is undefined.
- */
- /*public int[] get_pathDate() {
+ /**
+ * Set method for private instance variable <code>pathValue</code>.
+ *
+ * @param pathValue the value to set for the instance variable <code>pathValue</code>.
+ */
+ public void set_pathValue(float[] pathValue) {
+ this.pathValue = pathValue;
+ }
+ /**
+ * Accessor method for private instance variable <code>pathDate</code>.
+ *
+ * @return Value of instance variable <code>pathDate</code>.
+ * @exception DemoException thrown if instance variable <code>pathDate</code> is undefined.
+ */
+ /*public int[] get_pathDate() {
return(this.pathDate);
}*/
- /**
- * Set method for private instance variable <code>pathDate</code>.
- *
- * @param pathDate the value to set for the instance variable <code>pathDate</code>.
- */
- public void set_pathDate(int[] pathDate) {
- this.pathDate = pathDate;
- }
- //------------------------------------------------------------------------
- /**
- * Method to return the terminal value for a given rate path, as used
- * in derivative calculations.
- *
- * @return The last value in the rate path.
- */
- public float getEndPathValue() {
- return( getPathValue(pathValue.length-1) );
+ /**
+ * Set method for private instance variable <code>pathDate</code>.
+ *
+ * @param pathDate the value to set for the instance variable <code>pathDate</code>.
+ */
+ public void set_pathDate(int[] pathDate) {
+ this.pathDate = pathDate;
+ }
+ //------------------------------------------------------------------------
+ /**
+ * Method to return the terminal value for a given rate path, as used
+ * in derivative calculations.
+ *
+ * @return The last value in the rate path.
+ */
+ public float getEndPathValue() {
+ return( getPathValue(pathValue.length-1) );
+ }
+ /**
+ * Method to return the value for a given rate path, at a given index.
+ * <i>One may want to index this in a more user friendly manner!</i>
+ *
+ * @param index the index on which to return the path value.
+ * @return The value of the path at the designated index.
+ */
+ public float getPathValue(int index) {
+ return(pathValue[index]);
+ }
+ /**
+ * Method for calculating the returns on a given rate path, via the
+ * definition for the instantaneous compounded return.
+ * u_i = \ln{\frac{S_i}{S_{i-1}}}
+ *
+ * @return the return, as defined.
+ * @exception DemoException thrown if there is a problem with the
+ * calculation.
+ */
+ public ReturnPath getReturnCompounded() {
+ int length = this.nAcceptedPathValue;
+ float[] pathvalue = this.pathValue;
+ if( pathvalue == null || length == 0 ) {
+ return null;
}
- /**
- * Method to return the value for a given rate path, at a given index.
- * <i>One may want to index this in a more user friendly manner!</i>
- *
- * @param index the index on which to return the path value.
- * @return The value of the path at the designated index.
- */
- public float getPathValue(int index) {
- return(pathValue[index]);
+ float[] returnPathValue = new float[length];
+ returnPathValue[0] = (float)0.0;
+ for(int i=1; i< length; i++ ) {
+ returnPathValue[i] = Math.logf(pathvalue[i] / pathvalue[i-1]);
}
- /**
- * Method for calculating the returns on a given rate path, via the
- * definition for the instantaneous compounded return.
- * u_i = \ln{\frac{S_i}{S_{i-1}}}
- *
- * @return the return, as defined.
- * @exception DemoException thrown if there is a problem with the
- * calculation.
- */
- public ReturnPath getReturnCompounded() {
- int length = this.nAcceptedPathValue;
- float[] pathvalue = this.pathValue;
- if( pathvalue == null || length == 0 ) {
- return null;
- }
- float[] returnPathValue = new float[length];
- returnPathValue[0] = (float)0.0;
- for(int i=1; i< length; i++ ) {
- returnPathValue[i] = Math.logf(pathvalue[i] / pathvalue[i-1]);
- }
- ReturnPath rPath = new ReturnPath(returnPathValue, length, 1);
- //
- // Copy the PathId information to the ReturnPath object.
- rPath.copyInstanceVariables(this);
- rPath.estimatePath();
- return(rPath);
+ ReturnPath rPath = new ReturnPath(returnPathValue, length, 1);
+ //
+ // Copy the PathId information to the ReturnPath object.
+ rPath.copyInstanceVariables(this);
+ rPath.estimatePath();
+ return(rPath);
+ }
+ /**
+ * Method for calculating the returns on a given rate path, via the
+ * definition for the instantaneous non-compounded return.
+ * u_i = \frac{S_i - S_{i-1}}{S_i}
+ *
+ * @return the return, as defined.
+ * @exception DemoException thrown if there is a problem with the
+ * calculation.
+ */
+ public ReturnPath getReturnNonCompounded() {
+ int length = this.nAcceptedPathValue;
+ float[] pathvalue = this.pathValue;
+ if( pathvalue == null || length == 0 ) {
+ return null;
}
- /**
- * Method for calculating the returns on a given rate path, via the
- * definition for the instantaneous non-compounded return.
- * u_i = \frac{S_i - S_{i-1}}{S_i}
- *
- * @return the return, as defined.
- * @exception DemoException thrown if there is a problem with the
- * calculation.
- */
- public ReturnPath getReturnNonCompounded() {
- int length = this.nAcceptedPathValue;
- float[] pathvalue = this.pathValue;
- if( pathvalue == null || length == 0 ) {
- return null;
- }
- float[] returnPathValue = new float[length];
- returnPathValue[0] = (float)0.0;
- for(int i=1; i< length; i++ ) {
- returnPathValue[i] = (pathvalue[i] - pathvalue[i-1])/pathvalue[i];
- }
-
- ReturnPath rPath = new ReturnPath(returnPathValue, length, 2);
- //
- // Copy the PathId information to the ReturnPath object.
- rPath.copyInstanceVariables(this);
- rPath.estimatePath();
- return(rPath);
+ float[] returnPathValue = new float[length];
+ returnPathValue[0] = (float)0.0;
+ for(int i=1; i< length; i++ ) {
+ returnPathValue[i] = (pathvalue[i] - pathvalue[i-1])/pathvalue[i];
}
- //------------------------------------------------------------------------
- // Private methods.
- //------------------------------------------------------------------------
- /**
- * Method for reading in data file, in a given format.
- * Namely:
+
+ ReturnPath rPath = new ReturnPath(returnPathValue, length, 2);
+ //
+ // Copy the PathId information to the ReturnPath object.
+ rPath.copyInstanceVariables(this);
+ rPath.estimatePath();
+ return(rPath);
+ }
+ //------------------------------------------------------------------------
+ // Private methods.
+ //------------------------------------------------------------------------
+ /**
+ * Method for reading in data file, in a given format.
+ * Namely:
<pre>
881003,0.0000,14.1944,13.9444,14.0832,2200050,0
881004,0.0000,14.1668,14.0556,14.1668,1490850,0
990111,35.8125,35.8750,34.8750,35.1250,3920800,0
990112,34.8750,34.8750,34.0000,34.0625,3577500,0
</pre>
- * <p>Where the fields represent, one believes, the following:
- * <ol>
- * <li>The date in 'YYMMDD' format</li>
- * <li>Open</li>
- * <li>High</li>
- * <li>Low</li>
- * <li>Last</li>
- * <li>Volume</li>
- * <li>Open Interest</li>
- * </ol>
- * One will probably make use of the closing price, but this can be
- * redefined via the class variable <code>DATUMFIELD</code>. Note that
- * since the read in data are then used to compute the return, this would
- * be a good place to trap for zero values in the data, which will cause
- * all sorts of problems.
- *
- * @param dirName the directory in which to search for the data file.
- * @param filename the data filename itself.
- * @exception DemoException thrown if there was a problem with the data
- * file.
- */
- private void readRatesFile(){
- //
- // Now create an array to store the rates data.
- int minimumdate = MINIMUMDATE;
- float epsilon = EPSILON;
- int nLines = 1000; //200;
- int year = 88;
- int month = 10;
- int day = 3;
- this.pathValue = new float[nLines];
- this.pathDate = new int[nLines];
- float[] pathvalue = this.pathValue;
- int[] pathdate = this.pathDate;
- nAcceptedPathValue=0;
- int iLine=0;
- /*char[] date = new char[9];
+ * <p>Where the fields represent, one believes, the following:
+ * <ol>
+ * <li>The date in 'YYMMDD' format</li>
+ * <li>Open</li>
+ * <li>High</li>
+ * <li>Low</li>
+ * <li>Last</li>
+ * <li>Volume</li>
+ * <li>Open Interest</li>
+ * </ol>
+ * One will probably make use of the closing price, but this can be
+ * redefined via the class variable <code>DATUMFIELD</code>. Note that
+ * since the read in data are then used to compute the return, this would
+ * be a good place to trap for zero values in the data, which will cause
+ * all sorts of problems.
+ *
+ * @param dirName the directory in which to search for the data file.
+ * @param filename the data filename itself.
+ * @exception DemoException thrown if there was a problem with the data
+ * file.
+ */
+ private void readRatesFile(){
+ //
+ // Now create an array to store the rates data.
+ int minimumdate = MINIMUMDATE;
+ float epsilon = EPSILON;
+ int nLines = 1000; //200;
+ int year = 88;
+ int month = 10;
+ int day = 3;
+ this.pathValue = new float[nLines];
+ this.pathDate = new int[nLines];
+ float[] pathvalue = this.pathValue;
+ int[] pathdate = this.pathDate;
+ nAcceptedPathValue=0;
+ int iLine=0;
+ /*char[] date = new char[9];
date[0] = '1';
date[1] = '9';
date[2] = (char)(year/10 + '0');
date[6] = (char)(day/10 + '0');
date[7] = (char)(day%10 + '0');
date[8] = '\0';*/
- int aDate = 19881003;
- /*for(int di = 0; di < 9; di++) {
+ int aDate = 19881003;
+ /*for(int di = 0; di < 9; di++) {
aDate = aDate * 10 + (int)date[di];
}*/
- for(int k = 0; k < 20; /*40;*/ k++ ) {
- for(int j = 0; j < 50; /*5;*/ j++) {
- /*String date = "19"+String.valueOf(year);
+ for(int k = 0; k < 20; /*40;*/ k++ ) {
+ for(int j = 0; j < 50; /*5;*/ j++) {
+ /*String date = "19"+String.valueOf(year);
if(month < 10) {
date += "0";
}
date += "0";
}
date += String.valueOf(day);*/
- //int aDate = Integer.parseInt(date);
- day++;
- aDate++;
- /*if(date[7] == '9') {
+ //int aDate = Integer.parseInt(date);
+ day++;
+ aDate++;
+ /*if(date[7] == '9') {
date[7] = '0';
date[6] = (char)(date[6] + 1);
} else {
date[7] = (char)(date[7] + 1);
}*/
- if(month == 2) {
- if(day == 29) {
- day = 1;
- month++;
- /*date[6] = '0';
+ if(month == 2) {
+ if(day == 29) {
+ day = 1;
+ month++;
+ /*date[6] = '0';
date[7] = '1';
date[5] = '3';*/
- aDate += 72;// - day(29) + 101;
- }
- } else {
- if(day == 31) {
- day = 1;
- month++;
- aDate += 70;
- /*date[6] = '0';
+ aDate += 72;// - day(29) + 101;
+ }
+ } else {
+ if(day == 31) {
+ day = 1;
+ month++;
+ aDate += 70;
+ /*date[6] = '0';
date[7] = '1';*/
- if(month == 13) {
- month = 1;
- year++;
- aDate += 8800;
- /*date[4] = '0';
+ if(month == 13) {
+ month = 1;
+ year++;
+ aDate += 8800;
+ /*date[4] = '0';
date[5] = '1';
if(date[3] == '9') {
if(date[2] == '9') {
} else {
date[3] = (char)(date[3] + 1);
}*/
- } /*else {
+ } /*else {
if(date[5] == '9') {
date[4] = '1';
date[5] = '0';
date[5] = (char)(date[5] + 1);
}
}*/
- }
- }
- //
- // static float float.parsefloat() method is a feature of JDK1.2!
- int tmp = k + j;
- float aPathValue = (float)(121.7500 - tmp);
- if( (aDate <= minimumdate) /*| (Math.abs(aPathValue) < epsilon)*/ ) {
- //System.printString("Skipped erroneous data indexed by date="+date+".");
- } else {
- pathdate[iLine] = aDate;
- pathvalue[iLine] = aPathValue;
- iLine++;
- }
- }
- }
- //
- // Record the actual number of accepted data points.
- nAcceptedPathValue = iLine;
- //
- // Now to fill in the structures from the 'PathId' class.
- this.name = "rate";
- this.startDate = pathdate[0];
- this.endDate = pathdate[iLine-1];
- this.dTime = (float)(1.0/365.0);
+ }
+ }
+ //
+ // static float float.parsefloat() method is a feature of JDK1.2!
+ int tmp = k + j;
+ float aPathValue = (float)(121.7500 - tmp);
+ if( (aDate <= minimumdate) /*| (Math.abs(aPathValue) < epsilon)*/ ) {
+ //System.printString("Skipped erroneous data indexed by date="+date+".");
+ } else {
+ pathdate[iLine] = aDate;
+ pathvalue[iLine] = aPathValue;
+ iLine++;
+ }
+ }
}
+ //
+ // Record the actual number of accepted data points.
+ nAcceptedPathValue = iLine;
+ //
+ // Now to fill in the structures from the 'PathId' class.
+ this.name = "rate";
+ this.startDate = pathdate[0];
+ this.endDate = pathdate[iLine-1];
+ this.dTime = (float)(1.0/365.0);
+ }
}
-/** Banboo Version **/
+package JGFMonteCarlo;
/**************************************************************************
-* *
-* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
-* *
-* produced by *
-* *
-* Java Grande Benchmarking Project *
-* *
-* at *
-* *
-* Edinburgh Parallel Computing Centre *
-* *
-* email: epcc-javagrande@epcc.ed.ac.uk *
-* *
-* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
-* *
-* This version copyright (c) The University of Edinburgh, 2001. *
-* All rights reserved. *
-* *
-**************************************************************************/
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
+ * *
+ * This version copyright (c) The University of Edinburgh, 2001. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
/**
- * Class for representing the returns of a given security.
- *
- * <p>To do list:
- * <ol>
- * <li>Define a window over which the mean drift and volatility
- * are calculated.</li>
- * <li>Hash table to reference {DATE}->{pathValue-index}.</li>
- * </ol>
- *
- * @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
- */
+ * Class for representing the returns of a given security.
+ *
+ * <p>To do list:
+ * <ol>
+ * <li>Define a window over which the mean drift and volatility
+ * are calculated.</li>
+ * <li>Hash table to reference {DATE}->{pathValue-index}.</li>
+ * </ol>
+ *
+ * @author H W Yau
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
+ */
public class ReturnPath extends PathId {
/**
- * Flag for indicating one of the return definitions, via:
- * u_i = \ln{\frac{S_i}{S_{i-1}}}
- * corresponding to the instantaneous compounded return.
- */
+ * Flag for indicating one of the return definitions, via:
+ * u_i = \ln{\frac{S_i}{S_{i-1}}}
+ * corresponding to the instantaneous compounded return.
+ */
public int COMPOUNDED;
/**
- * Flag for indicating one of the return definitions, via:
- * u_i = \frac{S_i - S_{i-1}}{S_i}
- * corresponding to the instantaneous non-compounded return.
- */
+ * Flag for indicating one of the return definitions, via:
+ * u_i = \frac{S_i - S_{i-1}}{S_i}
+ * corresponding to the instantaneous non-compounded return.
+ */
public int NONCOMPOUNDED;
//------------------------------------------------------------------------
// Instance variables.
//------------------------------------------------------------------------
/**
- * An instance variable, for storing the return values.
- */
+ * An instance variable, for storing the return values.
+ */
public float[] pathValue;
/**
- * The number of accepted values in the rate path.
- */
+ * The number of accepted values in the rate path.
+ */
public int nPathValue;
/**
- * Integer flag for indicating how the return was calculated.
- */
+ * Integer flag for indicating how the return was calculated.
+ */
public int returnDefinition;
/**
- * Value for the expected return rate.
- */
+ * Value for the expected return rate.
+ */
public float expectedReturnRate;
/**
- * Value for the volatility, calculated from the return data.
- */
+ * Value for the volatility, calculated from the return data.
+ */
public float volatility;
/**
- * Value for the volatility-squared, a more natural quantity
- * to use for many of the calculations.
- */
+ * Value for the volatility-squared, a more natural quantity
+ * to use for many of the calculations.
+ */
public float volatility2;
/**
- * Value for the mean of this return.
- */
+ * Value for the mean of this return.
+ */
public float mean;
/**
- * Value for the variance of this return.
- */
+ * Value for the variance of this return.
+ */
public float variance;
//------------------------------------------------------------------------
// Constructors.
//------------------------------------------------------------------------
/**
- * Default constructor.
- */
+ * Default constructor.
+ */
public ReturnPath() {
super();
-
+
this.COMPOUNDED = 1;
this.NONCOMPOUNDED = 2;
this.nPathValue=-1;
}
/**
- * Another constructor.
- *
- * @param pathValue for creating a return path with a precomputed path
- * value. Indexed from 1 to <code>nPathArray-1</code>.
- * @param nPathValue the number of accepted data points in the array.
- * @param returnDefinition to tell this class how the return path values
- * were computed.
- */
+ * Another constructor.
+ *
+ * @param pathValue for creating a return path with a precomputed path
+ * value. Indexed from 1 to <code>nPathArray-1</code>.
+ * @param nPathValue the number of accepted data points in the array.
+ * @param returnDefinition to tell this class how the return path values
+ * were computed.
+ */
public ReturnPath(float[] pathValue,
- int nPathValue,
- int returnDefinition) {
+ int nPathValue,
+ int returnDefinition) {
this.pathValue = pathValue;
this.nPathValue = nPathValue;
this.returnDefinition = returnDefinition;
-
+
this.COMPOUNDED = 1;
this.NONCOMPOUNDED = 2;
this.expectedReturnRate = (float)0.0;
// Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
//------------------------------------------------------------------------
/**
- * Accessor method for private instance variable <code>pathValue</code>.
- *
- * @return Value of instance variable <code>pathValue</code>.
- * @exception DemoException thrown if instance variable <code>pathValue</code> is undefined.
- */
+ * Accessor method for private instance variable <code>pathValue</code>.
+ *
+ * @return Value of instance variable <code>pathValue</code>.
+ * @exception DemoException thrown if instance variable <code>pathValue</code> is undefined.
+ */
/*public float[] get_pathValue(){
return(this.pathValue);
}*/
/**
- * Set method for private instance variable <code>pathValue</code>.
- *
- * @param pathValue the value to set for the instance variable <code>pathValue</code>.
- */
+ * Set method for private instance variable <code>pathValue</code>.
+ *
+ * @param pathValue the value to set for the instance variable <code>pathValue</code>.
+ */
public void set_pathValue(float[] pathValue) {
this.pathValue = pathValue;
}
/**
- * Accessor method for private instance variable <code>nPathValue</code>.
- *
- * @return Value of instance variable <code>nPathValue</code>.
- * @exception DemoException thrown if instance variable <code>nPathValue</code> is undefined.
- */
+ * Accessor method for private instance variable <code>nPathValue</code>.
+ *
+ * @return Value of instance variable <code>nPathValue</code>.
+ * @exception DemoException thrown if instance variable <code>nPathValue</code> is undefined.
+ */
/*public int get_nPathValue() {
return(this.nPathValue);
}*/
/**
- * Set method for private instance variable <code>nPathValue</code>.
- *
- * @param nPathValue the value to set for the instance variable <code>nPathValue</code>.
- */
+ * Set method for private instance variable <code>nPathValue</code>.
+ *
+ * @param nPathValue the value to set for the instance variable <code>nPathValue</code>.
+ */
public void set_nPathValue(int nPathValue) {
this.nPathValue = nPathValue;
}
/**
- * Accessor method for private instance variable <code>returnDefinition</code>.
- *
- * @return Value of instance variable <code>returnDefinition</code>.
- * @exception DemoException thrown if instance variable <code>returnDefinition</code> is undefined.
- */
+ * Accessor method for private instance variable <code>returnDefinition</code>.
+ *
+ * @return Value of instance variable <code>returnDefinition</code>.
+ * @exception DemoException thrown if instance variable <code>returnDefinition</code> is undefined.
+ */
/*public int get_returnDefinition() {
return(this.returnDefinition);
}*/
/**
- * Set method for private instance variable <code>returnDefinition</code>.
- *
- * @param returnDefinition the value to set for the instance variable <code>returnDefinition</code>.
- */
+ * Set method for private instance variable <code>returnDefinition</code>.
+ *
+ * @param returnDefinition the value to set for the instance variable <code>returnDefinition</code>.
+ */
public void set_returnDefinition(int returnDefinition) {
this.returnDefinition = returnDefinition;
}
/**
- * Accessor method for private instance variable <code>expectedReturnRate</code>.
- *
- * @return Value of instance variable <code>expectedReturnRate</code>.
- * @exception DemoException thrown if instance variable <code>expectedReturnRate</code> is undefined.
- */
+ * Accessor method for private instance variable <code>expectedReturnRate</code>.
+ *
+ * @return Value of instance variable <code>expectedReturnRate</code>.
+ * @exception DemoException thrown if instance variable <code>expectedReturnRate</code> is undefined.
+ */
/*public float get_expectedReturnRate() {
return(this.expectedReturnRate);
}*/
/**
- * Set method for private instance variable <code>expectedReturnRate</code>.
- *
- * @param expectedReturnRate the value to set for the instance variable <code>expectedReturnRate</code>.
- */
+ * Set method for private instance variable <code>expectedReturnRate</code>.
+ *
+ * @param expectedReturnRate the value to set for the instance variable <code>expectedReturnRate</code>.
+ */
public void set_expectedReturnRate(float expectedReturnRate) {
this.expectedReturnRate = expectedReturnRate;
}
/**
- * Accessor method for private instance variable <code>volatility</code>.
- *
- * @return Value of instance variable <code>volatility</code>.
- * @exception DemoException thrown if instance variable <code>volatility</code> is undefined.
- */
+ * Accessor method for private instance variable <code>volatility</code>.
+ *
+ * @return Value of instance variable <code>volatility</code>.
+ * @exception DemoException thrown if instance variable <code>volatility</code> is undefined.
+ */
/*public float get_volatility() {
return(this.volatility);
}*/
/**
- * Set method for private instance variable <code>volatility</code>.
- *
- * @param volatility the value to set for the instance variable <code>volatility</code>.
- */
+ * Set method for private instance variable <code>volatility</code>.
+ *
+ * @param volatility the value to set for the instance variable <code>volatility</code>.
+ */
public void set_volatility(float volatility) {
this.volatility = volatility;
}
/**
- * Accessor method for private instance variable <code>volatility2</code>.
- *
- * @return Value of instance variable <code>volatility2</code>.
- * @exception DemoException thrown if instance variable <code>volatility2</code> is undefined.
- */
+ * Accessor method for private instance variable <code>volatility2</code>.
+ *
+ * @return Value of instance variable <code>volatility2</code>.
+ * @exception DemoException thrown if instance variable <code>volatility2</code> is undefined.
+ */
/*public float get_volatility2() {
return(this.volatility2);
}*/
/**
- * Set method for private instance variable <code>volatility2</code>.
- *
- * @param volatility2 the value to set for the instance variable <code>volatility2</code>.
- */
+ * Set method for private instance variable <code>volatility2</code>.
+ *
+ * @param volatility2 the value to set for the instance variable <code>volatility2</code>.
+ */
public void set_volatility2(float volatility2) {
this.volatility2 = volatility2;
}
/**
- * Accessor method for private instance variable <code>mean</code>.
- *
- * @return Value of instance variable <code>mean</code>.
- * @exception DemoException thrown if instance variable <code>mean</code> is undefined.
- */
+ * Accessor method for private instance variable <code>mean</code>.
+ *
+ * @return Value of instance variable <code>mean</code>.
+ * @exception DemoException thrown if instance variable <code>mean</code> is undefined.
+ */
/*public float get_mean() {
return(this.mean);
}*/
/**
- * Set method for private instance variable <code>mean</code>.
- *
- * @param mean the value to set for the instance variable <code>mean</code>.
- */
+ * Set method for private instance variable <code>mean</code>.
+ *
+ * @param mean the value to set for the instance variable <code>mean</code>.
+ */
public void set_mean(float mean) {
this.mean = mean;
}
/**
- * Accessor method for private instance variable <code>variance</code>.
- *
- * @return Value of instance variable <code>variance</code>.
- * @exception DemoException thrown if instance variable <code>variance</code> is undefined.
- */
+ * Accessor method for private instance variable <code>variance</code>.
+ *
+ * @return Value of instance variable <code>variance</code>.
+ * @exception DemoException thrown if instance variable <code>variance</code> is undefined.
+ */
/*public float get_variance() {
return(this.variance);
}*/
/**
- * Set method for private instance variable <code>variance</code>.
- *
- * @param variance the value to set for the instance variable <code>variance</code>.
- */
+ * Set method for private instance variable <code>variance</code>.
+ *
+ * @param variance the value to set for the instance variable <code>variance</code>.
+ */
public void set_variance(float variance) {
this.variance = variance;
}
//------------------------------------------------------------------------
/**
- * Method to calculate the expected return rate from the return data,
- * using the relationship:
- * \mu = \frac{\bar{u}}{\Delta t} + \frac{\sigma^2}{2}
- *
- * @exception DemoException thrown one tries to obtain an undefined variable.
- */
+ * Method to calculate the expected return rate from the return data,
+ * using the relationship:
+ * \mu = \frac{\bar{u}}{\Delta t} + \frac{\sigma^2}{2}
+ *
+ * @exception DemoException thrown one tries to obtain an undefined variable.
+ */
public void computeExpectedReturnRate() {
this.expectedReturnRate = mean/(float)this.dTime + (float)0.5*volatility2;
}
/**
- * Method to calculate <code>volatility</code> and <code>volatility2</code>
- * from the return path data, using the relationship, based on the
- * precomputed <code>variance</code>.
- * \sigma^2 = s^2\Delta t
- *
- * @exception DemoException thrown if one of the quantites in the
- * computation are undefined.
- */
+ * Method to calculate <code>volatility</code> and <code>volatility2</code>
+ * from the return path data, using the relationship, based on the
+ * precomputed <code>variance</code>.
+ * \sigma^2 = s^2\Delta t
+ *
+ * @exception DemoException thrown if one of the quantites in the
+ * computation are undefined.
+ */
public void computeVolatility() {
this.volatility2 = this.variance / (float)this.dTime;
this.volatility = Math.sqrtf(volatility2);
}
/**
- * Method to calculate the mean of the return, for use by other
- * calculations.
- *
- * @exception DemoException thrown if <code>nPathValue</code> is
- * undefined.
- */
+ * Method to calculate the mean of the return, for use by other
+ * calculations.
+ *
+ * @exception DemoException thrown if <code>nPathValue</code> is
+ * undefined.
+ */
public void computeMean() {
- float sum = (float) 0.0;
- float[] tmpvalue = this.pathValue;
- int length = this.nPathValue;
- for( int i=1; i < length; i++ ) {
- sum += tmpvalue[i];
- }
- this.mean = sum / ((float)(length - (float)1.0));
+ float sum = (float) 0.0;
+ float[] tmpvalue = this.pathValue;
+ int length = this.nPathValue;
+ for( int i=1; i < length; i++ ) {
+ sum += tmpvalue[i];
+ }
+ this.mean = sum / ((float)(length - (float)1.0));
}
/**
- * Method to calculate the variance of the retrun, for use by other
- * calculations.
- *
- * @exception DemoException thrown if the <code>mean</code> or
- * <code>nPathValue</code> values are undefined.
- */
+ * Method to calculate the variance of the retrun, for use by other
+ * calculations.
+ *
+ * @exception DemoException thrown if the <code>mean</code> or
+ * <code>nPathValue</code> values are undefined.
+ */
public void computeVariance() {
- float sum = (float) 0.0;
- int length = this.nPathValue;
- float[] tmpvalue = this.pathValue;
- float tmpmean = this.mean;
+ float sum = (float) 0.0;
+ int length = this.nPathValue;
+ float[] tmpvalue = this.pathValue;
+ float tmpmean = this.mean;
for( int i=1; i < length; i++ ) {
- sum += (tmpvalue[i] - tmpmean)*(tmpvalue[i] - tmpmean);
+ sum += (tmpvalue[i] - tmpmean)*(tmpvalue[i] - tmpmean);
}
this.variance = sum / ((float)(length - (float)1.0));
}
/**
- * A single method for invoking all the necessary methods which
- * estimate the parameters.
- *
- * @exception DemoException thrown if there is a problem reading any
- * variables.
- */
+ * A single method for invoking all the necessary methods which
+ * estimate the parameters.
+ *
+ * @exception DemoException thrown if there is a problem reading any
+ * variables.
+ */
public void estimatePath() {
computeMean();
computeVariance();
computeVolatility();
}
/**
- * Dumps the contents of the fields, to standard-out, for debugging.
- */
+ * Dumps the contents of the fields, to standard-out, for debugging.
+ */
public void dbgDumpFields() {
super.dbgDumpFields();
-// dbgPrintln("nPathValue=" +this.nPathValue);
-// dbgPrintln("expectedReturnRate="+this.expectedReturnRate);
-// dbgPrintln("volatility=" +this.volatility);
-// dbgPrintln("volatility2=" +this.volatility2);
-// dbgPrintln("mean=" +this.mean);
-// dbgPrintln("variance=" +this.variance);
+ // dbgPrintln("nPathValue=" +this.nPathValue);
+ // dbgPrintln("expectedReturnRate="+this.expectedReturnRate);
+ // dbgPrintln("volatility=" +this.volatility);
+ // dbgPrintln("volatility2=" +this.volatility2);
+ // dbgPrintln("mean=" +this.mean);
+ // dbgPrintln("variance=" +this.variance);
}
}
-/** Banboo Version **/
+package JGFMonteCarlo;
/**************************************************************************
-* *
-* Java Grande Forum Benchmark Suite - Thread Version 1.0 *
-* *
-* produced by *
-* *
-* Java Grande Benchmarking Project *
-* *
-* at *
-* *
-* Edinburgh Parallel Computing Centre *
-* *
-* email: epcc-javagrande@epcc.ed.ac.uk *
-* *
-* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
-* *
-* This version copyright (c) The University of Edinburgh, 2001. *
-* All rights reserved. *
-* *
-**************************************************************************/
+ * *
+ * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
+ * *
+ * produced by *
+ * *
+ * Java Grande Benchmarking Project *
+ * *
+ * at *
+ * *
+ * Edinburgh Parallel Computing Centre *
+ * *
+ * email: epcc-javagrande@epcc.ed.ac.uk *
+ * *
+ * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) *
+ * *
+ * This version copyright (c) The University of Edinburgh, 2001. *
+ * All rights reserved. *
+ * *
+ **************************************************************************/
/**
- * Class for defining the results of a task. Currently, this is simply
- * the Monte Carlo generate rate path.
- *
- * @author H W Yau
- * @version $Revision: 1.1 $ $Date: 2011/07/13 23:49:52 $
- */
+ * Class for defining the results of a task. Currently, this is simply
+ * the Monte Carlo generate rate path.
+ *
+ * @author H W Yau
+ * @version $Revision: 1.2 $ $Date: 2011/07/14 21:28:29 $
+ */
public class ToResult {
//private String header;
public float expectedReturnRate;
public float[] pathValue;
/**
- * Constructor, for the results from a computation.
- *
- * @param header Simple header string.
- * @param pathValue Data computed by the Monte Carlo generator.
- */
+ * Constructor, for the results from a computation.
+ *
+ * @param header Simple header string.
+ * @param pathValue Data computed by the Monte Carlo generator.
+ */
public ToResult(/*String header, */
- float expectedReturnRate,
- float volatility,
- float volatility2,
- float finalStockPrice,
- float[] pathValue) {
+ float expectedReturnRate,
+ float volatility,
+ float volatility2,
+ float finalStockPrice,
+ float[] pathValue) {
//this.header=header;
this.expectedReturnRate = expectedReturnRate;
this.volatility = volatility;
this.pathValue = pathValue;
}
/**
- * Gives a simple string representation of this object.
- *
- * @return String representation of this object.
- */
+ * Gives a simple string representation of this object.
+ *
+ * @return String representation of this object.
+ */
/*public String toString(){
return(header);
}*/
// Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999.
//------------------------------------------------------------------------
/**
- * Accessor method for private instance variable <code>header</code>.
- *
- * @return Value of instance variable <code>header</code>.
- */
+ * Accessor method for private instance variable <code>header</code>.
+ *
+ * @return Value of instance variable <code>header</code>.
+ */
/*public String get_header() {
return(this.header);
}*/
/**
- * Set method for private instance variable <code>header</code>.
- *
- * @param header the value to set for the instance variable <code>header</code>.
- */
+ * Set method for private instance variable <code>header</code>.
+ *
+ * @param header the value to set for the instance variable <code>header</code>.
+ */
/*public void set_header(String header) {
this.header = header;
}*/
/**
- * Accessor method for private instance variable <code>expectedReturnRate</code>.
- *
- * @return Value of instance variable <code>expectedReturnRate</code>.
- */
+ * Accessor method for private instance variable <code>expectedReturnRate</code>.
+ *
+ * @return Value of instance variable <code>expectedReturnRate</code>.
+ */
/*public float get_expectedReturnRate() {
return(this.expectedReturnRate);
}*/
/**
- * Set method for private instance variable <code>expectedReturnRate</code>.
- *
- * @param expectedReturnRate the value to set for the instance variable
- * <code>expectedReturnRate</code>.
- */
+ * Set method for private instance variable <code>expectedReturnRate</code>.
+ *
+ * @param expectedReturnRate the value to set for the instance variable
+ * <code>expectedReturnRate</code>.
+ */
public void set_expectedReturnRate(float expectedReturnRate) {
this.expectedReturnRate = expectedReturnRate;
}
/**
- * Accessor method for private instance variable <code>volatility</code>.
- *
- * @return Value of instance variable <code>volatility</code>.
- */
+ * Accessor method for private instance variable <code>volatility</code>.
+ *
+ * @return Value of instance variable <code>volatility</code>.
+ */
/*public float get_volatility() {
return(this.volatility);
}*/
/**
- * Set method for private instance variable <code>volatility</code>.
- *
- * @param volatility the value to set for the instance variable <code>volatility</code>.
- */
+ * Set method for private instance variable <code>volatility</code>.
+ *
+ * @param volatility the value to set for the instance variable <code>volatility</code>.
+ */
public void set_volatility(float volatility) {
this.volatility = volatility;
}
/**
- * Accessor method for private instance variable <code>volatility2</code>.
- *
- * @return Value of instance variable <code>volatility2</code>.
- */
+ * Accessor method for private instance variable <code>volatility2</code>.
+ *
+ * @return Value of instance variable <code>volatility2</code>.
+ */
/*public float get_volatility2() {
return(this.volatility2);
}*/
/**
- * Set method for private instance variable <code>volatility2</code>.
- *
- * @param volatility2 the value to set for the instance variable <code>volatility2</code>.
- */
+ * Set method for private instance variable <code>volatility2</code>.
+ *
+ * @param volatility2 the value to set for the instance variable <code>volatility2</code>.
+ */
public void set_volatility2(float volatility2) {
this.volatility2 = volatility2;
}
/**
- * Accessor method for private instance variable <code>finalStockPrice</code>.
- *
- * @return Value of instance variable <code>finalStockPrice</code>.
- */
+ * Accessor method for private instance variable <code>finalStockPrice</code>.
+ *
+ * @return Value of instance variable <code>finalStockPrice</code>.
+ */
/*public float get_finalStockPrice() {
return(this.finalStockPrice);
}*/
/**
- * Set method for private instance variable <code>finalStockPrice</code>.
- *
- * @param finalStockPrice the value to set for the instance variable
- * <code>finalStockPrice</code>.
- */
+ * Set method for private instance variable <code>finalStockPrice</code>.
+ *
+ * @param finalStockPrice the value to set for the instance variable
+ * <code>finalStockPrice</code>.
+ */
public void set_finalStockPrice(float finalStockPrice) {
this.finalStockPrice = finalStockPrice;
}
/**
- * Accessor method for private instance variable <code>pathValue</code>.
- *
- * @return Value of instance variable <code>pathValue</code>.
- */
+ * Accessor method for private instance variable <code>pathValue</code>.
+ *
+ * @return Value of instance variable <code>pathValue</code>.
+ */
/*public float[] get_pathValue() {
return(this.pathValue);
}*/
/**
- * Set method for private instance variable <code>pathValue</code>.
- *
- * @param pathValue the value to set for the instance variable <code>pathValue</code>.
- */
+ * Set method for private instance variable <code>pathValue</code>.
+ *
+ * @param pathValue the value to set for the instance variable <code>pathValue</code>.
+ */
public void set_pathValue(float[] pathValue) {
this.pathValue = pathValue;
}
+package RayTracer;
+
public class Composer {
int numCore;
public long result1;
public Composer(int numCore,
- int size) {
+ int size) {
this.numCore = numCore;
this.num_composed = 0;
heightPerCore = size/this.numCore;
this.result = 0;
this.result1 = 0;
}
-
+
public boolean compose(TestRunner tr) {
this.num_composed++;
int startidx=0; //heightPerCore * tr.id;
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
/**************************************************************************
* * Java Grande Forum Benchmark Suite - Version 2.0 * * produced by * * Java
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
{
Vec c;
float r, r2;
-//Vec v,b; // temporary vecs used to minimize the memory load
+ //Vec v,b; // temporary vecs used to minimize the memory load
public Sphere(Vec center, float radius) {
c = center;
r = radius;
r2 = r*r;
-// v=new Vec();
-// b=new Vec();
+ // v=new Vec();
+ // b=new Vec();
}
public float dot(float x1, float y1, float z1, float x2, float y2, float z2){
ip = new Isect();
ip.t = t;
ip.enter = dot(x,y,z,x,y,z) > r2 + 1e-6 ? 1 : 0;
-// ip.enter = Vec.dot(v, v) > r2 + 1e-6 ? 1 : 0;
+ // ip.enter = Vec.dot(v, v) > r2 + 1e-6 ? 1 : 0;
ip.prim = this;
ip.surf = surf;
return ip;
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package RayTracer;
+
/**************************************************************************
* * Java Grande Forum Benchmark Suite - Version 2.0 * * produced by * * Java
* Grande Benchmarking Project * * at * * Edinburgh Parallel Computing Centre *
Scene scene = rt.createScene();
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner(i, threadnum, size, scene);
- tr.run();
- if(comp.compose(tr)) {
- long r = comp.result;
- }
+ tr.start();
}
}
}
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
public static Vec cross(Vec a, Vec b) {
return
- new Vec(a.y*b.z - a.z*b.y,
- a.z*b.x - a.x*b.z,
- a.x*b.y - a.y*b.x);
+ new Vec(a.y*b.z - a.z*b.y,
+ a.z*b.x - a.x*b.z,
+ a.x*b.y - a.y*b.x);
}
public static float dot(Vec a, Vec b) {
public static Vec comb(float a, Vec A, float b, Vec B) {
return
- new Vec(a * A.x + b * B.x,
- a * A.y + b * B.y,
- a * A.z + b * B.z);
+ new Vec(a * A.x + b * B.x,
+ a * A.y + b * B.y,
+ a * A.z + b * B.z);
}
public final void comb2(float a,Vec A,float b,Vec B) {
+package RayTracer;
+
/**************************************************************************
* *
* Java Grande Forum Benchmark Suite - Version 2.0 *
+package bh;
/**
* A class used to representing particles in the N-body simulation.
+package bh;
/**
* A class used to represent internal nodes in the tree
+package bh;
/**
* A class representing a three dimensional vector that implements
+package bh;
/**
* A class that represents the common fields of a cell or body
int i = 0;
for (int k = 0; k < 3/*MathVector.NDIM*/; k++) {
if (((int)ic.value(k) & l) != 0)
- i += 8/*Cell.NSUB*/ >> (k + 1);
+ i += 8/*Cell.NSUB*/ >> (k + 1);
}
return i;
}
return hg;
}
}
-
-/**
- * A class which is used to compute and save information during the
- * gravity computation phse.
- **/
-public class HG
-{
- /**
- * Body to skip in force evaluation
- **/
- public Body pskip;
- /**
- * Point at which to evaluate field
- **/
- public MathVector pos0;
- /**
- * Computed potential at pos0
- **/
- public double phi0;
- /**
- * computed acceleration at pos0
- **/
- public MathVector acc0;
-
- /**
- * Create a HG object.
- * @param b the body object
- * @param p a vector that represents the body
- **/
- public HG(Body b, MathVector p)
- {
- pskip = b;
- pos0 = (MathVector)p.clone();
- phi0 = 0.0;
- acc0 = new MathVector();
- }
-}
-
+package bh;
/*import java.util.Enumeration;
import java.lang.Math;*/
**/
public class TestRunner extends Thread
{
-
+
/**
* The user specified number of bodies to create.
**/
public double DTIME; // = 0.0125;
public double TSTOP; // = 2.0;
-
+
public TestRunner(int nbody) {
this.nbody = nbody;
this.nsteps = 10;
* @param seed the seed to the generator
* @return a random number
**/
- public double myRand(double seed)
+ public double myRand(double seed)
{
double t = 16807.0*seed + 1;
-
+
seed = t - 2147483647.0 * Math.floor(t / 2147483647.0f);
return seed;
}
* @param r seed
* @return a doubleing point randon number
**/
- public double xRand(double xl, double xh, double r)
+ public double xRand(double xl, double xh, double r)
{
double res = xl + (xh-xl)*r/2147483647.0;
return res;
int nbody = 700;
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner(nbody);
- tr.run();
+ tr.start();
}
}
}
+package bh;
//import java.util.Enumeration;
class Tree
{
public double DTIME;
-
+
MathVector rmin;
public double rsize;
/**
rmin.value(0, -2.0);
rmin.value(1, -2.0);
rmin.value(2, -2.0);
-
+
this.DTIME = DTIME;
}
double res = xl + (xh-xl)*r/2147483647.0;
return res;
}
-
+
/**
* Create the testdata used in the benchmark.
* @param nbody the number of bodies to create
this.root = null;
makeTree(nstep);
-
+
Body next = null;
Body b = this.bodyTabRev;
do {
MathVector dacc = new MathVector();
MathVector dvel = new MathVector();
double dthf = 0.5 * this.DTIME;
-
+
Body b = p;
do {
MathVector acc1 = (MathVector)b.newAcc.clone();
b.pos = (MathVector)dpos.clone();
vel1.addition(dvel);
b.vel = (MathVector)vel1.clone();
-
+
b = b.getProcNext();
} while(b != null);
}
-public class TestRunner {
+package lcss;
+
+public class TestRunner extends Thread {
int[] testargs;
args[5] = 240;
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner(args);
- tr.run();
+ tr.start();
}
}
}
\ No newline at end of file
+package tsp;
//import java.io.*;
**/
public class TestRunner extends Thread
{
-
+
/**
* Number of cities in the problem.
**/
* Set to true to print informative messages
**/
//private static boolean printMsgs = false;
-
+
public TestRunner(int cities) {
this.cities = cities;
}
if (printMsgs)
System.out.println("Building tree of size " + cities);
-
+
long start0 = System.currentTimeMillis();*/
Tree_tsp t = Tree_tsp.buildTree(this.cities, false, 0.0f, 1.0f, 0.0f, 1.0f);
/*long end0 = System.currentTimeMillis();
int ncities = 4080*2;
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner(ncities);
- tr.run();
+ tr.start();
}
}
}
+package tsp;
//import java.util.Random;
M_E3 = 20.08553692318766774179f;
M_E6 = 403.42879349273512264299f;
M_E12 = 162754.79141900392083592475f;*/
-
+
sz = size;
this.x = x;
this.y = y;
choice = 4;
if (choice == 1) {
- //case 1:
+ //case 1:
// 1:p1,this this,p2 n2,n1 -- reverse 2!
n2.reverse();
p1.next = this;
n1.prev = n2;
//break;
} else if(choice == 2) {
- //case 2:
+ //case 2:
// 2:p1,this this,n2 p2,n1 -- OK
p1.next = this;
this.prev = p1;
n1.prev = p2;
//break;
} else if(choice == 3) {
- //case 3:
+ //case 3:
// 3:p2,this this,n1 p1,n2 -- OK
p2.next = this;
this.prev = p2;
n2.prev = p1;
//break;
} else if(choice == 4) {
- //case 4:
+ //case 4:
// 4:n1,this this,n2 p2,p1 -- reverse 1!
n1.reverse();
n1.next = this;
float M_E3 = 20.08553692318766774179f;
float M_E6 = 403.42879349273512264299f;
float M_E12 = 162754.79141900392083592475f;
-
+
// get random value in [0.0, 1.0)
float t = (new Random()).nextFloat();
+package voronoi;
/**
* A class that represents the quad edge data structure which implements
-
+package voronoi;
/**
* A class that represents an edge pair
-
+package voronoi;
/**
* A class that represents a wrapper around a double value so
-
+package voronoi;
/**
+ *
* A Java implementation of the <tt>voronoi</tt> Olden benchmark. Voronoi
* generates a random set of points and computes a Voronoi diagram for
* the points.
**/
public class TestRunner extends Thread
{
-
+
/**
* The number of points in the diagram
**/
private int points;
-
+
public TestRunner(int npoints) {
this.points = npoints;
}
Vertex point = v.createPoints(points-1, new MyDouble(extra.X()), points-1);
Edge edge = point.buildDelaunayTriangulation(extra);
}
-
+
public static void main(String[] args) {
int threadnum = 62;
int npoints = 32000;
for(int i = 0; i < threadnum; ++i) {
TestRunner tr = new TestRunner(npoints);
- tr.run();
+ tr.start();
}
}
}
-
+package voronoi;
/**
* Vector Routines from CMU vision library.
float norm;
public Vec2() {}
-
+
public Vec2(float xx, float yy)
{
x = xx;
{
return norm;
}
-
+
public void setNorm(float d)
{
norm = d;
Vec2 sub(Vec2 v)
{
- return(new Vec2((float)(x - v.x), (float)(y - v.y)));
+ return(new Vec2((float)(x - v.x), (float)(y - v.y)));
}
-/* V2_magn: magnitude of vector */
+ /* V2_magn: magnitude of vector */
float magn()
{
}
-
+
-
+package voronoi;
/**
* A class that represents a voronoi diagram. The diagram is represnted
{
left = l;
}
-
+
public void setRight(Vertex r)
{
right = r;
{
return left;
}
-
+
public Vertex getRight()
{
return right;
cur.right = right;
curmax.value = (float)cur.X();
Vertex left = cur.createPoints(n/2, curmax, i-1);
-
+
cur.left = left;
return cur;
}
Edge e = new Edge();
retval = e.doMerge(delleft.getLeft(), delleft.getRight(),
- delright.getLeft(), delright.getRight());
+ delright.getLeft(), delright.getRight());
Edge ldo = retval.getLeft();
while (ldo.orig() != minx) {
/*void print()
{
Vertex tleft, tright;
-
+
System.out.println("X=" + X() + " Y=" + Y());
if (left == null)
System.out.println("NULL");
{
Vertex temp;
Vertex tree = this;
-
+
while ((temp=tree.getLeft()) != null)
tree = temp;
return tree;
}
-
+
/****************************************************************/
/* Geometric primitives
- ****************************************************************/
+ ****************************************************************/
boolean incircle(Vertex b, Vertex c, Vertex d)
- /* incircle, as in the Guibas-Stolfi paper. */
+ /* incircle, as in the Guibas-Stolfi paper. */
{
float adx, ady, bdx, bdy, cdx, cdy, dx, dy, anorm, bnorm, cnorm, dnorm;
float dret ;
dret += (float)((cnorm - dnorm) * (adx * bdy - ady * bdx));
return( (0.0f < dret) ? true : false );
}
-
+
boolean ccw(Vertex b, Vertex c)
/* TRUE iff this, B, C form a counterclockwise oriented triangle */
{
float dret ;
float xa,ya,xb,yb,xc,yc;
Vertex loc_a,loc_b,loc_c;
-
+
int donexa,doneya,donexb,doneyb,donexc,doneyc;
loc_a = this;
{
this.seed = this.random(this.seed);
float retval = ((float)this.seed) /
- (float) 2147483647;
+ (float) 2147483647;
return retval;
}
-
+
}
-
+