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

📄 callcontrolvariatetest.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*//* * ControllVariateTest_2.java * * Created on March 9, 2002, 2:32 PM */package Examples.ControlVariates;import Statistics.*;import Market.*;import Options.*;import Exceptions.*;/**  * <p>The Monte Carlo price and controlled Monte Carlo price price of a European  * call on a constant volatility asset computed from a sample of 10000 paths of * the underlying asset are introduced as random variables in their own right  * and the variance of these random variables computed.</p> * * <p>The two variances are computed from a sample of size 200</p> * * <p>The idea is to check if use of the control variate does reduce  * the variance</p> </p>  * * <p>The control variate is the discounted price of the underlying asset * at exoiration (the default control variate).</p> * * <p>Parameters (time to expiration, volatility,...) fixed in source code  * without user interaction and are chosen so that a high correlation of the * call payoff with the control variate prevails (deep in the money call).</p> * *  * @author  Michael J. Meyer * */public class CallControlVariateTest{  public static void main(String[] args)  {            final int  T=50,                 nPaths=10000,                 nSamples=200;                   final double S_0=50,                   mu=0.24,                   sigma=0.31,                   q=0.05,                   r=0.07,                   K=45,                   dt=0.02;                           // the underlying, nSignChange=8       ConstantVolatilityAsset       asset=new ConstantVolatilityAsset(T,dt,8,S_0,r,q,mu,sigma);                 // the call        final BlackScholesCall call=new BlackScholesCall(K,asset);       // correlation of call payoff with control variate to 5 decimals       double cv_corr=call.controlVariateCorrelation(3000);       cv_corr=1.0*Math.round(10000*cv_corr)/10000;              String Str;       Str="Correlation of call payoff with control variate = "+cv_corr+"\n";       System.out.println(Str);                      /* The Monte carlo price of the call as a random variable.         * No conditioning so the time parameter t is ignored.         */        final RandomVariable mc_price=new RandomVariable(){                    public double getValue(int t)            {               return call.discountedMonteCarloPrice(nPaths);                               } // end getValue                }; //end X             // variance of the uncontrolled Monte Carlo price        double variance=mc_price.variance(nSamples);                String         message="Variance of uncontrolled Monte Carlo price = "+variance;        System.out.println(message);                                // the controlled Monte Carlo price as a random variable        final RandomVariable cmc_price=new RandomVariable(){                    public double getValue(int t)            {                return call.controlledDiscountedMonteCarloPrice(nPaths);              } // end getValue                }; //end cmc_price                        // variance of the controlled Monte Carlo price        double controlled_variance=cmc_price.variance(nSamples);                message="Variance of controlled Monte Carlo price = "                +controlled_variance;        System.out.println(message);           }//end main   }//end CallControlVariateTest        

⌨️ 快捷键说明

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