📄 montecarlopath.java
字号:
/*************************************************************************** ** Java Grande Forum Benchmark Suite - MPJ 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. ** ***************************************************************************/package jgf_mpj_benchmarks.section3.montecarlo;//package montecarlo;import java.util.*;import java.io.*;/** * Class representing the paths generated by the Monte Carlo engine. * * <p>To do list: * <ol> * <li><code>double[] pathDate</code> is not simulated.</li> * </ol> * * @author H W Yau * @version $Revision: 1.1 $ $Date: 2005/04/29 17:43:42 $ */public class MonteCarloPath extends PathId { //------------------------------------------------------------------------ // Class variables. //------------------------------------------------------------------------ /** * Class variable for determining whether to switch on debug output or * not. */ public static boolean DEBUG=true; /** * Class variable for defining the debug message prompt. */ protected static String prompt="MonteCarloPath> "; /** * Class variable for determining which field in the stock data should be * used. This is currently set to point to the 'closing price', as * defined in class RatePath. */ public static int DATUMFIELD=RatePath.DATUMFIELD; //------------------------------------------------------------------------ // Instance variables. //------------------------------------------------------------------------ /** * Random fluctuations generated as a series of random numbers with * given distribution. */ private double[] fluctuations; /** * The path values from which the random fluctuations are used to update. */ private double[] pathValue; /** * Integer flag for determining how the return was calculated, when * used to calculate the mean drift and volatility parameters. */ private int returnDefinition=0; /** * Value for the mean drift, for use in the generation of the random path. */ private double expectedReturnRate=Double.NaN; /** * Value for the volatility, for use in the generation of the random path. */ private double volatility=Double.NaN; /** * Number of time steps for which the simulation should act over. */ private int nTimeSteps=0; /** * The starting value for of the security. */ private double pathStartValue=Double.NaN; //------------------------------------------------------------------------ // 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(); set_prompt(prompt); set_DEBUG(DEBUG); } /** * 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) throws DemoException { /** * These instance variables are members of PathId class. */ copyInstanceVariables(returnPath); this.nTimeSteps = nTimeSteps; this.pathValue = new double[nTimeSteps]; this.fluctuations = new double[nTimeSteps]; /** * Whether to debug, and how. */ set_prompt(prompt); set_DEBUG(DEBUG); } /** * 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, double expectedReturnRate, double volatility, int nTimeSteps) throws DemoException { /** * These instance variables are members of PathId class. * Invoking with this particular signature should point to the * definition in the PathId class. */ copyInstanceVariables(pathId); this.returnDefinition = returnDefinition; this.expectedReturnRate = expectedReturnRate; this.volatility = volatility; this.nTimeSteps = nTimeSteps; this.pathValue = new double[nTimeSteps]; this.fluctuations = new double[nTimeSteps]; /** * Whether to debug, and how. */ set_prompt(prompt); set_DEBUG(DEBUG); } /** * 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, double dTime, int returnDefinition, double expectedReturnRate, double volatility, int nTimeSteps) { /** * These instance variables are members of PathId class. */ set_name(name); set_startDate(startDate); set_endDate(endDate); set_dTime(dTime); this.returnDefinition = returnDefinition; this.expectedReturnRate = expectedReturnRate; this.volatility = volatility; this.nTimeSteps = nTimeSteps; this.pathValue = new double[nTimeSteps]; this.fluctuations = new double[nTimeSteps]; /** * Whether to debug, and how. */ set_prompt(prompt); set_DEBUG(DEBUG); } //------------------------------------------------------------------------ // 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 double[] get_fluctuations() throws DemoException { if( this.fluctuations == null ) throw new DemoException("Variable fluctuations is undefined!"); 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(double[] 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 double[] get_pathValue() throws DemoException { if( this.pathValue == null ) throw new DemoException("Variable pathValue is undefined!"); 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(double[] 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -