📄 bondpaths.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*//* * BondPaths.java * * Created on September 3, 2002, 2:23 PM */package Examples.Libor;import Libor.LiborProcess.*;import Graphics.*;import com.skylit.io.EasyReader;/** <p>Opens a window, allocates a Libor Process of dimension <code>n=60</code> * with quarterly compounding and then displays zero coupon bond paths with * 300 time steps to maturity. The user defines the bond maturity.</p> * * <p>The apparent jumps in the bond price paths is an artifact created by the * way the program handles Libors at times <code>t</code> between Libor reset * points <code>T_j</code>. It uses Libor evaluated at the nearest reset point * and hence causing a jump as <code>t</code> crosses the midpoint of Libor * accrual intervals.</p> * * @author Michael J. Meyer */public class BondPaths extends PathFrame{ // window parameters static final int w=600, h=350, xOffset=70, yOffset=70, timeSteps=300, // number of time N=timeSteps+1, // length of path array n=60; // dimension of Liborprocess double step, // size of time step Tm; // time o maturity static final double[] path=new double[N]; LiborProcess LP; /******************************************************************************* * * THE PATHS * ******************************************************************************/ /** Alternates between Libor and driftless Libor set at time * <code>t=T_11</code>. */ public double[] nextPath() { LP.newPath(); for(int t=0;t<N;t++)path[t]=LP.B(t*step,Tm); return path; } // end newPath /******************************************************************************* * * CONSTRUCTOR * ******************************************************************************/ /** Some parameter values are needed for the super class constructor * (<code>T,B0</code>). * * @param LP the Libor process * @param T bond maturity * @param B0 bond value <code>B(0,T)</code> * @param dt size of time step (must be <code>T/timesteps=T/300</code>). * @param mPath number of paths displayed simultaneously. */ public BondPaths (LiborProcess LP, double T, double B0, double dt, int mPath) { super("Zero coupon bond B(t,"+T+") paths", w,h,xOffset,yOffset,timeSteps,dt,B0,mPath); this.LP=LP; Tm=T; step=Tm/timeSteps; } // end constructor /******************************************************************************* * * MAIN * ******************************************************************************/ /** Opens the window and displays a new path of Libor <code>L_75<code> * and the corresponding path of driftless Libor code>L^0_75<code> * whenever the window is clicked. */ public static void main(String[] args) { EasyReader io=new EasyReader(); System.out.print ("Displaying zero coupon bond paths.\n"+ "Choose maturity T (in years, must be <= 15): "); double T=io.readDouble(); double dt=T/N; // size of time step System.out.print ("How many paths should be displayed simultaneously: "); int mPath=io.readInt(); LMM_Parameters lmmParams=new LMM_Parameters(n,LMM_Parameters.CS); LiborProcess Libor=new LiborProcess(lmmParams); double B0=Libor.B(0.0,T); new BondPaths(Libor,T,B0,dt,mPath).show(); } // end main } // end PathPairs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -