📄 liborpaths.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*//* * PathPairs.java * * Created on September 2, 2002, 3:41 PM */package Examples.Libor;import Libor.LiborProcess.*;import Graphics.*;/** <p>Opens a window and allocates a Libor Process of dimension * <code>n=100</code> with time steps <code>delta_j=0.25</code>. * ie. a tenor structure of length 25 years.</p> * * <p>Whenever the window is clicked a new path of Libor <code>L_90</code> * and the corresponding log-Gaussian approximations <code>L0_90</code> * and <code>L1_90</code> are displayed. The idea is to see how well the * log-Gaussian approximations track true Libor.</p> * * <p>Unsurprisingly it is found that <code>L1</code> approximates Libor * better than <code>L0</code>. Noticeably divergence is seen only * after long time periods.</p> * * @author Michael J. Meyer */public class LiborPaths extends PathFrame{ // window parameters static final int w=600, h=350, xOffset=70, yOffset=70, mPath=3; static final double dt=0.25; // size of time step // Libor process setup static final int n=100, // dimension of Libor process i=90, // computing Libors L_i, L^0_i T=i-1; // time steps to horizon static final double[] path=new double[i+1]; // Libor parameter sample static final LMM_Parameters lmmParams=new LMM_Parameters(n,LMM_Parameters.CS); static final LiborProcess LP=new LiborProcess(lmmParams); static final double l0=LP.initialTermStructure()[i]; // L_i(0) int count; // counts the paths so we can cycle correctly // in groups of three /******************************************************************************* * * THE PATHS * ******************************************************************************/ /** Alternates between Libor and driftless Libor set at time * <code>t=T_11</code>. */ public double[] nextPath() { if(count==0){ LP.newPath(i,i,true,true,true); for(int t=0;t<=i;t++)path[t]=LP.L(i,t); count=1; } else if(count==1){ for(int t=0;t<=i;t++)path[t]=LP.L0(i,t); count=2; } else if(count==2){ for(int t=0;t<=i;t++)path[t]=LP.L1(i,t); count=0; } return path; } // end newPath /******************************************************************************* * * CONSTRUCTOR * ******************************************************************************/ /** Uses the static final parameter values since we don't intend * to alter these. */ public LiborPaths() { super("L_j (black), L0_j (red), L1_j (blue); "+ "j="+i+", n="+n+", delta_k=0.25", w,h,xOffset,yOffset,T,dt,l0,mPath); count=0; } /******************************************************************************* * * 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) { new LiborPaths().show(); } } // end PathPairs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -