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

📄 ep_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*//* * EP_FactorLoading.java * * Created on September 17, 2002, 10:31 PM */package Libor.LiborProcess;import LinAlg.*;/**<p>A factor loading with log-Libor volatilities of the form  * <code>sigma_j(t)=c_jg(1-t/T_j)</code> with <code>g(t)=1+Ah(t)</code>  * where <code>h(t)=t(1-t)</code> and correlations <code>rho_ij=b_i/b_j</code>,  * for </code>i&lt=j</code>, with <code>b_i=exp(beta*i^alpha)</code>.</p> * * <p>Here <code>A</code> is intended to be positive. The volatility then *  is humped, peaking halfway to the date Libor is set.</p> * * <p>This factor loading is used to generate the synthetic data we use to * calibrate the LMM based on a <code>CS_FactorLoading</code>.</p> * * @author  Michael J. Meyer */public class EP_FactorLoading extends FactorLoading {        /** Parameters describing the volatility and correlation structure     *  as described above.     *     */    double A,alpha,beta;        /** Array of factors <code>c_j</code> defining the volatilities      *  <code>sigma_j</code> as <code>sigma_j=c_jg(1-t/T_j)</code>.     *  See <i>LiborProcess.ps</i>.     */    double[] c;        /** 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 * *******************************************************************************/    /** The function <code>g(t)=1+Ah(t)</code>.     */    private double g(double t){ return 1+A*t*(1-t); }       //Integrals needed for the covariation integrals:        /** The integral <code>integral_t^T h(1-s/a)ds</code>.     */    private double integral_h(double t, double T, double a)    {         double f=1.0/a, g=f*f, T2=T*T, t2=t*t;        return f*(T2-t2)/2-g*(T*T2-t*t2)/3;    } //end integral_h            /** The integral <code>integral_t^T h(1-s/a)h(1-s/b)ds</code>.     */    private double integral_hh(double t, double T, double a, double b)    {        double T3=T*T*T, T4=T*T3, T5=T*T4,               t3=t*t*t, t4=t*t3, t5=t*t4,               ab=a*b, ab2=ab*ab;                return (T3-t3)/(3*ab)-(a+b)*(T4-t4)/(4*ab2)+(T5-t5)/(5*ab2);        } //end integral_hh            /** The integral <code>integral_t^T g(1-s/a)(1-s/b)ds</code>.     */    private double integral_gg(double t, double T, double a, double b)    {        double I_1=integral_h(t,T,a),               I_2=integral_h(t,T,b),               I_12=integral_hh(t,T,a,b);                return (T-t)+A*(I_1+I_2)+A*A*I_12;        } //end integral_gg              /******************************************************************************* * *                              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 L_0(t) is constant and so superfluous.     *     * @param n number of forward Libors including L_0.     * @param c array of c_j factors calibrating volatilities to caplet prices.     * @param Tc continuous time tenor structure (0=T_0,T_1,...,T_n).     */    public EP_FactorLoading    (int n, double A, double alpha, double beta, double[] c, double[] Tc)     {       super(n,Tc);              //System.out.print       //("\n\nAllocating volatility and correlation structure, time: ");       //double before, after, time;       //before=System.currentTimeMillis();              this.n=n;       this.A=A;       this.alpha=alpha;       this.beta=beta;       this.c=c;              // allocate and initialize the correlation base b[]=(b_1,...,b_{n-1})       // WARNING: <code>b[i]=b_{i+1}.       double[] b=new double[n-1];        for(int i=0;i<n-1;i++)       {            double x=Math.exp(alpha*Math.log(i+1));    // x=i^alpha           b[i]=Math.exp(beta*x);        }                         // 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++){ double q=b[j]/b[i]; rho[i][j]=q; rho[j][i]=q; }              // 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);       }               //after=System.currentTimeMillis();       //time=after-before;       //System.out.print(time+"\n");                 } // end constructor                /******************************************************************************* * *       VOLATILITIES, CORRELATIONS, COVARIATION INTEGRALS * *******************************************************************************/         /** Instantaneous log-Libor correlations. Note the index shift since    *  Libors L_i(t) start at i=1,2,...,n-1 while array indexing starts at     *  zero.    *    *@param i index of forward Libor L_i(t), <code>0&lt;i&lt;n</code>.    *@param j index of forward Libor L_j(t), <code>0&lt;j&lt;n</code>.    */   public double rho(int i, int j){ return rho[i-1][j-1]; }      /** Volatility sigma_i(t) of log(L_i(t)), defined on [0,T_i].    *    *@param i index of forward Libor L_i(t)    *@param t current <i>continuous</i> time.    */   public double sigma(int i, double t){ return c[i]*g(1-t/Tc[i]); }     /** The integral    *  <code>    *  &lt;log(L_i),log(L_j)&gt;_t^T=    *  int_t^T sigma_i(s)sigma_j(s)rho_ijds     *  </code><br>    *  neeeded for the distribution of time step increments.     *  See document LiborProcess.ps    *    *@param i index of forward Libor L_i(t)    *@param j index of forward Libor L_j(t)    */   public double    integral_sgi_sgj_rhoij(int i, int j, double t, double T)   {       return c[i]*c[j]*rho(i,j)*integral_gg(t,T,Tc[i],Tc[j]);    }/******************************************************************************* * *                         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, c_j=0.25, A=1.2, alpha=0.7, beta=0.4.     *  </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 EP_FactorLoading sample(int n)    {        double delta=0.25, A=1.2, alpha=0.7, beta=0.4;                double[] c=new double[n],                 Tc=new double[n+1];                for(int i=0;i<n;i++)   c[i]=0.25;         for(int i=0;i<n+1;i++) Tc[i]=i*delta;                 return new         EP_FactorLoading(n,A,alpha,beta,c,Tc);         } // end sample           /******************************************************************************* * *                         toString() * *******************************************************************************/                /** A message what type of factor loading it is, all the parameter values.     */    public String toString()    {        String stringRep=        "\nEP_FactorLoading:"+        "\nn="+n+", A="+A+", alpha="+alpha+", beta="+beta;        return stringRep;    }                        /******************************************************************************* * *                         TEST PROGRAM * *******************************************************************************/               /** Small test program. Allocates a factor loading of size    *  <code>n=50</code> to time the computation of the matrix arrays    *  (happens in the constructor). There is a separate class of     *  <code>junit</code> tests which tests the class more thoroughly.    */   public static void main(String[] args)   {         sample(50);   } // end main} // end CS_FactorLoading

⌨️ 快捷键说明

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