什麼是「蒙地卡羅方法」?它是一種數值方法,利用亂數取樣(randomsampling)模擬來解決數學問題。一般公認蒙地卡羅方法一詞為著名數學家JohnvonNeumann等人於1949年一篇名為「TheMonteCarlomethod」所提出。其實,此方法的理論基礎於更早時候已為人所知,只不過用手動產生亂數來解決問題,是一件費時又費力的繁瑣工作,必須等到電腦時代,使此繁複計算工作才變得實際可執行為什麼取名「蒙地卡羅方法」?在數學上,所謂產生亂數,就是從一給定的數集合中選出的數,若從集合中不按順序隨機選取其中數字,這就叫是亂數,若是被選到的機率相同,這就叫是一均勻亂數。例如擲骰子,1點至6點骰子出現機率均等。雖然,現在科學研究中經常是利用電腦產生均勻分佈於[0,1]之間的數,但早期最簡單方式是由賭場輪盤以機械方式產生亂數。這也是為何以摩洛歌首都--蒙地卡羅(賭城)為名的緣故[例題:求圓周率]利用電腦產生均勻分佈於[0,1]之間的數為點X、Y座標位置,由於點座標均勻分佈在0~1之間,所以落在某區域之點數目與其面積成正比,只要將落在圓內點數目除以點模擬總數目,即可得圓周率之數值。[蒙地卡羅方法基本原理]蒙地卡羅方法到底適合解決哪些問題?舉凡所有具有隨機效應的過程,均可能以蒙地卡羅方法大量模擬單一事件,藉統計上平均值獲得某設定條件下實際最可能測量值。現今此方法已被應用在許多領域中。蒙地卡羅方法的基本原理是將所有可能結果發生的機率,定義出一機率密度函數。將此機率密度函數累加成累積機率函數,調整其值最大值為1,此稱為歸一化(Normalization)。這也將正確反應出所有事件出現的總機率為1的機率特性,這也為亂數取樣與實際問題模擬建立起連結。也就是說我們將電腦所產生均勻分佈於[0,1]之間的亂數,透過所欲模擬的過程所具有機率分佈函數,模擬出實際問題最可能結果。MonteCarloSimulationBasicsAMonteCarlomethodisatechniquethatinvolvesusingrandomnumbersandprobabilitytosolveproblems.ThetermMonteCarloMethodwascoinedbyS.UlamandNicholasMetropolisinreferencetogamesofchance,apopularattractioninMonteCarlo,Monaco(Hoffman,1998;MetropolisandUlam,1949).Computersimulationhastodowithusingcomputermodelstoimitatereallifeormakepredictions.Whenyoucreateamodel,youhaveacertainnumberofinputparametersandafewequationsthatusethoseinputstogiveyouasetofoutputs(orresponsevariables).Thistypeofmodelisusuallydeterministic,meaningthatyougetthesameresultsnomatterhowmanyyoure-calculate.Figure1:Aparametricdeterministicmodelmapsasetofinputvariablestoasetofoutputvariables.MonteCarlosimulationisamethodforiterativelyevaluatingadeterministicmodelusingsetsofrandomnumbersasinputs.Thismethodisoftenusedwhenthemodeliscomplex,nonlinear,orinvolvesmorethanjustacoupleuncertainparameters.Asimulationcantypicallyinvolveover10,000evaluationsofthemodel,ataskwhichinthepastwasonlypracticalusingsupercomputers.[Example:ADeterministicModelforCompoundInterest]DeterministicModelExampleAnexampleofadeterministicmodelisacalculationtodeterminethereturnona5-yearinvestmentwithanannualinterestrateof7%,compoundedmonthly.Themodelisjusttheequationbelow:Theinputsaretheinitialinvestment(P=$1000),annualinterestrate(r=7%=0.07),thecompoundingperiod(m=12months),andthenumberofyears(Y=5).表單的頂端CompoundInterestModelPresentvalue,PAnnualrate,rPeriods/Year,mYears,YFuturevalue,FOneofthepurposesofamodelsuchasthisistomakepredictionsandtry"WhatIf?"scenarios.Youcanchangetheinputsandrecalculatethemodelandyou'llgetanewanswer.Youmightevenwanttoplotagraphofthefuturevalue(F)vs.years(Y).Insomecases,youmayhaveafixedinterestrate,butwhatdoyoudoiftheinterestrateisallowedtochange?Forthissimpleequation,youmightonlycaretoknowaworst/bestcasescenario,whereyoucalculatethefutureval...