⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callmdeltahedge.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 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*//* * CallmDeltaHedge.java * * Created on March 20, 2002, 9:18 PM */package Examples.Hedging;import Statistics.*;import Market.*;import Options.*;import Hedging.*;import Triggers.*;import TradingStrategies.*;import IO.*;/** <p>Computes mean and standard deviation of call hedge P&L over a *  variety of strikes and maturities. Compares the performance of *  classical analytic deltas with analytic market deltas.  *  The hedge is rebalanced at each time step. Paths of the underlying are  *  simulated in the market probability. Output is written to the file *  "CallmDeltaHedge.txt".</p> * *  <p>Console  *  program, no user interaction. All parameters fixed in source code.</p> * * @author Michael J. Meyer */public class CallmDeltaHedge {       public static void main(String[] args)   throws java.io.IOException   {             // file writer to write in columns of fixed width w       final int w=35;                     // width of output columns       String fileName="CallmDeltaHedge.txt";          // output file       FixedFieldWidthFileWriter        fout=new FixedFieldWidthFileWriter(fileName,w);             int nSignChange=5, nBranch=10, nPaths=400000;              double S_0=50, mu=0.3, sigma=0.2, r=0.05, q=0.0, dt =0.05;       String str="S_0="+S_0+", mu="+mu+", sigma="+sigma+", r="+r+", dt="+dt;       fout.write(str+"\n\n\n");              fout.writeField("Time to expiry",20);       fout.writeField("Strike",10);       fout.writeField("deltas: mean",14);       fout.writeField("amDeltas: mean",17);       fout.writeField("deltas: stdv",14);       fout.writeField("amDeltas: stdv",17);       fout.write("\n\n\n");       for(int T=2;T<6;T+=1)       for(double K=40;K<71;K+=10){                      System.out.println("N="+T+", K="+K);                      double Tc=FinMath.round(T*dt,3);        // time to expiry                      // the underlying, nSignChange=8           final ConstantVolatilityAsset           asset=new ConstantVolatilityAsset(T,dt,8,S_0,r,q,mu,sigma);                     // the call            final BlackScholesCall call=new BlackScholesCall(K,asset);                      // hedge with analytic market deltas, transaction costs = 0           RandomVariable amDeltaHedge=call.discountedHedgeGain           (call.ANALYTIC_MINIMUM_VARIANCE_DELTA,            Flag.MARKET_PROBABILITY,nBranch,0,0);                      // hedge with analytic deltas, transaction costs = 0            RandomVariable deltaHedge=call.discountedHedgeGain           (call.ANALYTIC_DELTA,Flag.MARKET_PROBABILITY,nBranch,0,0);                 // the discounted hedge gain           double[]  deltaHedgeSTATS=                     deltaHedge.meanAndStandardDeviation(nPaths),                     amDeltaHedgeSTATS=                     amDeltaHedge.meanAndStandardDeviation(nPaths);                      double  deltaHedgeMEAN=deltaHedgeSTATS[0],                   deltaHedgeSTDV=deltaHedgeSTATS[1],                   amDeltaHedgeMEAN=amDeltaHedgeSTATS[0],                   amDeltaHedgeSTDV=amDeltaHedgeSTATS[1];                      deltaHedgeMEAN=FinMath.round(deltaHedgeMEAN,4);           deltaHedgeSTDV=FinMath.round(deltaHedgeSTDV,4);           amDeltaHedgeMEAN=FinMath.round(amDeltaHedgeMEAN,4);           amDeltaHedgeSTDV=FinMath.round(amDeltaHedgeSTDV,4);                      fout.writeField("  T="+Tc+",",20);           fout.writeField("K="+K+",",10);           fout.writeField(" "+deltaHedgeMEAN,14);           fout.writeField(" "+amDeltaHedgeMEAN,17);           fout.writeField(" "+deltaHedgeSTDV,14);           fout.writeField(" "+amDeltaHedgeSTDV,17);           fout.write("\n");           if(K==70)fout.write("\n\n");             } // for T             fout.close();      System.out.println      ("Finished, results in file CallmDeltaHedge.txt");      } // end main} // end CallHedgeVariance

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -