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

📄 callpriceqmc.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*//* * CallPriceQMC.java * * Created on April 19, 2002, 9:52 PM */package Examples.Pricing;import QuasiRandom.*;import Statistics.*;import Market.*;import Options.*;import com.skylit.io.EasyWriter;/** <p>Computes the price of a European call: analytic price, ordinary Monte  *  Carlo price and Sobol QMC price with inverse normal CDF conversion and  *  writes a report *  on relative accuracy to the file QMC-accuracy.txt.</p> *   * * @author  Michael J. Meyer */public class CallPriceQMC {      // write results to file    static final EasyWriter io=new EasyWriter("QMC-accuracy.txt", "app");       public static void main(String[] args)   {            int  T=9,           nPaths=100000,           nSignChange=5,  // irrelevant, but needed for asset constructor           uniformToNormalConversion;                   double S_0=50,             mu=0.0,             sigma=0.4,             q=0.0,             r=0.0,             dt=1.0/T,             K=90;                    // timing       long before=System.currentTimeMillis();              // the underlying with ordinary random dynamics       ConstantVolatilityAsset asset=       new ConstantVolatilityAsset(T,dt,nSignChange,S_0,r,q,mu,sigma);       BlackScholesCall call=new BlackScholesCall(K,asset);       double analytic_price=call.discountedAnalyticPrice(0);              System.out.println("\n\n\n");       io.println("\n\n\nDIMENSION (time steps to horizon): "+T+"\n");       io.println("Call analytic price: "+analytic_price);       io.println("Paths="+nPaths+"\n");             // the call as path independent option       // to ensure full paths are computed when option price is evaluated.              // classic Monte Carlo              // the call based on Monte Carlo asset       CallAsPathDependent callMC=new CallAsPathDependent(K,asset);       double priceMC=callMC.discountedMonteCarloPrice(nPaths);       report("Monte Carlo",analytic_price,priceMC,T,nPaths);                            // Sobol-QMC       // the underlying with QMC dynamics       ConstantVolatilityAssetQMC        assetQMC=new ConstantVolatilityAssetQMC       (T,dt,nSignChange,S_0,r,q,mu,sigma,ConstantVolatilityAssetQMC.SOBOL);       // the call based on Quasi Monte Carlo asset       CallAsPathDependent callQMC=new CallAsPathDependent(K,assetQMC);       double priceQMC=callQMC.discountedMonteCarloPrice(nPaths);       report("Quasi Monte Carlo, Sobol-Inverse Normal CDF",              analytic_price,priceQMC,T,nPaths);                         // time used       long after=System.currentTimeMillis(),            time=after-before;       io.println("Time: "+time+".");       io.close();       System.out.println       ("Finished. Results in file QMC-accuracy.txt.");                  } // end main              // print findings    static void report(String str, double analytic_price, double z,                       int T, int nPaths)    {        double relerror=Math.abs(analytic_price-z)/analytic_price;        io.println(str+", relative error(%): "+(100*relerror)+"\n");        System.out.println(str+", done.");    }                        } // end CallPriceQMC

⌨️ 快捷键说明

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