?? ratepath.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.io.*;import java.util.*;/** * Class for recording the values in the time-dependent path of a security. * * <p>To Do list: * <ol> * <li><i>None!</i> * </ol> * * @author H W Yau * @version $Revision: 1.1 $ $Date: 2005/04/29 17:43:42 $ */public class RatePath extends PathId { //------------------------------------------------------------------------ // Class variables. //------------------------------------------------------------------------ /** * Class variable, for setting whether to print debug messages. */ public static boolean DEBUG=true; /** * The prompt to write before any debug messages. */ protected static String prompt="RatePath> "; /** * Class variable for determining which field in the stock data should be * used. This is currently set to point to the 'closing price'. */ public static int DATUMFIELD=4; /** * Class variable to represent the minimal date, whence the stock prices * appear. Used to trap any potential problems with the data. */ public static final int MINIMUMDATE = 19000101; /** * 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 static final double EPSILON= 10.0 * Double.MIN_VALUE; //------------------------------------------------------------------------ // Instance variables. //------------------------------------------------------------------------ /** * An instance variable, for storing the rate's path values itself. */ private double[] pathValue; /** * An instance variable, for storing the corresponding date of the datum, * in 'YYYYMMDD' format. */ private int[] pathDate; /** * The number of accepted values in the rate path. */ private int nAcceptedPathValue=0; //------------------------------------------------------------------------ // Constructors. //------------------------------------------------------------------------ /** * Constructor, where the user specifies the filename in from which the * data should be read. * * @param String filename * @exception DemoException thrown if there is a problem reading in * the data file. */ public RatePath(String filename) throws DemoException { set_prompt(prompt); set_DEBUG(DEBUG); readRatesFile(null,filename); } /** * 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(String dirName, String filename) throws DemoException { set_prompt(prompt); set_DEBUG(DEBUG); readRatesFile(dirName,filename); } /** * 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(double[] pathValue, String name, int startDate, int endDate, double dTime) { set_name(name); set_startDate(startDate); set_endDate(endDate); set_dTime(dTime); set_prompt(prompt); set_DEBUG(DEBUG); 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) throws DemoException { // // Fields pertaining to the parent PathId object: set_name(mc.get_name()); set_startDate(mc.get_startDate()); set_endDate(mc.get_endDate()); set_dTime(mc.get_dTime()); // // Fields pertaining to RatePath object itself. pathValue=mc.get_pathValue(); nAcceptedPathValue=mc.get_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, double dTime) { set_name(name); set_startDate(startDate); set_endDate(endDate); set_dTime(dTime); set_prompt(prompt); set_DEBUG(DEBUG); this.pathValue = new double[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 void inc_pathValue(double[] operandPath) throws DemoException { if( pathValue.length != operandPath.length ) throw new DemoException("The path to update has a different size to the path to update with!"); for(int i=0; i<pathValue.length; i++ ) pathValue[i] += operandPath[i]; } /** * 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 void inc_pathValue(double scale) throws DemoException { if( pathValue==null ) throw new DemoException("Variable pathValue is undefined!"); for(int i=0; i<pathValue.length; i++ ) pathValue[i] *= scale;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -