想用VBA跑历史模拟法风险值计算,但是一直有小地方出错!!请问有人愿意帮我看一下吗?谢谢
Dim n As Integer, j As Integer, w As Integer, k As Integer, lamda As Double, level As Double
privatesub commandbutton1_click() 这里一直出现错误 请问要怎么改呢?
Application.Dialogs(xlDialogOpen).Show
Rows("1:1").Select
rang("n1").Activate
Selection.Insert shift:=xlDown
Columns("a:a").Select
Selection.Copy
Workbooks("historicalvar.xls").Worksheets("sheet1").Activate
Columns("a:a").Select
ActiveSheet.Paste
End Sub
Private Sub commandbutton3_click()
Cells(1, 1) = "历史股价"
Cells(1, 2) = "日报酬率"
Cells(3, 3) = "选定信赖水平下之临界报酬率"
Cells(1, 4) = "历史模拟法 var"
n = Range("a65536").End(xlUp).Row - 1
For j = 2 To n
Cells(j, 2) = ((Cells(j, 1) - Cells(j + 1, 1)) / Cells(j + 1, 1))
Next j
Range(Cells(2, 2), Cells(n, 2)).Sort key1:=Range(Cells(2, 2), Cells(n, 2))
level = Val(1 - Cells(2, 3))
k = Application.WorksheetFunction.Floor((n - 1) * level, 1)
Cells(4, 3) = Cells(k + 1, 2)
Cells(2, 4) = Val(textbox2.Text) * Cells(4, 3)
textbox1.Text = Application.WorksheetFunction.Round(Cells(2, 4), 0)
想要计算VAR,输出时用ROUND四拾五入到整数字!! 但是也跑不出来
End Sub
Private Sub commandbutton6_click()
Cells(1, 5) = "权重"
Cells(1, 6) = "修正后股价"
Cells(1, 7) = "修正后报酬率"
Cells(3, 8) = "修正后临界报酬率"
Cells(1, 9) = "指数加权移动平均法 var"
For w = 2 To n + 1
Cells(w, 5) = (1 + (lamda ^ (w - 1) * (1 - lamda) / (1 - lamda ^ n)))
Cells(w, 6) = Cells(w, 5) * Cells(w, 1)
Next
For w = 2 To n
Cells(w, 7) = (Cells(w, 6) - Cells(w + 1, 6)) / Cells(w + 1, 6)
Next
Range(Cells(2, 7), Cells(n, 7)).Sort key1:=Range(Cells(2, 7), Cells(n, 7))
Cells(4, 8) = Cells(k + 1, 7)
Cells(2, 9) = Val(textbox2.Text) * cell(4, 8)
textbox3.Text = Application.WorksheetFunction.Round(Cells(2, 9), 0)
End Sub