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

📄 zerocouponbond.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*//* * ZeroCouponBond.java * * Created on September 6, 2002, 7:32 PM */package Libor.LiborDerivatives;import Libor.LiborProcess.*;import Statistics.*;/** <p>A zero coupon bond is the simplest example of a Libor derivative. *  The payoff is the constant random variable <code>1</code>. Zero coupon bond *  prices can also be computed directly from the Libors. In this way the  *  Zero coupon bond as a Libor derivative is a test case of a Libor  *  derivative with known analytic price. This can be used to validate *  model correctness, to see how well the log-normal Libor approximations *  work in the pricing of derivatives etc.</p> * * <p>Our implementation assumes that the bond matures at a Libor reset time * <code>T_i<code>.</p> * * @author  Michael J. Meyer */public class ZeroCouponBond extends LiborDerivative {        int i;         // bond matures at T_i        /******************************************************************************* * *                           CONSTRUCTOR * ******************************************************************************/           /**     * @param LP underlying Libor process.     * @param i bond matures at time <code>T_i</code>, must satisfy     * <code>0&lt;i&lt=n</code>.     */    public ZeroCouponBond(LiborProcess LP, int i)     {        // Libors needed to transport payoff 1 forward from time T_i        // to time T_n are L_j, j>=i and they are needed at time t=T_i.        super(LP,i,i,LP.X0LiborVector(i));        this.i=i;        super.controlVariateNeedsX0=false;    // no control variate implemented        super.controlVariateNeedsX1=false;             }    /******************************************************************************* * *                        FORWARD TRANSPORTED PAYOFF * ******************************************************************************/                   /** The payoff 1 at time <code>T_i</code> transported forward to time     *  <code>T_n</code>, value in current Libor path.     */    public double currentForwardPayoff()    {       double h=1;  // payoff at time T_i       // move this forward from time T_i to time T_n       return h*LP.forwardTransport(i);    }                /** <p>The forward transported payoff (as seen from time <code>t=0</code>)     *  computed from a new sample of the <code>LiborVector</code> object     *  <code>U=(X^0_i(T_i),...,X^0_{n-1}(T_i))</code>, a log-normal     *  approximating to the vector of true Libors     *  <code>U=(X_i(T_i),...,X_{n-1}(T_i))</code>.     *  Recall <code>X_j(t)=delta_jL_j(t)</code>, see document      *  <i>LiborProcess.ps</i>.</p>     */     public double lognormalForwardPayoffSample()     {          double[] U=LV.getValue(0);          double f=1;          // move this forward from time T_i to time T_n          // note index downshift j->j-i since U starts with X_i.          for(int j=i;j<n;j++)f*=1+U[j-i];                return f;     }         /******************************************************************************* * *                        ANALYTIC PRICE * ******************************************************************************/              /** Analytic <code>T_n</code>-forward price at time <code>t</code>.      *      * @param t current discrete time.      */     public double analyticForwardPrice(int t)     {         return LP.forwardTransport(t,i);     }                    /******************************************************************************* * *                                TEST PROGRAM * ******************************************************************************/        /** <p>Test program. Allocates a Libor process of dimension       *  <code>n=20</code> the zero coupon bond maturing at time       *  <code>T_10</code>.</p>       *      *  <p>Then computes the Monte Carlo forward price of this zero coupon bond       *  at time <code>T_n</code> and compares it to the analytic       *  price computed directly from the Libors and to the Monte Carlo price       *  based on the log-normal Libor approximation <code>X0</code>.       *  The forward transporting and discounting involves all Libors       *  <code>L_j, j&gt=10</code>.</p>      */     public static void main(String[] args)     {         // Libor process setup         int n=20,            // dimension of Libor process             i=10;            // bond matures at T_i              // Libor parameter sample        final LMM_Parameters lmmParams=new LMM_Parameters(n,LMM_Parameters.CS);       final LiborProcess LP=new LiborProcess(lmmParams);              final LiborDerivative H=new ZeroCouponBond(LP,i);              // all prices forward prices at time T_n       double aprice,                   // analytic price              mcprice,                  // Monte carlo price              lgnprice;                 // log-normal price              int nPath=40000;                 // number of Libor paths              System.out.println       ("\nZero coupon bond forward price, "+nPath+" paths:");       aprice=H.analyticForwardPrice(0);       mcprice=H.monteCarloForwardPrice(0,nPath);       lgnprice=H.lognormalMonteCarloForwardPrice(nPath);              aprice=FinMath.round(aprice,8);       mcprice=FinMath.round(mcprice,8);       lgnprice=FinMath.round(lgnprice,8);        String report=       "analytic: "+aprice+"\n"+       "Monte Carlo: "+mcprice+"\n"+       "lognormal Monte Carlo: "+lgnprice;       System.out.println(report);                   } // end main          } // end ZeroCouponBond

⌨️ 快捷键说明

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