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

📄 callhedgehistogram.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*//* * CallHedgeHistogram.java * * Created on March 20, 2002, 9:18 PM */package Examples.Hedging;import Statistics.*;import Market.*;import Options.*;import Hedging.*;import Triggers.*;import com.skylit.io.EasyReader;/** <p>Histogram of hedge gains. *  A European call on a constant volatility asset is hedged using analytic  *  deltas. Hedge is rebalanced as soon as the asset price changes 10%. *  Computes and displays a histogram of the hedge gains and also of the  *  naked short in the call.</p> * *  <p>Console  *  program, no user interaction. All parameters fixed in source code.</p> * * @author Michael J. Meyer */public class CallHedgeHistogram {       public static void main(String[] args)   {            EasyReader io=new EasyReader();              double r=0,dt=0,S_0=0,mu=0,sigma=0,q=0,K=0,             fixed_trc=0, prop_trc=0;      int T=0, nPath=0, nBins=0, nBranch=0, nSignChange=5, triggerPercentage=0;             boolean done=false;      while(!done){          // main loop                        System.out.print          ("Call on one share of S with strike K will be\n"+           "priced and hegded.\n"+           "Histogram of hegde profit and loss will be displayed.\n\n"+           "Test data (0) or user defined data (1)?\n"+           "Enter choice: ");          int choice=io.readInt();                    if(choice==1){  // user dialogue                                // read S          System.out.print("Asset S:\n"+"S(0)=");          S_0=io.readDouble();          System.out.print("drift of returns=");          mu=io.readDouble();          System.out.print("instantaneous volatility of returns=");          sigma=io.readDouble();          System.out.print("Dividend yield=");          q=io.readDouble();          System.out.print("strike K=");          K=io.readDouble();          System.out.print("riskfree rate=");          r=io.readDouble();                                     System.out.print("\n\nSimulation:\n");          System.out.print("size of time step (years)=");          dt=io.readDouble();          System.out.print("number of time steps to expiry=");          T=io.readInt();          System.out.print("number of simulated price paths=");          nPath=io.readInt();          System.out.print          ("number of path branches per conditional expectation=");          nBranch=io.readInt();          System.out.print("number of histogram bins=");          nBins=io.readInt();                    System.out.print("\n\nHedge:\n");          System.out.print("Percent price change the hedge reacts to (1-50)=");          triggerPercentage=io.readInt();                             }          else {  // test data                   T=10;                   dt=0.05;                    S_0=21;                   mu=0.3;                   sigma=0.4;                   r=0.03;                   q=0.05;                                     K=25;                                  nPath=100000;                   nBranch=1000;                   nBins=100;                           // hedge                 triggerPercentage=7;                 fixed_trc=0.0;             // fixed transaction costs                 prop_trc=0.0;              // proportional transaction costs                    } // end else               // the underlying       ConstantVolatilityAsset       asset=new ConstantVolatilityAsset(T,dt,nSignChange,S_0,r,q,mu,sigma);              // the call        final BlackScholesCall call=new BlackScholesCall(K,asset);              // price cut off to 2 decimals       final double        price=FinMath.round(call.discountedAnalyticPrice(0),4);           // the trigger for the hedge trades:       TriggerAtPercentChange       percent_trigger=new TriggerAtPercentChange(asset,triggerPercentage);            // hedge with analytic deltas       Hedge hedge=new DeltaHedge       (asset,call,percent_trigger,Flag.A_DELTA,nBranch,fixed_trc,prop_trc);               // the discounted hedge gain       RandomVariable hedge_gain=hedge.discountedHedgeGain();              // payoff, naked short the call       RandomVariable naked_short=new RandomVariable(){                      public double getValue(int t)           {               return price-call.discountedPayoff().getValue(t);           }       }; // end naked_short                     // let the user know what's going on       double tau=T*dt;    // time to expiration       String message=       "Asset: mu="+mu+", sigma="+sigma+", q="+q+", r="+r+"\n"+       "Call: strike K="+K+", time to expiration tau="+tau+"\n"+       "Call price: "+price+"\n"+       "Hedge: analytic deltas, reacts to "+triggerPercentage+       "% price changes in the underlying.\n\n"+       "Computing histogram of hedge profit and loss (includes call premium).";              System.out.println(message);              // show the histogram        String title="Gains, call delta hede, call price: "+price,              filename="Pictures/Histograms/CallHedge/call-hedge.eps";       int ftype=Graphics.Flag.EPS;       hedge_gain.displayHistogram(nPath,nBins,true,title,"",filename,ftype);              message="Compare this to the unhedged position:";       System.out.println(message);        title="Gains, call naked short, call price: "+price;       filename="Pictures/Histograms/CallHedge/call-naked-short.eps";       naked_short.displayHistogram(nPath,nBins,true,title,"",filename,ftype);                     System.out.println       ("\n\nAnother run? Yes(1) No(0):\n"+"Enter choice:");       choice=io.readInt();       if(choice==0)done=true;              } // end main loop      } // end main} // end histogram

⌨️ 快捷键说明

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