📄 callablereversefloater.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*//* * CallableReverseFloater.java * * Created on September 10, 2002, 6:11 PM */package Libor.LiborDerivatives;import Libor.LiborProcess.*;import Statistics.*;import Exceptions.*;import LinAlg.*;/** The callable reverse floater <code>CRF(p,q,K1,K2)</code> is simply * a call on the {@link ReverseFloater} <code>RF(p,q,K1,K2)</code> with zero * strike expiring at time <code>T_p</code>.</p> * * <p>This call is exercised precisely if the value of the reverse floater * at time <code>T_p</code> is positive and hence has payoff * <code>max(RF(T_p),0)</code> where <code>RF(T_p)</code> denotes the price * of the reverse floater at time <code>T_p</code>. * * @author Michael J. Meyer */public class CallableReverseFloater extends LiborDerivative { int p,q; //interval [T_p,T_q] double K1,K2; ReverseFloater RF; // the underlying reverse floater //LiborDerivative::T_max = T_p (check the control variate) //Liborderivative::k = p /******************************************************************************* * * CONSTRUCTOR * ******************************************************************************/ /** <p>Libors <code>L_j</code> needed for <code>j>=p</code> and until time * <code>T_p</code>.</p> * * @param LP underlying Libor process. * @param p accrual starts <code>T_p</code>. * @param q accrual stops <code>T_q</code>, with * <code>0<p<q<=n</code>. * @param K1 see {@link ReverseFloater}. * @param K2 see ReverseFloater. * */ public CallableReverseFloater (LiborProcess LP, int p, int q, double K1, double K2) { // Libors needed to transport payoff 1 forward from time T_i // to time T_n are L_j, j>=i and they are needed at time t=T_i. super(LP,p,p); this.p=p; this.q=q; this.K1=K1; this.K2=K2; RF=new ReverseFloater(LP,p,q,K1,K2); super.hasControlVariate=true; super.controlVariateNeedsX0=false; // no control variate implemented super.controlVariateNeedsX1=false; } /******************************************************************************* * * FORWARD TRANSPORTED PAYOFF * ******************************************************************************/ /** The payoff at time <code>T_p</code> is simply the price * transported forward to time * <code>T_n</code>, value in current Libor path. */ public double currentForwardPayoff() { return Math.max(RF.analyticForwardPrice(p),0); } /******************************************************************************* * * CONTROL VARIATE * ******************************************************************************/ /** Mean of the control variate conditioned on the state of the * Libor path at time <code>t</code>. This is simply * <code>(B_p(t)-B_q(t))/B_n(t)</code> * (a <code>P_n</code>-martingale). See <i>LiborProcess.ps</i>. * * @param t current discrete time <code>t<=p</code>. */ public double controlVariateMean(int t) { return LP.forwardTransport(t,p)-LP.forwardTransport(t,q); } /** Control variate is sum of forward transported Libors * <code>(B_p(T_p)-B_q(T_p))/B_n(T_p)(1-B_q(T_p))/B_n(T_p)</code>. * See <i>LiborProcess.ps</i> */ public double[] currentControlledForwardPayoff() { double h=currentForwardPayoff(), cv=LP.forwardTransport(p,p)-LP.forwardTransport(p,q); return new double[] {h,cv}; } /******************************************************************************* * * TEST PROGRAM * ******************************************************************************/ /** <p>Test program. Allocates a Libor process of dimension * <code>n=15</code> and prices calleable reverse floater * <code>CRF(p,q,K1,K2)</code> with * <code>p=5, q=15, K1=0.09, K2=0.03</code>. All Libors are intialized * at <code>L_j(0)=0.04</code>.</p> * * <p>Computes the Monte Carlo forward price of the calleable reverse * floater with and without control variates and the correlation of the * payoff to the control variate.</p> */ public static void main(String[] args) { // Libor process setup int n=15, // dimension of Libor process p=8, q=15; // accrual period [T_p,T_q] double K1=0.09, K2=0.03; // Libor parameter sample final LMM_Parameters lmmParams=new LMM_Parameters(n,LMM_Parameters.CS); final LiborProcess LP=new LiborProcess(lmmParams); final LiborDerivative crf=new CallableReverseFloater(LP,p,q,K1,K2); // all prices forward prices at time T_n double mcprice, // Monte carlo price cvmcprice; // Monte carlo price with control variate int nPath=40000; // number of Libor paths System.out.print ("\nCALLABLE REVERSE FLOATER: \n"+ "Correlation of payoff with control variate, "+nPath/4+" paths: "); double cvcorr=crf.controlledForwardPayoff(). correlationWithControlVariate(0,nPath/4); cvcorr=FinMath.round(cvcorr,4); System.out.print(cvcorr+"\n\nPrice, "+nPath+" paths:\n\n"); // move full Libor path to time t=T_3 LP.newPath(3,0); // all prices computed at time t=T_3 mcprice=crf.monteCarloForwardPrice(3,nPath); cvmcprice=crf.controlledMonteCarloForwardPrice(3,nPath); mcprice=FinMath.round(mcprice,8); cvmcprice=FinMath.round(cvmcprice,8); String report= "Monte Carlo: "+mcprice+"\n"+ "Controlled Monte Carlo: "+cvmcprice; System.out.println(report); } // end main } // end ReverseFloater
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -