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

📄 lognormallibor.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
字号:
/* WARANTY NOTICE AND COPYRIGHTThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.Copyright (C) Michael J. Meyermatmjm@mindspring.comspyqqqdia@yahoo.com*//* * LogNormalLibor.java * * Created on September 5, 2002, 9:00 AM */package Examples.Libor;import Libor.LiborProcess.*;import Statistics.*;import com.skylit.io.EasyReader;/** <p>Computes histograms of the errors with which the log-normal approximations *  <code>L0_j(T_j)</code> and <code>L1_j(T_j)</code> approximate true Libor *  <code>L_j(T_j)</code>. Simulations show that the approximations can be *  much larger than true Libor with a very small probability. In other words *  the errors</p> *  <p> *  <center> *  <code>err0:=L_j(T_j)-L0_j(T_j)</code> *  and  *  <code>err1:=L_j(T_j)-L1_j(T_j)</code> *  </center> *  </p> *  <p>can assume very large negative values (with small probability). If these *  values were displayed resolution of the display of the histogram would *  suffer. Thus we cut the values off at the low and and compute *  histograms of the random variables</p> *  <p> *  <center> *  <code>D0:=max{err0,-0.02}</code> *  and  *  <code>D1:=max{err1,-0.02}</code> *  </center> *  </p> *  The outliers below then show up as a point mass at -0.02. All Libors are *  initialized at <code>L_j(0)=0.04</code> with annulaized volatilities *  of about <code>0.39</code>. * * @author  Michael J. Meyer */public class LogNormalLibor {                 public static void main(String[] args)       {           EasyReader io=new EasyReader();                      // read dimension n, index j                      System.out.print           ("LIBOR: computing histograms of approximation errors\n"+            "L_i(T_i)-L0_i(T_i) and L_i(T_i)-L1_i(T_i).\n");                      // main loop           int more=1;           while(more==1){                          System.out.print           ("Enter dimension n of Libor process: ");           final int n=io.readInt();                      System.out.print("Enter Libor index j: ");           final int j=io.readInt();                       System.out.print("Enter number of sample paths: ");           final int nPaths=io.readInt();                       // Libor parameter sample            final LMM_Parameters            lmmParams=new LMM_Parameters(n,LMM_Parameters.CS);           final LiborProcess LP=new LiborProcess(lmmParams);                      // D0=L_j(T_j)-L0_j(T_j)           final RandomVariable D0=new RandomVariable(){                              public double getValue(int t)               {                   LP.newPath(j,j,true,true,false);                   double diff=LP.L(j,j)-LP.L0(j,j);                   // cutting off outliers                   return (diff>-0.02)? diff : -0.02;               }           }; // end D0                                 // D0=L_j(T_j)-L1_j(T_j)           final RandomVariable D1=new RandomVariable(){                              public double getValue(int t)               {                   LP.newPath(j,j,true,false,true);                   double diff=LP.L(j,j)-LP.L1(j,j);                   // cutting off outliers                   return (diff>-0.02)? diff : -0.02;               }           }; // end D1                      int nBins=200;                                // HISTOGRAMS           String title="log-normal approximation error",                  xAxisLabel="L_"+j+"(T_"+j+")-L0_"+j+"(T_"+j+")";;           D0.displayHistogram(nPaths,nBins,true,title,xAxisLabel);           title="log-normal approximation error";           xAxisLabel="L_"+j+"(T_"+j+")-L1_"+j+"(T_"+j+")";;           D1.displayHistogram(nPaths,nBins,true,title,xAxisLabel);                     /* MEAN AND STANDARD DEVIATION           double[] d0mstdv=D0.meanAndStandardDeviation(nPaths);           String message=           "\nL0-APPROXIMATION:\n"+           "Approximation error L_"+j+"(T_"+j+")-L0_"+j+"(T_"+j+")\n"+           "mean: "+d0mstdv[0]+"\n"+           "standard deviation: "+d0mstdv[1];           System.out.println(message);                      double[] d1mstdv=D1.meanAndStandardDeviation(nPaths);           message=           "\nL1-APPROXIMATION:\n"+           "Approximation error L_"+j+"(T_"+j+")-L1_"+j+"(T_"+j+")\n"+           "mean: "+d1mstdv[0]+"\n"+           "standard deviation: "+d1mstdv[1];           System.out.println(message);           */                      System.out.println("Another run? (0/1)");           more=io.readInt();                      } // end main loop                  } // end main           } // end LogNormalLibor

⌨️ 快捷键说明

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