📄 pjtriggerbase.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 following * Peter Jaeckel. 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 twop steps and composition is used.</p> * * @author Michael J. Meyer */public class PjTriggerBase { 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].... Libor X(t,t) // path[i][t-p][1].... swaprate S_{t+1,n}(t) // path[i][t-p][2].... forward swap payoff from immediate exercise (>=0) // path[i][t-p][3].... time s>=t of optimal exercise starting at time t // all compute from Libor sample path i, note index shift t->t-p to // get to zero based indices double[] S; // S[t-p]=S_{t+1,n}(0), swaprate /******************************************************************************* * * ACCESSORS * ******************************************************************************/ public double[][] getPath(int i){ return path[i]; } public int getnPath(){ return nPath; } public double[] getS(){ return S; } /******************************************************************************* * * CONSTRUCTOR * ******************************************************************************/ /** * @param bswpn the Bermudan swaption we want to exercise */ public PjTriggerBase(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[4]; } // initial swap rates S=new double[n-p-1]; for(int t=p;t<n-1;t++)S[t-p]=LP.swapRate(t+1,n); 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]=LP.L(t,t); path[i][t-p][1]=LP.swapRate(t+1,n,t); path[i][t-p][2]=bswpn.currentForwardPayoff(t); } // however for t=n-1 (no next swap rate) and we must set // the optimal exercise time s=t or s=t+1 (no exercise) int t=n-1; double f=LP.L(t,t); path[i][t-p][0]=f; path[i][t-p][2]=bswpn.currentForwardPayoff(t); if(f>kappa)path[i][t-p][3]=t; else path[i][t-p][3]=t+1; } // 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. * Will be called from <code>pjTrigger</code> constructor.</p> */ public boolean exercise(int i, int t, double[] x) { double f=path[i][t-p][0], sw=path[i][t-p][1], q=x[0]*S[t-p]/(sw-x[1])+x[2]; return ((f-x[2])*(sw-x[1])>x[0]*S[t-p])&&(sw>x[1])&& (path[i][t-p][2]>0); } } // end pjTriggerBase
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -