⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ratepath.java

📁 MPI for java for Distributed Programming
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  }  //------------------------------------------------------------------------  // 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 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>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() throws DemoException {    if( this.pathDate == null )      throw new DemoException("Variable pathDate is undefined!");    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 double 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 double 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() throws DemoException {    if( pathValue == null || nAcceptedPathValue == 0 ) {      throw new DemoException("The Rate Path has not been defined!");    }    double[] returnPathValue = new double[nAcceptedPathValue];    returnPathValue[0] = 0.0;    try{      for(int i=1; i< nAcceptedPathValue; i++ ) {	returnPathValue[i] = Math.log(pathValue[i] / pathValue[i-1]);      }    } catch( ArithmeticException aex ) {      throw new DemoException("Error in getReturnLogarithm:"+aex.toString());    }    ReturnPath rPath = new ReturnPath(returnPathValue, nAcceptedPathValue,     ReturnPath.COMPOUNDED);    //    // 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() throws DemoException {    if( pathValue == null || nAcceptedPathValue == 0 ) {      throw new DemoException("The Rate Path has not been defined!");    }    double[] returnPathValue = new double[nAcceptedPathValue];    returnPathValue[0] = 0.0;    try{      for(int i=1; i< nAcceptedPathValue; i++ ) {	returnPathValue[i] = (pathValue[i] - pathValue[i-1])/pathValue[i];      }    } catch( ArithmeticException aex ) {      throw new DemoException("Error in getReturnPercentage:"+aex.toString());    }    ReturnPath rPath = new ReturnPath(returnPathValue, nAcceptedPathValue,     ReturnPath.NONCOMPOUNDED);    //    // 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      ...      990108,35.8125,36.7500,35.5625,35.8125,4381200,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(String dirName, String filename) throws DemoException {    java.io.File ratesFile = new File(dirName, filename);    java.io.BufferedReader in;    if( ! ratesFile.canRead() ) {      throw new DemoException("Cannot read the file "+ratesFile.toString());    }    try{      in = new BufferedReader(new FileReader(ratesFile));    } catch( FileNotFoundException fnfex ) {      throw new DemoException(fnfex.toString());    }    //    // Proceed to read all the lines of data into a Vector object.    int iLine=0, initNlines=100, nLines=0;        String aLine;    java.util.Vector allLines = new Vector(initNlines);    try{      while( (aLine = in.readLine()) != null ) {	iLine++;	//	// Note, I'm not entirely sure whether the object passed in is copied	// by value, or just its reference.	allLines.addElement(aLine);      }    } catch( IOException ioex ) {      throw new DemoException("Problem reading data from the file "+ioex.toString());    }    nLines = iLine;    //    // Now create an array to store the rates data.    this.pathValue = new double[nLines];    this.pathDate  = new int[nLines];    nAcceptedPathValue=0;    iLine=0;    for( java.util.Enumeration enum_ = allLines.elements(); enum_.hasMoreElements(); ) {      aLine = (String) enum_.nextElement();      String[] field = Utilities.splitString(",",aLine);      int aDate = Integer.parseInt("19"+field[0]);      //      // static double Double.parseDouble() method is a feature of JDK1.2!      double aPathValue = Double.valueOf(field[DATUMFIELD]).doubleValue();      if( (aDate <= MINIMUMDATE) || (Math.abs(aPathValue) < EPSILON) ) {	dbgPrintln("Skipped erroneous data in "+filename+" indexed by date="+field[0]+".");      } 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.    set_name(ratesFile.getName());    set_startDate(pathDate[0]);    set_endDate(pathDate[nAcceptedPathValue-1]);    set_dTime((double)(1.0/365.0));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -