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

📄 callhedgevariance.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* 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*//* * CallHedgeVariance.java * * Created on September 29, 2002, 1:18 PM */package Examples.Hedging;import Statistics.*;import Market.*;import Options.*;import Hedging.*;import Triggers.*;import IO.*;/** <p>Disregard. *  Contains methods to compute various functionals and expectations  *  connected with the analysis of the variance of the outcome of delta hedging *  the European call. The hedge is rebalanced at regular time intervals *  (at each time step). For details see the document <code>Variance.tex</code>. *  </p> * *  <p>Console  *  program, no user interaction. All parameters fixed in source code.</p> * * @author Michael J. Meyer */public class CallHedgeVariance {            static final double twoPi=6.28319,                        pi=3.14159;        int T;    double S_0, sigma, r, dt, K;        // allocate with mu=r so market probability is risk neutral    // (hedges compute statistics only in the market probability)    ConstantVolatilityAsset asset;        BlackScholesCall call;    Hedge callHedge;    Trigger rebalance;        // constants used in the hedge variance analysis    public double  sg2dt,       // sigma^2dt                   f,F,L;            /******************************************************************************* * *                              CONSTRUCTOR * ******************************************************************************/              /** Creates a new instance of CallHedgeVariance */    public CallHedgeVariance    (double S_0, double sigma, double r, int T, double dt, double K)     {        this.S_0=S_0;        this.sigma=sigma;        this.r=r;        this.T=T;        this.dt=dt;        this.K=K;        int nSignChange=1;        double q=0.0;        double mu=r;                // market probability is risk neutral        asset=new ConstantVolatilityAsset(T,dt,nSignChange,S_0,r,0.0,mu,sigma);        call=new BlackScholesCall(K,asset);        rebalance=new TriggerAtEachTimeStep(T);        callHedge=new DeltaHedge(asset,call,rebalance,Flag.A_DELTA,0,0,0);                // initialize the constants F,L        sg2dt=sigma*sigma*dt;        f=(Math.exp(6*sg2dt)-1)/6-2*(Math.exp(3*sg2dt)-1)/3+(Math.exp(sg2dt)-1);                L=Math.log(S_0/K)+(r*dt-0.5*sg2dt)*T;        F=f*K*K/(twoPi*sg2dt*Math.exp(2*r*T*dt));                     } // end constructor       /******************************************************************************* * *                 Some Asset Path Functionals * ******************************************************************************/            public double d_plus(int t)    {        double[] S=asset.get_S();        double Sigma=sigma*Math.sqrt((T-t)*dt);                return (Math.log(S[t]/K)+r*T*dt)/Sigma+Sigma/2;    }              public double d_minus(int t)    {        double[] S=asset.get_S();        double Sigma=sigma*Math.sqrt((T-t)*dt);                return (Math.log(S[t]/K)+r*T*dt)/Sigma-Sigma/2;    }            /** <code>F_1(t)</code> , see VarTemp.tex.     */     public RandomVariable F1(final int t)    {        return new RandomVariable(){                        public double getValue(int s)            {                asset.newPath(Flag.MARKET_PROBABILITY);                double St=asset.get_S()[t],                       dp=d_plus(t),                       dm=d_minus(t);                                       return dm*dm*Math.exp(-dp*dp)*St*St;            }        }; // end return new    } // end F1                /** <code>F_1(t)</code> , see VarTemp.tex.     */     public RandomVariable F2(final int t)    {        return new RandomVariable(){                        public double getValue(int s)            {                asset.newPath(Flag.MARKET_PROBABILITY);                double St=asset.get_S()[t],                       dp=d_plus(t),                       dm=d_minus(t);                                       return dm*Math.exp(-dp*dp)*St*St;            }        }; // end return new    } // end F2            /** <code>F_3(t)</code> , see VarTemp.tex.     */     public RandomVariable F3(final int t)    {        return new RandomVariable(){                        public double getValue(int s)            {                asset.newPath(Flag.MARKET_PROBABILITY);                double St=asset.get_S()[t],                       dp=d_plus(t);                                       return Math.exp(-dp*dp)*St*St;            }        }; // end return new    } // end F3                  /** Analytic mean of <code>F1</code>.     *     */     public double meanF1(int t)    {        double Tc=T*dt, tc=t*dt,                sg2=sigma*sigma,               H=Math.sqrt((Tc-tc))*K*K*Math.exp(-2*r*Tc-L*L/(sg2*(Tc+tc)))/                 Math.sqrt((Tc+tc)),               Q=(L*L*(Tc-tc)+sg2*tc*(Tc+tc))/(sg2*(Tc+tc)*(Tc+tc));                return H*Q;    } // end meanF1            /** Analytic mean of <code>F2</code>.     *     */     public double meanF2(int t)    {        double Tc=T*dt, tc=t*dt,                sg2=sigma*sigma,               H=Math.sqrt((Tc-tc))*K*K*Math.exp(-2*r*Tc-L*L/(sg2*(Tc+tc)))/                 Math.sqrt((Tc+tc)),               Q=L*Math.sqrt((Tc-tc))/(sigma*(Tc+tc));                return H*Q;    } // end meanF2            /** Analytic mean of <code>F3</code>.     */     public double meanF3(int t)    {        double Tc=T*dt, tc=t*dt,                sg2=sigma*sigma,               H=Math.sqrt((Tc-tc))*K*K*Math.exp(-2*r*Tc-L*L/(sg2*(Tc+tc)))/                 Math.sqrt((Tc+tc));                return H;    } // end meanF1                /** The function <code>Q(t)</code>. , see VarTemp.tex.     */     public double Q(int t)    {        double Tc=T*dt, tc=t*dt, sg2=sigma*sigma, Q1,Q2,Q3;                Q1=L*L*(Tc-tc)+sg2*(Tc+tc);        Q1/=(Tc*Tc-tc*tc)*(Tc*Tc-tc*tc);        Q1*=sg2dt*dt*dt/(12*pi);                Q2=L/(Tc*Tc-tc*tc);        Q2*=-5*sg2dt*dt*dt/(6*pi);                Q3=1.0/(Tc-tc);        Q3*=sg2dt*dt/(4*pi);                return Q1+Q2+Q3;    } // end Q                /** The function <code>H(t)</code>. , see VarTemp.tex.     */     public double H(int t)    {        double Tc=T*dt, tc=t*dt, h;                h=Math.sqrt(Tc-tc)/Math.sqrt(Tc+tc);        h*=K*K*Math.exp(-2*r*Tc-L*L/(sg2dt*(T+t)));                return h;    } // end H                /** The analytic approximation to the variance of the call delta hedge.     *  The hedge is rebalanced at each time step. See     *  <code>Variance.tex</code>     */       public double callDeltaHedgeAnalyticVariance()    {        double sum=0;

⌨️ 快捷键说明

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