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

📄 jr_factorloading.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*//* * JR_FactorLoading.java * * Created on November 20, 2002, 3:11 PM */package Libor.LiborProcess;import LinAlg.*;import Statistics.Random;/** Implements the correlation and volatility structure from Jaeckel's book *  <i>Monte Carlo Methods in Finance</i>.  * * @author Michael J. Meyer */public class JR_FactorLoading extends FactorLoading {            /** Parameters describing the volatility and correlation structure.     *     */    double a,b,c,d;    static double beta=0.1;        /** Array of factors <code>k_j</code> defining the volatilities      *  <code>sigma_j</code> as <code>sigma_j=k_jg(1-t/T_j)</code>.     *  See <i>LiborProcess.ps</i>.     */    double[] k;        /** The matrix of instantaneous log-Libor correlations.     *  Warning <code>rho[i][j]=rho_{i+1,j+1}</code> since the Libors     *  <code>L_i(t)</code> start at i=1,2,... but array indexing starts at     *  zero.     */    double[][] rho;              /******************************************************************************* * *                           THE CORRELATION MATRIX * ******************************************************************************/       /** Accessor to correlation matrix <code>rho[][]</code>.    *  WARNING: <code>rho[i][j]=rho_{i+1,j+1}</code> because we do not    *  store the correlations <code>rho_{0,j}</code>.    */    public double[][] getRho(){ return rho; }      /** The correlation matrix <code>rho_ij</code> as a <code>ColtMatrix</code>.    *  See <i>LiborProcess.ps</i>. Used for testing purposes only.    */   public ColtMatrix correlationMatrix(){ return new ColtMatrix(rho); }        /******************************************************************************* * *                      AUXILLIARY FUNCTIONS * *******************************************************************************/    /** Correlation rho_ij, applies to j<=i only!     */    double corr(int i, int j){ return Math.exp(beta*(Tc[j]-Tc[i])); }            /** Indefinite integral      *  <code>\int\sigma_i(t)\sigma_j(t)\rho_{ij}(t)dt</code>     */   double Fij(int i, int j, double t)   {       double f,A,B,C,              ctmti=c*(t-Tc[i]),              ctmtj=c*(t-Tc[j]),              timtj=Math.abs(Tc[i]-Tc[j]),              q=ctmti+ctmtj,                    // c(2t-ti-tj)              ac=a*c,              ad=a*d,              cd=c*d,              bcd=b*c*d;                     f=k[i]*k[j]*Math.exp(-beta*timtj)/(c*c*c);       A=ac*cd*(Math.exp(ctmtj)+Math.exp(ctmti))+c*cd*cd*t;       B=bcd*(Math.exp(ctmti)*(ctmti-1)+Math.exp(ctmtj)*(ctmtj-1));       C=Math.exp(q)*(ac*(ac+b*(1-q))+b*b*(0.5*(1-q)+ctmti*ctmtj))/2;              return f*(A-B+C);   } // end Fij        /******************************************************************************* * *                              CONSTRUCTOR * *******************************************************************************/                /** For the meaning of the parameters A,D,alpha,beta,rho00 see      *  <i>LiborProcess.ps</i>. Parameter array <code>c[ ]</code> starts with     *  <code>c[0]=c_0</code> even though <code>L_0(t)</code> is constant and      *  so superfluous.     *     * @param n number of forward Libors including <code>L_0</code>.     * @param c array of <code>c_j</code> factors calibrating volatilities to      * caplet prices.     * @param Tc continuous time tenor structure      * <code>(0=T_0,T_1,...,T_n)</code>.     */    public JR_FactorLoading    (int n, double a, double b, double c, double d, double[] k, double[] Tc)     {       super(n,Tc);              this.n=n;       this.a=a;       this.b=b;       this.c=c;       this.d=d;       this.k=k;                     // allocate and initialize the correlation matrix        // rho=(rho_ij)_{i.j=1}^{n-1}       // WARNING:  rho[i][j]=rho_{i+1,j+1}       rho=new double[n-1][n-1];       for(int i=0;i<n-1;i++)       for(int j=0;j<=i;j++)       { rho[i][j]=corr(i+1,j+1); rho[j][i]=rho[i][j]; }                  // initialize the matrix arrays super.covariationMatrices and       // super.choleskyRoots.       for(int t=0;t<n-1;t++)       {           ColtMatrix cv_t=logCovariationMatrix(t),                      cr_t=cv_t.choleskyRoot();           covariationMatrices.initialize(t,cv_t);           choleskyRoots.initialize(t,cr_t);       }           } // end constructor                /******************************************************************************* * *       VOLATILITIES, CORRELATIONS, COVARIATION INTEGRALS * *******************************************************************************/         /** <p>Instantaneous log-Libor correlations <code>rho_ij</code>    *  for <code>i,j&gt=1</code>.</p>    *    *@param i index of L_i(t), must satisfy <code>i&gt=1</code>.    *@param j index of L_j(t), must satisfy <code>j&gt=1</code>.    */   public double rho(int i, int j){ return rho[i-1][j-1]; }      /** Volatility <code>sigma_i(t)</code> of <code>log(L_i(t))</code>,     *  defined on <code>[0,T_i]</code>.    *    *@param i index of forward Libor <code>L_i(t)</code>.    *@param t current <i>continuous</i> time.    */   public double sigma(int i, double t)   {        double s=(Tc[i]-t);       return k[i]*((a+b*s)*Math.exp(-c*s)+d);   }     /** The integral<br>    *  <code>    *  integral_t^T sigma_i(s)sigma_j(s)rho_ijds       =&lt;log(L_i),log(L_j)&gt;_t^T     *  </code><br>    *  neeeded for the distribution of time step increments.     *  See document LiborProcess.ps    *    *@param i index of forward Libor <code>L_i(t)</code>.    *@param j index of forward Libor <code>L_j(t)</code>.    */   public double    integral_sgi_sgj_rhoij(int i, int j, double t, double T)   {      return Fij(i,j,T)-Fij(i,j,t);   }/******************************************************************************* * *                         SAMPLE FACTOR LOADING * *******************************************************************************/          /** <p>Provides a sample <code>CS_FactorLoading</code> object of dimension     *  <code>n</code>. Parameter values are as follows:</p>     *  <p>     *  <center>     *  <code>     *  delta_j=0.25, k_j=0.25, a=1.3, b=2, c=0.5, d=1.0, beta=0.01.     *  </code>     *  </center>     *  </p>     * <p>This choice implies annualized Libor volatilities of about 33%     * and a humped volatility peaking halfway out to the reset date.</p>     *      * @param n dimension of the Libor process     */    public static JR_FactorLoading sample(int n)    {        double delta=0.5, a=-0.05, b=0.5, c=1.5, d=0.15, beta=0.1;                double[] k=new double[n],                 Tc=new double[n+1];                for(int i=0;i<n;i++)   k[i]=1.0;         for(int i=0;i<n+1;i++) Tc[i]=i*delta;                 return new         JR_FactorLoading(n,a,b,c,d,k,Tc);         } // end sample           /******************************************************************************* * *                         toString() * *******************************************************************************/                /** A message what type of factor loading it is, all the parameter values.     */    public String toString()    {        String stringRep=        "\nJR_FactorLoading:"+        "\nn="+n+", a="+a+", b="+b+", c="+c+", d="+d+", beta="+beta+        ", k_i="+k[0];        return stringRep;    }                       /******************************************************************************* * *                         TEST PROGRAM * *******************************************************************************/               /** Small test program. Allocates a JR factor loading of size    *  <code>n=20</code> and prints the Libor volatilities.    */    public static void main(String[] args)    {         // Libor process setup         int n=20;            // caps Libor on  [T_i,T_{i+1}]                  FactorLoading factorLoading=JR_FactorLoading.sample(n);         for(int j=1;j<n;j++){                      double T=j*0.5,                    vol=factorLoading.integral_sgi_sgj_rhoij(j,j,0,T);             vol=Math.sqrt(vol/T);                          String report="vol_"+j+" = "+vol;             System.out.println(report);         }                   } // end main       } // end CS_FactorLoading

⌨️ 快捷键说明

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