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

📄 bermudanswaption.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* 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*//* * BermudanSwaption.java * * Created on November 21, 2002, 21:09 PM */package Libor.LiborDerivatives;import Libor.LiborProcess.*;import Statistics.*;import Triggers.*;import LinAlg.*;import Graphics.*;/** <p>Bermudan Swaption. Limited functionality. Intended to support some  *  experiments. The underlying swap is assumed to end at the terminal *  date of the underlying Libor process.</p> *   * * @author  Michael J. Meyer */public class BermudanSwaption {     double kappa;        // strike        public int n,               // number of forward Libors            p;               // first date he swaption can be exercised double[] delta,      // delta[t]=T_{t+1}-T_t,length of compounding intervals          Tc,         // tenor structure, Tc[t]=T_t          x;          // initial X-Libors x[j]=X_j(0)=delta_jL_j(0)  /** the underlying Libor process*/LiborProcess LP;  // We precompute the matrices needed for the analytic prices of all swaptions // swpn_t(kappa,[T_q,T_n]), p<=t<q<n. ColtMatrix[][] CR;         /******************************************************************************                                                           ACCESSOR METHODS   *****************************************************************************/   /** Reference to the underlying Libor process.  */ public LiborProcess getLP(){ return LP; }  /** Swaption exercise begins T_p  */ public int getp(){ return p; }   /** Swaption strike  */ public double getKappa(){ return kappa; }   /******************************************************************************                                                           CONSTRUCTOR   *****************************************************************************/  /** <p>Constructor, underlying swap ends at the terminal date of the  *  underlying Libor process.</p>  *  * @param LP the underlying LiborProcess.  * @param p  first exercise date at <code>T_p</code>.  */ public BermudanSwaption(LiborProcess LP, int p, double kappa) {     this.LP=LP;     this.p=p;     this.kappa=kappa;          this.n=LP.dimension();     this.delta=LP.delta();     this.Tc=LP.tenorStructure();     this.x=LP.xInitial();          // the array of matrixes needed to compute analytic swaption prices     CR=new ColtMatrix[n-p][];     for(int j=p+1;j<n;j++){                  CR[j-p]=new ColtMatrix[j-p];         for(int t=p;t<j;t++){                          // matrix for swpn_t(kappa,[T_j,T_n])              // see Swaption.anaylticForwardPrice(int t), tau=j.             CR[j-p][t-p]=LP.logCovariationCholeskyRoot(j,n,Tc[t],Tc[j]);             CR[j-p][t-p].transposeSelf();         }     } } // end constructor/*******************************************************************************                    ANALYTIC EUROPEAN SWAPTION PRICES                                     *******************************************************************************/         /** <p>The weight <code>w^{p,q}_j(t)</code> in the representation of the       *  swap rate <code>S_pq(t)</code> as a convex combination of Libors.      *  See <i>LiborProcess.ps</i>.      *      * @param p swap begins      * @param q swap ends      * @param j Libor index in <code>[p,q)</code>.      * @param t current discrete time.      */     public double wpq(int p, int q, int j, int t)     {          double delta_j=LP.delta()[j];         return delta_j*LP.B(j+1,t)/LP.B_pq(p,q,t);     }                 /** <p>The vector <code>x_pq(t)</code> used in the computation of the      *  approximation of the volatility of the swap rate <code>S_pq</code>.       *  See <i>LiborProcess.ps</i>.</p>      *      * @param p swap begins      * @param q swap ends      * @param t current discrete time.      */     public ColtVector xpq(int p, int q, int t)     {          ColtVector x=new ColtVector(q-p);         for(int j=p;j<q;j++){                          double x_j=wpq(p,q,j,t)*LP.L(j,t);             x.setQuick(j-p,x_j);         }         return x;     } // end xpq                  /** <p>Analytic approximation to the price of the payer swaption    *  <code>swpn_t(kappa,[T_j,T_n])</code>.     *  See {@link Swaption#analyticForwardPrice}.     *  Correct only for <code>t<j</code>.</p>    *    * @param t current discrete time.    * @param j swap begins at T_j    */   public double swaptionAnalyticForwardPrice(int t, int j)   {       double S=LP.swapRate(j,n,t),              // S_jn(t)              Sigma,Nplus,Nminus;                                      // recall t<j implicit assumption, compute Sigma(t),       // see Swaption.Sigma(int t)      Sigma=(xpq(j,n,t).timesEquals(CR[j-p][t-p]).L2Norm())/S;                           // Black-Scholes swaption price      Nplus=FinMath.N(FinMath.d_plus(S,kappa,Sigma));      Nminus=FinMath.N(FinMath.d_minus(S,kappa,Sigma));          return LP.B_pq(j,n,t)*(S*Nplus-kappa*Nminus)/LP.B(n,t);     } //end analyticForwardPrice()     /*******************************************************************************                    ANALYTIC SWAP PRICES                                     *******************************************************************************/      /** <p>Analytic forward price of the payer swap    *  <code>swpn_t(kappa,[T_j,T_n])</code>.     *  See {@link Swap#analyticForwardPrice}.     *  Correct only for <code>t<j</code>.</p>    *    * @param t current discrete time.    * @param j swap begins at T_j    */   public double swapAnalyticForwardPrice(int t, int j)   {       double S=LP.swapRate(j,n,t);                            return LP.B_pq(j,n,t)*(S-kappa)/LP.B(n,t);      } //end analyticForwardPrice()                   /*******************************************************************************               PAYOFF AS MEMEBER FUNCTION AND AS RANDOM VARIABLE                                     *******************************************************************************/  /** Forward transported exercise payoff at time <code>t</code> computed from   *  the current Libor path.  *  * @param t time of exercise  */ public double currentForwardPayoff(int t) {     if(t<p) return 0;     double x=swapAnalyticForwardPrice(t,t);     return (x>0)? x : 0; }     /** The forward option payoff <code>h(rho_t)</code> based on a given    *  exercise strategy <code>rho=(rho_t)</code> computed from the current path   *  of the Libor process at time <code>t</code>, that is, the option has not   *  been exercised before time <code>t</code>. The current path is given up to    *  time <code>t</code>. From there the method computes a new path forward    *  until the time of exercise.</p>   *   *  <p>This is the quantity    *  <code>h(rho_t)</code> in the terminology of AmericanOption.tex.</p>   *   * @param t current time.   * @param exercise exercise strategy <code>rho=(rho_t)</code>.   */  public double currentForwardPayoff(int t, Trigger exercise) {          int s=LP.newPathSegment(t,exercise);     if(s==n)return 0;                          // exercise never triggered     return currentForwardPayoff(s);  } //end ForwardPayoff /** The forward option payoff based on a given exercise policy as a random   *  variable.  *

⌨️ 快捷键说明

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