Dear All-
short intro first. I am a prof of Finance in a Business School and teach portfolio management to master students.
In this context, I develop concepts around efficient frontier. I would like to show my students how an efficient frontier could be built out of excel using solver and VBA.
I am currently trying to automate a VBA-prompted Solver to generate an efficient frontier; The solver is pre-calibrated, so no need to set goal, constraints etc...
When I run the macro, nothing executes..... big frustration.
See my code below
See also the level of automation I would ideally want to reach.
YOUR HELP MUCH APPRECIATED
Thanks and Best Regards
https://www.youtube.com/watch?v=fa3TG4ZpJY8 - This vid link show the level of automation I would want to reach. My xlsm is comparable to his
See code below
Sub SolverMacro()
Dim datastart As Integer 'dimension variable
OrigCalculation = Application.Calculation 'store current calculation mode.
iter = 1 'define iter
'Loop
Do While iter <= totiter 'totiter is the cell named for total number of iterations
'take the first target return of the list and put it as target return for the sim
Sheets("Sheet1").Range("targret").Value = Sheets("Sheet1").Range("Anchor").Value
'run the solver
Call SolverSolve(True)
SolverFinish
'define dynamic target row
datastart = Sheets("Sheet1").Range("b20").Value
'report results in the table
Sheets("Sheet1").Range("datastart").Offset(1, 0).Value = Sheets("Sheet1").Range("j5").Value
Sheets("Sheet1").Range("datastart").Offset(1, 1).Value = Sheets("Sheet1").Range("j6").Value
Sheets("Sheet1").Range("datastart").Offset(1, 2).Value = Sheets("Sheet1").Range("j7").Value
iter = iter + 1
Loop
Application.Calculation = OrigCalculation 'reset calculation mode to same as before macro was executed.
End Sub
short intro first. I am a prof of Finance in a Business School and teach portfolio management to master students.
In this context, I develop concepts around efficient frontier. I would like to show my students how an efficient frontier could be built out of excel using solver and VBA.
I am currently trying to automate a VBA-prompted Solver to generate an efficient frontier; The solver is pre-calibrated, so no need to set goal, constraints etc...
When I run the macro, nothing executes..... big frustration.
See my code below
See also the level of automation I would ideally want to reach.
YOUR HELP MUCH APPRECIATED
Thanks and Best Regards
https://www.youtube.com/watch?v=fa3TG4ZpJY8 - This vid link show the level of automation I would want to reach. My xlsm is comparable to his
See code below
Sub SolverMacro()
Dim datastart As Integer 'dimension variable
OrigCalculation = Application.Calculation 'store current calculation mode.
iter = 1 'define iter
'Loop
Do While iter <= totiter 'totiter is the cell named for total number of iterations
'take the first target return of the list and put it as target return for the sim
Sheets("Sheet1").Range("targret").Value = Sheets("Sheet1").Range("Anchor").Value
'run the solver
Call SolverSolve(True)
SolverFinish
'define dynamic target row
datastart = Sheets("Sheet1").Range("b20").Value
'report results in the table
Sheets("Sheet1").Range("datastart").Offset(1, 0).Value = Sheets("Sheet1").Range("j5").Value
Sheets("Sheet1").Range("datastart").Offset(1, 1).Value = Sheets("Sheet1").Range("j6").Value
Sheets("Sheet1").Range("datastart").Offset(1, 2).Value = Sheets("Sheet1").Range("j7").Value
iter = iter + 1
Loop
Application.Calculation = OrigCalculation 'reset calculation mode to same as before macro was executed.
End Sub