Hi,
I asked the question because you can get the standard deviation, mean, and so on, from VBA, but it requires a complicated syntax. This can be useful if you are trying to do it in the middle of a simulation - using the stepped simulation function, as above - but it's much easier if you only need the values at the end of a simulation.
To run a simulation from VBA, using the VBA library, you can do it in one line of code:
RiskAMP_RunSimulation( 1000 )
for 1000 iterations. To get values for standard error, standard deviation, and so on, I would suggest putting the functions into spreadsheet cells and fetching the results directly from those cells. So if you have a value in cell A1, you can put the standard error function in A2, like
=SimulationStandardError( A1 )
and then fetch the result from VBA with code like
Range( "A2" ).value
---
If you don't want to use the spreadsheet to do this, you can do it from VBA, but it 's more complicated. There are a few things you need to do:
First, you need to have at least one cell in the spreadsheet reference the cell you want to look at. For example, if you want to look at the value in cell A1, somewhere else in the spreadsheet you have to have something - maybe a mean function - like
=SimulationMean( A1 )
The reason is because we only store results for cells that are referenced by our statistics functions. We do this to save memory; otherwise we would have to store every result for every cell, which would require much more available memory. Once you do that, in order to refer to a cell specifically, you have to use the Excel INDIRECT method with the cell's address.
Finally, because these functions aren't in the VBA module, you have to use the full syntax. To put that all together, if you want to look at the standard error for cell A1, the function in VBA would look like
value = Application.ExecuteExcel4Macro("SimulationStandardError(INDIRECT(" & Chr(34) & "A1" & Chr(34) & "))")
The other functions work the same way; you would use SimulationStandardDeviation or SimulationMean to get the deviation and mean, respectively. I'm sorry this is so complicated. Please let me know if that helps.
Cheers,
Alex Edwards
alex@riskamp.com