monte carlo programs

上传人:aa****6 文档编号:37041327 上传时间:2018-04-06 格式:PDF 页数:70 大小:733.10KB
返回 下载 相关 举报
monte carlo programs_第1页
第1页 / 共70页
monte carlo programs_第2页
第2页 / 共70页
monte carlo programs_第3页
第3页 / 共70页
monte carlo programs_第4页
第4页 / 共70页
monte carlo programs_第5页
第5页 / 共70页
点击查看更多>>
资源描述

《monte carlo programs》由会员分享,可在线阅读,更多相关《monte carlo programs(70页珍藏版)》请在金锄头文库上搜索。

1、CHAPTER 83 Monte Carlo programsIn this Chapter.a few illustrative simulation programs83.1INTRODUCTIONHere are a few Visual Basic codes to get you started with this important numerical method.83.2MONTE CARLO PRICING OF A BASKETThe following code values a European option onNDimlognormal assets. The pa

2、yoff in this example is simply the maximum of all of the assets. Arrays must be input forAsset, the starting prices,VolandDivYld. The correlation matrixCorrelis input as a square array. This is decomposed by the subroutineNewMat.Function Monte_Carlo_Basket(Asset, Correl, Vol, DivYld, IntRate, Expiry

3、, _ NoEvals, NDim)ReDim ux(1 To NDim) As Double ReDim cx(1 To NDim) As Double ReDim s(1 To NDim) As Double ReDim CholM(1 To NDim, 1 To NDim) As Doublerootexpiry = Sqr(Expiry) a = Exp(-IntRate * Expiry) / NoEvals suma = 0Call NewMat(Correl, CholM, NDim)For k = 1 To NoEvalsproduce uncorrelated Normal

4、variables For i = 1 To NDim If test = 0 Then1312Part Six numerical methods and programsDo y = 2 * Rnd() - 1 z = 2 * Rnd() - 1 dist = y * y + z * z Loop Until dist 0) n1 = Int(n0 / b) r = n0 - n1 * b h = h + f * r f = f / b n0 = n1 Wend Halton = h End Function83.4MONTE CARLO FOR AMERICAN OPTIONSThis

5、code implements the Longstaff in this case it is that for a put. You should also modify this code to use different basis functions.Function USOptionMC(SToday, Strike, Expn, Vol, IntRate, NTS, NPaths)ReDim Stock(0 To NTS, 1 To NPaths) ReDim Cashflow(1 To NTS, 1 To NPaths) ReDim TempArrayX(1 To NPaths

6、, 1 To 2) ReDim TempArrayY(1 To NPaths) Dim TempArrayXForRegression() Dim TempArrayYForRegression() ReDim Regress(1 To 3)Monte Carlo programs Chapter 831315TStep = Expn / NTS Drift = (IntRate - 0.5 * Vol * Vol) * TStep SD = Vol * Sqr(TStep) DF = Exp(-IntRate * TStep) Simulate stock For i = 1 To NPat

7、hs Stock(0, i) = SToday For j = 1 To NTS Stock(j, i) = Stock(j - 1, i) * Exp(Drift + SD * Norm) Next j Next iFor i = 1 To NPaths Cashflow(NTS, i) = Payoff(Stock(NTS, i), Strike) ValueEuro = ValueEuro + Cashflow(NTS, i) / NPaths Next iValueEuro = DF NTS * ValueEuro Just in case you want to output thi

8、s as wellFor j = NTS - 1 To 1 Step -1Num = 0For i = 1 To NPaths If Payoff(Stock(j, i), Strike) 0 Then Num = Num + 1 Next i Regression ReDim TempArrayXForRegression(1 To 2, 1 To Num) ReDim TempArrayYForRegression(1 To Num) k = 1For N = 1 To Num TempArrayXForRegression(1, N) = 0 TempArrayXForRegressio

9、n(2, N) = 0 TempArrayYForRegression(N) = 0 Next NFor i = 1 To NPathsIf Payoff(Stock(j, i), Strike) 0 Then ITM TempArrayXForRegression(1, k) = Stock(j, i) TempArrayXForRegression(2, k) = Stock(j, i) * Stock(j, i) For m = 1 To NTS - j TempArrayYForRegression(k) = TempArrayYForRegression(k) _ + DF m *

10、Cashflow(j + m, i) Next m k = k + 1 End IfNext i Use Excel LinEst function to calculate regression coefficients Regress = Application.LinEst(TempArrayYForRegression, TempArrayXForRegression)1316Part Six numerical methods and programsFor i = 1 To NPaths If Payoff(Stock(j, i), Strike) Regress(1) * Sto

11、ck(j, i) * Stock(j, i) + _ Regress(2) * Stock(j, i) + Regress(3) _ And Payoff(Stock(j, i), Strike) 0 Then Exercise Cashflow(j, i) = Payoff(Stock(j, i), Strike) For m = 1 To NTS - j Cashflow(j + m, i) = 0 Next m Else Cashflow(j, i) = 0 End If Next iNext j Present Value all cashflows and average For i

12、 = 1 To NPaths For j = 1 To NTS ValueUS = ValueUS + DF j * Cashflow(j, i) / NPaths Next j Next iUSOptionMC = ValueUSEnd FunctionFunction Payoff(S, E) Payoff = 0 If S = 1) Then GoTo 1 Norm = Y * Sqr(-2 * Log(R) / R)End FunctionAPPENDIX A all the math you need. and no more (an executive summary)In thi

13、s Appendix.e log differentiation and Taylor series expectations and variancesA.1INTRODUCTIONThis book is for everyone interested in quantitative finance. This subject is becoming increas- ingly technical. Some people dont have a high-level math training, through no fault of their own, but may still

14、be interested in the technical side of things. In this appendix we look at the mathematics that you need to cope with the vast majority of derivatives theory and prac-tice. Although often couched in very high-level mathematics almost all finance theory can be interpreted using only the basics that I

15、 describe here.The most useful math is the simplest math. This is particularly true in finance where the beauty of the mathematics can and does lead to people not seeing the wood for the trees. Allbasic finance theory and a great deal of the advanced research really require only elementary mathemati

16、cs if approached in the right way. In this appendix I explain this elementary mathe- matics and show how to use it to understand the BlackScholes derivatives theory. I am trying to do for Mathematical Finance what Seuss (1999) did for the English language.A.2THE DIFFERENT TYPES OF MATHEMATICS FOUND IN FINANCEThere are many different types of mathematics in use in quantitative finance. The most popular are differential equations, abstract probability theory

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号