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

📄 liborvector.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*//* * LiborVector.java * * Created on September 9, 2002, 12:49 PM */package Libor.LiborProcess;import Statistics.*;/** <p>The {@link Statistics.RandomVector} of Libors  *  <code>U=(X_m(T_m),X_{m+1}(T_m),...,X_{n-1}(T_m))</code> as seen from time  *  <code>t=0</code>, ie. a snapshot of the Libors <code>L_j, j&gt;=m</code>  *  at time <code>T_m</code>.</p> *  *  <p>No conditioning on information available at time <code>t</code>. *  Time <code>t</code> is ignored. *  Useful only for pricing at time <code>t=0</code>.</p> * * <p>The idea is that many Libor derivatives depend only on such a vector *  and that direct simulation of this vector is much faster than computation *  of Libor paths.</p> * * <p>Unfortunately the only way to compute this vector accurately is to  * derive it from Libor paths which is exactly what we want to avoid. * Fortunately there are log-Gaussian <i>approximations</i> to this vector * (the vector of logarithms <code>log(X_j(T_j))</code> is multinormal) * with known mean and covariance matrix which can be simulated directly.</p> * * <p>This class provides the basic interface to such a vector and implements * many methods associated with a LiborProcess (such as zero coupon bonds, * swap rates,...) now derived from the vector <code>U</code> instead of true  * Libor. This allows for fast approximate valuation of Libor derivatives * which depend only on the vecor <code>U</code>.</p> * * <p>A Libor process has methods to compute associated (approximate) * Libor vectors based on either the <code>X0</code> or <code>X1</code> * approximation to true Libor and each Libor derivative maintains a reference * to both an underlying Libor process and associated Libor vector.</p> * * <p>Note: obvioulsy there a large number of other vectors of Libors * which one might need. The current vector <code>this</code> is useful * in the pricing of zero coupon bonds (test case) and swaptions. * Other vectors can be implemented similarly.</p> * * @author  Michael J. Meyer */public abstract class LiborVector extends RandomVector {            int m,               // Libors L_j, j>=m, at time T_m        n;               // dimension of underlying Libor process            double[] U;          // U[j-m]=X_j(T_m), j>=m.        LiborProcess LP;     // reference to the underlying Libor process        double[] x,          // intial term structure x[j]=X_j(0)             delta;      // delta[j]=delta_j length of accrual intervals                     /******************************************************************************* * *                         CONSTRUCTOR * ******************************************************************************/            /** <p>The approximation to true Libor is either <code>X0</code> or     *  <code>X1</code> (see <i>LiborProcess.ps</i>). At present only     *  <code>X0</code> is supported and specification of approximation type      *  <code>X1</code> defaults to type <code>X0</code>.</p>     *     * <p>Not intended to be instantiated directly. <code>LiborVectors</code>     * are returned by methods of the class <code>LiborProcess</code>.</p>     *     * @param LP underlying Libor process.     * @param m Libors <code>X_j(T_m), j>=m</code>.     */    public LiborVector(LiborProcess LP, int m)    {           super(LP.dimension()-m);         this.m=m;        n=LP.dimension();        U=new double[dim()];         // super.dim()        this.LP=LP;        x=LP.xInitial();        U[0]=x[0];                   // X_0(T_0) is constant.        delta=LP.delta();    }    /******************************************************************************* * *                          SAMPLING * ******************************************************************************/             // It is more economical to write samples into U and retrieve them from     // there rather than go directly through the method getValue(t).          /** <p>No conditioning on information available at time <code>t</code>.      *  The time parameter is ignored.</p>      *      * @param t discrete time, ignored.      */     public double[] getValue(int t)     {         nextSample();   // write next sample into U.         return U;     }     /** Writes the next random sample of the vector of (approximate) Libors       *  <code>U=(X_m(T_m),X_{m+1}(T_m),...,X_{n-1}(T_m))</code> into the array      *  <code>this.X</code>.       */     public abstract void nextSample();    /******************************************************************************* * *             FUNCTIONALS ASSOCIATED WITH THE LIBOR VECTOR * ******************************************************************************/                 // duplicates the basic methods in the class LiborProcess but     // everything is based on the (approximate) X-Libors in the vector     // X instead of true Libors.     // Obviously functionals can only be evaluated at time t=0 or t=T.               /******************************************************************************* * *                          ZERO COUPON BONDS  * ******************************************************************************/             /** The zero coupon bond <code>B_i(0)=B(0,T_i)</code>.     *       * @param i bond matures at time <code>T_i<code>     */     public double B_i0(int i)     {          double f=1;         // accumulate 1 from time t=0 to time t=T_i                             for(int j=0;j<i;j++)f*=(1+x[j]);          return 1/f;                                 // B_i(0)=1/f       }        /** The zero coupon bond <code>B_i(T_m)</code>.     *     *  @param i bond matures at time <code>T_i</code>,      *  must satisfy <code>T&lt=i</code>.     */    public double B_iTm(int i)    {             double f=1;             // accumulate 1 forward from time t to time i, U[k]=X_k(T)        for(int k=m;k<i;k++)f*=(1+U[k-m]);         return 1/f;                                 // B_i(T_t)=1/f      }              /** <p>Accrual factor <code>1/B(T_m,T_n)=1/B(n,m)</code>. This factor shifts     *  a cashflow from time <code>T_m</code> to the horizon <code>T_n</code>     *  with Libors in state at time <code>T_m</code>.</p>     *       */     public double forwardTransport()     {          double f=1.0;         for(int j=m;j<n;j++)f*=(1+U[j-m]);         return f;     }           /******************************************************************************* * *                        FORWARD SWAP RATES * ******************************************************************************/                                         /** <p>The forward swap rate <code>S_pq(t)=k(t,[T_p,T_q])</code> at     *  discrete time <code>t=T_m</code>.</p>    *    * @param p swap begins at <code>T_p</code>,     * must satisfy <code>m&lt;=p</code>    * @param q swap ends at <code>T_q</code> (settled).    */      public double S_pqTm(int p, int q)     {         double f=1+U[q-1-m], S=delta[q-1];        for(int k=q-2;k>=p;k--){ S+=delta[k]*f; f*=(1+U[k-m]); }         return (f-1)/S;     } //end Swap_Rate   /** <p>The forward swap rate <code>S_pq(t)=k(t,[T_p,T_q])</code> at time     *  <code>t=0</code>.</p>    *    * @param p swap begins at <code>T_p</code>.    * @param q swap ends at <code>T_q</code> (settled).    */      public double S_pq0(int p, int q)     {         double f=1+x[q-1], S=delta[q-1];        for(int k=q-2;k>=p;k--){ S+=delta[k]*f; f*=(1+x[k]); }         return (f-1)/S;     } //end Swap_Rate     /******************************************************************************* * *                         ANNUITY NUMERAIRE * ******************************************************************************/                                      /** <p>The annuity <code>B_pq(t)=sum_{k=p}^{q-1}delta_kB_{k+1}(t)</code>.    *  at time <code>t=T_m</code>.</p>    *    * @param p annuity begins at <code>T_p</code>.    * @param q annuity ends at <code>T_q</code> (settled).    */      public double B_pqTm(int p, int q)     {          double S=0, F=B_iTm(q);         for(int k=q-1;k>=p;k--){ S+=delta[k]*F; F*=(1+U[k-m]); }         return S;     } //end B_pq        /** <p>The annuity <code>B_pq(t)=sum_{k=p}^{q-1}delta_kB_{k+1}(t)</code>    *  at time <code>t=0</code>.    *  </p>    *    * @param p annuity begins at <code>T_p</code>.    * @param q annuity ends at <code>T_q</code> (settled).    */      public double B_pq0(int p, int q)     {          double S=0, F=B_i0(q);         for(int k=q-1;k>=p;k--){ S+=delta[k]*F; F*=(1+x[k]); }         return S;     } //end B_pq        } // end LiborVector

⌨️ 快捷键说明

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