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

📄 cvxtriggerbase.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/* * pjTrigger.java * * Created on November 27, 2002, 11:47 PM */package Libor.LiborDerivatives;import Libor.LiborProcess.*;import Triggers.*;import Optimizers.*;import LinAlg.*;/** <p>Base for an exercise trigger of a Bermudan swaption using convex  *  deformation of the pure continuation region (see AmericanOptions.tex).  *  A completed object of this type is needed for the *  construction of the whole trigger and that's why the construction *  process is split into two steps and composition is used.</p> * * @author  Michael J. Meyer */public class CvxTriggerBase {       static final double EPS=0.0000000001,                       bSCALE=2;           // scaling factor for beta       LiborProcess LP;   BermudanSwaption bswpn;      double kappa;   // swaption strike      int nPath,      // number of training paths       p,          // swaption exercise begins T_p       n;          // swap ends T_n (dimension of Libor process)      double[][][] path;         // path[i][t-p][0,1,2] are as follows:   // path[i][t-p][0].... h_t, forward payoff from exercise at time t   // path[i][t-p][1].... Q(t)=max{ E_t(h_j) : j>t }, most expensive European   // path[i][t-p][2].... optimal exercise time s>=t   // all computed from Libor sample path i, note index shift t->t-p to    // get to zero based indices      double[] alpha,       // Q(t) exponent            beta;        // scaling factor          /******************************************************************************* * *                      ACCESSORS * ******************************************************************************/   public double[][] getPath(int i){ return path[i]; }   public int getnPath(){ return nPath; }   public double getbScale(){ return bSCALE; }   /******************************************************************************* * *                       CONSTRUCTOR * ******************************************************************************/       /**      * @param bswpn the Bermudan swaption we want to exercise     */    public CvxTriggerBase(BermudanSwaption bswpn, int nPath)     {        this.bswpn=bswpn;        this.nPath=nPath;        kappa=bswpn.getKappa();        LP=bswpn.getLP();        p=bswpn.getp();        n=LP.dimension();                path=new double[nPath][][];        for(int i=0; i<nPath; i++){                        path[i]=new double[n-p][];            for(int t=p; t<n; t++) path[i][t-p]=new double[3];        }                fillPaths();            } // end constructor        /******************************************************************************* * *                RELEVANT INFORMATION FROM TRAINING PATHS * ******************************************************************************/       /** <p>Fills the training path arrays with all information necessary to     *  decide exercise and compute the coefficients. Alone the flags      *  <code>path[i][t-p][3]</code> indicating exercise under the optimized      *  parameters are computed in the subclass constructor where these      *  parameters are computed.</p>     *     */    private void fillPaths()    {        for(int i=0; i<nPath; i++){                        LP.newPath(n-1,p);            for(int t=p;t<n-1;t++){                                  path[i][t-p][0]=bswpn.currentForwardPayoff(t);                path[i][t-p][1]=bswpn.Q(t);                // flags path[i][t-p][2] will be set later            }             // however for t=n-1 (no Q(t)) and we must set            // the exercise time starting from time t            int t=n-1;            double f=LP.L(t,t);            path[i][t-p][0]=bswpn.currentForwardPayoff(t);            path[i][t-p][1]=0;            // exercise time            if(f>kappa)path[i][t-p][2]=t;   // exercise now            else path[i][t-p][2]=t+1;       // no exercise        } // end i     } // end fillPaths    /******************************************************************************* * *                RELEVANT INFORMATION FROM TRAINING PATHS * ******************************************************************************/                 /** <p>True if the exercise condition is met under coefficients      *  <code>x</code> at time <code>t</code>  along training path      *  <code>i</code>, false otherwise. Exercises only if payoff>0.</p>     */    public boolean exercise(int i, int t, double[] x)    {        double alpha=x[0],                beta=Math.abs(bSCALE*x[1])+EPS,               h=path[i][t-p][0],          // payoff h_t on path i               q=path[i][t-p][1]/beta;     // Q(t)               q=Math.log(q);               q*=alpha;               q=Math.exp(q);               q*=beta;                    // beta*(Q(t)/beta)^alpha        return (h>q);    }    }  // end pjTriggerBase

⌨️ 快捷键说明

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