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

📄 mc_asset_test.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*//* * CompoundPoissonProcess.java * * Created on February 22, 2002, 5:00 PM */  package Examples.Pricing;import Statistics.*;import Processes.*;import Market.*;import Options.*;import Triggers.*;import java.lang.Math.*; /** <p>Console program testing the accuracy of the Markov chain approximation *  of a constant volatility asset.</p> * *<p>A standard European call is priced analytically, by Monte Carlo  * simulation based on the Markov chain approximation of the asset price  * and by Monte Carlo simulation based on the asset price dynamics itself. * The prices are then compared for accuracy.</p> * *<p>All parameters fixed in source code. No user interaction. *  Change the parameters in the source code and recompile if you must.</p> * * @author  Michael J. Meyer */public class MC_Asset_Test{    public static void main(String[] args)    {        final double // underlying asset:                     S_0=50,           // asset price at time t=0                     mu=0.15,          // asset price market drift                     sigma=0.3,        // asset price volatility                     r=0.06,           // risk free rate                     q=0.05,           // dividend yield                     dt=0.01,          // size of time step                     // Markov chain approximation:                     ds=0.5,           // mesh size of range grid                     delta=0.01,       // cutoff probability residual states                     // call:                     K=65;             // call strike                final int T=50,                // time steps to horizon (expiry)                   nSignChange=2,                  nStates=500;        // number of states in markov chain                                        // approximation                final ConstantVolatilityAsset         asset=new ConstantVolatilityAsset(T,dt,nSignChange,S_0,r,q,mu,sigma);                final BlackScholesCall call=new BlackScholesCall(K,asset);                final SFSMarkovChainImpl chain=asset.markovChain(nStates,ds,delta);                             /* Set up the discounted call payoff as a random variable          * using the Markov chain approximation of the asset price.         * Since we compute the price at time t=0 only we can disregard the         * time parameter t below.         */        RandomVariable call_payoff=new RandomVariable(){                          // the (value, control variate) pair             public double getValue(int t)             {                 chain.newPath();                 double j=chain.get_path()[T],                        S_T=(0.5+j)*ds,                        B_T=asset.get_B()[T],                        discounted_payoff=Math.max(S_T-K/B_T,0.0);                                  return discounted_payoff;                                     } // end getValue                      }; // end callpayoff                           System.out.println("CALL PRICE:\n");                  // analytic price to 5 decimals         double an_price=call.discountedAnalyticPrice(0);         an_price=1.0*Math.round(an_price*10000)/10000;         System.out.println         ("Analytic: "+an_price+"\n\n");                  // 10 computations of the Markov chain Monte Carlo price         // to 5 decimals         for(int i=0;i<10;i++){         double mc_price=call_payoff.expectation(100000);         mc_price=1.0*Math.round(mc_price*10000)/10000;         System.out.println("Markov chain Monte Carlo: "+mc_price);}                  System.out.println("\n");                  // 10 computations of the ordinary Monte Carlo price         // to 5 decimals         for(int i=0;i<10;i++){         double mc_price=call.discountedMonteCarloPrice(100000);         mc_price=1.0*Math.round(mc_price*10000)/10000;         System.out.println("Monte Carlo: "+mc_price);}               } // end main     } // end MC_Asset_Test                                                                

⌨️ 快捷键说明

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