佟 瑞
[摘 要] 本文在給出股票價格的隨機(jī)模擬方法步驟的基礎(chǔ)上,設(shè)計了求解股票價格的計算程序,這樣可大大提高其計算效率。
[關(guān)鍵詞] 股票價格;隨機(jī)模擬;信息化實現(xiàn)
[中圖分類號]F275;F232[文獻(xiàn)標(biāo)識碼]A[文章編號]1673-0194(2009)01-0029-02
1 股票價格的隨機(jī)模擬方法
假設(shè)股票價格滿足下面的方程:S■= S■exp( μΔt+
σz■),式中,S■為t時刻的股票價格;S■為(t+1)時刻的股票價格; μ為股票價格對數(shù)變動的均值;σ為股票價格對數(shù)變動的標(biāo)準(zhǔn)差;Δt為要計算的時間間隔(以年為單位,若1年內(nèi)股票交易天數(shù)按250天計算,則Δt=1/250);z為服從標(biāo)準(zhǔn)正態(tài)分布的隨機(jī)數(shù)。
則可以根據(jù)這個方程建立股票價格的蒙特卡羅模擬模型。股票價格的蒙特卡羅模擬過程如下:
(1)首先根據(jù)股票價格的歷史數(shù)據(jù)進(jìn)行統(tǒng)計分析,得出股票價格對數(shù)變動的均值和標(biāo)準(zhǔn)差。
(2)利用上述方程對不同的隨機(jī)數(shù)計算股票價格。
(3)進(jìn)行足夠多次數(shù)的模擬計算,將這些模擬計算結(jié)果的平均值作為股票價格的估計。
2 股票價格的隨機(jī)模擬及其信息化的實現(xiàn)方案
上述計算是一個相當(dāng)麻煩的過程,為此,我們編制了一個VBA程序,簡化了上述的計算。VBA程序如下:
Sub zbsj()
Dim n As Integer, m As Integer, i As Integer
n = Cells(4, 2)
m = Cells(5, 2)
Cells(10, 1) = "輸入各個證券的投資比重,股票價格,對數(shù)均值和對數(shù)標(biāo)準(zhǔn)差"
Cells(11, 1) = "證券"
For i = 1 To n
Cells(11, i + 1) = "證券" & i
Next i
Cells(12, 1) = "投資比重"
Cells(13, 1) = "股票價格對數(shù)均值"
Cells(14, 1) = "股票價格對數(shù)標(biāo)準(zhǔn)差"
Cells(15, 1) = "目前股票價格"
End Sub
Sub js()
Dim i As Integer, j As Integer, n As Integer, m As Integer, nt As Integer
Dim dt As Single, rd As Single, z As Single, sumt As Single, sum1 As Single, sum2 As Single
Dim myrange1 As String, myrange2 As String, myrange3 As String
n = Cells(4, 2)
m = Cells(5, 2)
nt = Cells(8, 2)
dt = Cells(6, 2) / 250
ReDim w(n), p0(n), p1n(n), pcn(n), p(n, m), pp(m),
rp(m) As Single
For i = 1 To n
w(i) = Cells(12, i + 1)'各股票的投資比例
p1n(i) = Cells(13, i + 1)'各股票價格對數(shù)均值
pcn(i) = Cells(14, i + 1)'各股票價格對數(shù)標(biāo)準(zhǔn)差
p(i, 0) = Cells(15, i + 1) '各股票的目前價格
Next i
sumt = 0
For i = 1 To n
sumt = sumt + w(i) * p(i, 0)
Next i
pp(0) = sumt '目前的投資組合價格
UserForm1.Show
UserForm1.Label2.Width = 0
For j = 1 To m
sum1 = 0
sum2 = 0
For t = 1 To nt
sumt = 0
rd = Rnd()
z = Worksheets.Application.WorksheetFunction.NormSInv(rd)
For i = 1 To n
p(i, j) = p(i, j - 1) * Exp(p1n(i) * dt + pcn(i) * z * Sqr(dt)) '各股票價格模擬
sumt = sumt + w(i) * p(i, j)
Next i
sum1 = sum1 + sumt
'顯示計算進(jìn)度條(模擬過程)
UserForm1.Label5.Width = Int(t / nt * 225)
UserForm1.Label6.Caption = CStr(Int(t / nt * 100)) + "%"
DoEvents
Next t
pp(j) = sum1 / nt'各投資組合價格的模擬
'顯示計算進(jìn)度條(總進(jìn)度)
UserForm1.Label2.Width = Int(j / m * 225)
UserForm1.Label3.Caption = CStr(Int(j / m * 100)) + "%"
DoEvents
Next j
Unload UserForms1
For j = 1 To m
rp(j) = pp(j) - pp(j - 1)'各期投資組合收益的模擬
Next j
Cells(17, 1) = "計算過程——(模擬計算)" & nt & "次的平均值"
For j = 1 To m
Cells(17 + j, 1) = j
Cells(17 + j, 2) = pp(j)
Cells(17 + j, 3) = rp(j)
Range(Cells(17 + j, 2), Cells(17 + j, 3)).NumberFormat = "0.00"
Next j
myrange1 = "b18" & ":" & "b" & 17 + m '投資組合價格數(shù)據(jù)區(qū)域
myrange2 = "c18" & ":" & "c" & 17 + m '投資組合各期收益數(shù)據(jù)區(qū)域
myrange3 = "b18" '期初投資組合價格數(shù)據(jù)區(qū)域
Range("F3") = "=average(" & myrange1 & " ) "
Range("F4") = "=average(" & myrange2 & " ) "
Range("F5") = "b3" & myrange3
Range("F6") = "f4*f5"
Range("F5:F6").Select
Selection.NumberFormat = "0.00"
nm = Int(Cells(5, 2) * (1 - Cells(7, 2)))
Range("G3") = "第" & nm & "個最壞收益"
Range("H3") = "Small(" & myrange2 & "," & nm & ")"
Range("H4") = "=F5*ABS(H3)"
Range("H3:H4").Select
Selection.NumberFormat = "0.00"
MsgBox ("模擬計算結(jié)束")
End Sub
主要參考文獻(xiàn)
[1]朱順泉. 理財信息化[M]. 北京:清華大學(xué)出版社,2006:297-304.