PC Review


Reply
Thread Tools Rate Thread

Creating Excel simulation in VBA

 
 
Drews
Guest
Posts: n/a
 
      4th Jun 2007
Greetings VBA experts!

I need to make a macro that will generate 1000 simulations for 60
periods (i.e. a total of 60 000 simulations). The simulation is based
on a historic price, a std.dev., and a mean. In Excel I would use the
following formula for period 1:

=$'historic price' + norminv(rand();mean;std.dev.)

.... and copy it to 1000 rows.

For period 2 to 60 I would use the following formula:

='price simulation n for period 1' +
norminv(rand();mean;std.dev.)

.... and copy it to 1000 rows for each period 2 to 60.

My motivation for making the vba macro instead of using Excel formula
is that I don't want the simulation to update unless I request it -
e.g. by running the macro.

Hopefully someone can kindly help me with the code as my VBA skills
are obviously very limited. Thank you!

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmVuIE1jQmVu?=
Guest
Posts: n/a
 
      4th Jun 2007
Not sure you want to get into this - the general form could look like:

Dim darrMySimulationData() As Double
Dim i As Long, j As Long

ReDim darrMySimulationData(1 To 1000, 1 To 60)

j = 1
For i = LBound(darrMySimulationData) To UBound(darrMySimulationData)
darrMySimulationData(i, j) = 1 ' Your func here
Next i

For j = LBound(darrMySimulationData, 2) + 1 To UBound(darrMySimulationData, 2)
For i = LBound(darrMySimulationData) To UBound(darrMySimulationData)
darrMySimulationData(i, j) = darrMySimulationData(i, 1) ' Your
func here
Next i
Next j


However, as far as I know you cant use the rand function in VBA (but there
are several VBA implementations if you google for them).

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel simulation formula larry Microsoft Excel Worksheet Functions 1 1st Oct 2008 05:06 PM
HOw to use Monte cARLO sIMULATION IN eXCEL? Suparna Microsoft Excel Misc 1 1st Jun 2008 05:29 PM
Simulation in operations research using Excel denise1082 via OfficeKB.com Microsoft Excel Worksheet Functions 3 31st Jul 2006 10:46 AM
Blackjack simulation in Excel G Love Microsoft Excel Discussion 4 9th Nov 2005 12:25 PM
can excel do Monte Carlo simulation? =?Utf-8?B?UHJhZHM=?= Microsoft Excel Misc 2 19th May 2005 08:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:45 PM.