我是VBA编码的新手,我正在尝试编写VBA代码。 它应该尝试创建一个有效的前沿,因此解决目标波动率(约束1到20)并最大化投资组合预期收益。 应修改代码,以便theSolver可以迭代一系列目标投资组合波动率,以生成有效的边界。
代码如下:
Sub efficient_frontier_solver()
Dim rngobjectCells As Range
Set rngobjectCells = Range("R4:R23")
Dim rngObjectcell As Range
For Each rngObjectcell In rngobjectCells
SolverReset
SolverOk SetCell:=rngObjectcell.Address, MaxMinVal:=1, ValueOf:=0, ByChange:=rngObjectcell.Address, _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=rngObjectcell.Address, Relation:=2, FormulaText:=rngObjectcell.Address
SolverOk SetCell:=rngObjectcell.Address, MaxMinVal:=1, ValueOf:=0, ByChange:=rngObjectcell.Address, _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:=rngObjectcell.Address, MaxMinVal:=1, ValueOf:=0, ByChange:=rngObjectcell.Address, _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Next
End Sub
它给出了一个错误,变量未定义。 有人可以帮忙吗?
亲切的问候,
弗雷德里克