📄 bermudanexerciseboundary.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*/package Libor.LiborDerivatives;import Libor.LiborProcess.*;import Statistics.*;import Triggers.*;import LinAlg.*;import Graphics.*; /** <p>A JFrame associated with a <code>BermudanSwaption</code> and a two * dimensional statistic (path functional) of the underlying Libor * path. The frame computes <code>nPaths</code> paths of the Libor process * and plots the points corresponding to the value of the statistic * colored saccording as the naive Bermudan exercise strategy does or does * not exercise at the respective Libor path at time <code>t</code></p>. * * <p>The objective is to discover a statistic which induces a nice * separation between the exercise and continuation region.</p> * * @author Michael J. Meyer */public abstract class BermudanExerciseBoundary extends PointFrame{ BermudanSwaption bswpn; LiborProcess LP; Trigger exercise; int t, // discrete time at which the statistic is computed p, // discrete time at which exercise begins n, // dimension of Libor process nPaths; // number of paths // parameters for the display window static final int // upper right corner of display rectangle x_offset=70, y_offset=70, // dimensions of display rectangle width=400, height=400; // a point (x,y) will be plotted only if xmin<x<xmax and // ymin<y<ymax final double xmin=0, xmax=0.15, ymin=0, ymax=0.15; /******************************************************************************* * * TWO DIMENSIONAL STATISTIC USED TO CHARACTERISE THE BOUNDARY * ******************************************************************************/ /** The value of the two dimensional statistic (Libor path functional) * computed from the current Libor path at time <code>t</code>. * This statistic will be plotted and the points colored according as * the naive Bermudan exercise strategy does or does not exercise at the * current Libor path at time <code>t</code>. The objective is to * discover a statistic which induces a nice separation between the * exercise and continuation region. */ public abstract double[] currentStatistic(); /******************************************************************************* * * THE ARRAY OF POINTS OF THE STATISTIC * ******************************************************************************/ /** Allocates and computes the array of points of the statistic colored * according to the exercise decision. */ public Point nextPoint() { LP.newPath(t,p); boolean excise=exercise.isTriggered(0,t); double[] stat=currentStatistic(); double x=stat[0], y=stat[1]; java.awt.Color color; if(excise)color=java.awt.Color.yellow; else color=java.awt.Color.black; return new Point(x,y,color); } // end computeExercisePoints /******************************************************************************* * * CONSTRUCTOR * ******************************************************************************/ /** Constructor */ public BermudanExerciseBoundary (String title, BermudanSwaption bswpn, Trigger exercise, int t, int nPaths, double xmin, double xmax, double ymin, double ymax) { // allocate the PointFrame but don't fill the point array yet super(title,600,600,50,50,xmin,xmax,ymin,ymax,nPaths,false); this.bswpn=bswpn; this.LP=bswpn.getLP(); this.exercise=exercise; this.t=t; this.p=bswpn.getp(); this.n=LP.dimension(); this.nPaths=nPaths; fillPoints(); } // end constructor /** Constructor, this one draws axes <code>x=x0</code>, <code>y=y0</code>. */ public BermudanExerciseBoundary (String title, BermudanSwaption bswpn, Trigger exercise, int t, int nPaths, double xmin, double xmax, double ymin, double ymax, double x0, double y0, java.awt.Color axesColor) { // allocate the PointFrame but don't fill the point array yet super(title,500,500,50,50,xmin,xmax,ymin,ymax,nPaths, false,x0,y0,axesColor); this.bswpn=bswpn; this.LP=bswpn.getLP(); this.exercise=exercise; this.t=t; this.p=bswpn.getp(); this.n=LP.dimension(); this.nPaths=nPaths; fillPoints(); } // end constructor /******************************************************************************* * * TEST PROGRAM * ******************************************************************************/ /** <p>Test program. Allocates a Libor process of dimension * <code>n=20</code> and a semiannual 10 non call 2 Bermudan swaption. * Then computes the exercise boundary from the naive exercise strategy * at time <code>t=8</code>.</p> */ public static void main(String[] args) { // Libor process setup final int n=20, p=4; final double kappa=0.04; // strike rate // Libor parameter sample final LMM_Parameters lmmParams=new LMM_Parameters(n,LMM_Parameters.JR); final LiborProcess LP=new LiborProcess(lmmParams); final BermudanSwaption bswpn=new BermudanSwaption(LP,p,kappa); final int nPath=10000, t=6; final boolean verbose=true; final Trigger pj=new PjTrigger(bswpn,nPath,verbose); final int nPaths=100000; final double xmin=0.02, xmax=0.09, ymin=0.02, ymax=0.09, x0=0.04, y0=0.04; final String title=n/2+" non call "+p/2+", boundary at t="+t/2+ ", x=f"+t+", y=S"+(t+1)+", "+xmin+"<x,y<"+xmax; System.out.println(title); final BermudanExerciseBoundary window=new BermudanExerciseBoundary (title,bswpn,pj,t,nPaths,xmin,xmax,ymin,ymax,x0,y0,java.awt.Color.red) { public double[] currentStatistic() { double x=(this.LP).L(this.t,this.t), y=(this.LP).swapRate(this.t+1,this.n,this.t); double[] z= {x,y}; return z; } }; // end window window.setVisible(true); final String filename="bdr.jpg"; window.saveAsJPEG(filename); } // end main } // end BermudanExerciseBoundary
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -