股票价格的随机模拟及其信息化的实现方案
2009-09-21佟瑞
佟 瑞
[摘 要] 本文在给出股票价格的随机模拟方法步骤的基础上,设计了求解股票价格的计算程序,这样可大大提高其计算效率。
[关键词] 股票价格;随机模拟;信息化实现
[中图分类号]F275;F232[文献标识码]A[文章编号]1673-0194(2009)01-0029-02
1 股票价格的随机模拟方法
假设股票价格满足下面的方程:S■= S■exp( μΔt+
σz■),式中,S■为t时刻的股票价格;S■为(t+1)时刻的股票价格; μ为股票价格对数变动的均值;σ为股票价格对数变动的标准差;Δt为要计算的时间间隔(以年为单位,若1年内股票交易天数按250天计算,则Δt=1/250);z为服从标准正态分布的随机数。
则可以根据这个方程建立股票价格的蒙特卡罗模拟模型。股票价格的蒙特卡罗模拟过程如下:
(1)首先根据股票价格的历史数据进行统计分析,得出股票价格对数变动的均值和标准差。
(2)利用上述方程对不同的随机数计算股票价格。
(3)进行足够多次数的模拟计算,将这些模拟计算结果的平均值作为股票价格的估计。
2 股票价格的随机模拟及其信息化的实现方案
上述计算是一个相当麻烦的过程,为此,我们编制了一个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) = "输入各个证券的投资比重,股票价格,对数均值和对数标准差"
Cells(11, 1) = "证券"
For i = 1 To n
Cells(11, i + 1) = "证券" & i
Next i
Cells(12, 1) = "投资比重"
Cells(13, 1) = "股票价格对数均值"
Cells(14, 1) = "股票价格对数标准差"
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)'各股票价格对数均值
pcn(i) = Cells(14, i + 1)'各股票价格对数标准差
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
'显示计算进度条(模拟过程)
UserForm1.Label5.Width = Int(t / nt * 225)
UserForm1.Label6.Caption = CStr(Int(t / nt * 100)) + "%"
DoEvents
Next t
pp(j) = sum1 / nt'各投资组合价格的模拟
'显示计算进度条(总进度)
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 '投资组合价格数据区域
myrange2 = "c18" & ":" & "c" & 17 + m '投资组合各期收益数据区域
myrange3 = "b18" '期初投资组合价格数据区域
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 ("模拟计算结束")
End Sub
主要参考文献
[1]朱顺泉. 理财信息化[M]. 北京:清华大学出版社,2006:297-304.