| Category: Excel |
View Full Details
|
Generating multivariate normal random numbers in VBA |
| Submitter: vanna |
Date: 2008/9/23 |
|
|
Description:
This function GetMuiltivariateRandomNos returns a set of n vectors drawn from multivariate normal distribution. Input parameters are : Mu : mean array Sigma : covariance matrix of a normal distribution cases : no. of random vectors Following is example usage:
Redim Sigma(1 to 3,1 to 3)
Sigma(1,1)=1.55869
Sigma(1,2)=-0.85802
Sigma(1,3)=1.45868
Sigma(2,1)=-0.85802
Sigma(2,2)=2.24283
Sigma(2,3)=-2.44512
Sigma(3,1)=1.45868
Sigma(3,2)=-2.44512
Sigma(3,3)=3.75283
ReDim Mu(1 To 3, 1 To 1)
Mu(1, 1) = 1
Mu(2, 1) = 2
Mu(3, 1) = 0
rndvars = GetMuiltivariateRandomNos(Mu, Sigma, 10)
Following is value of rndvars matrix:
-0.347443879 2.04617674 -1.186177819
2.580336111 0.464957559 2.243791782
1.131096202 1.727204021 2.338258573
0.583116106 3.809239781 -2.834853381
0.637456616 2.87640474 -0.190386463
0.133824191 1.677845184 0.221439357
2.03751742 2.8033236 0.428118682
0.473264324 3.623211235 -2.341566983
5.078022715 -1.278159439 4.887537982
2.249934772 4.007060452 -1.970715669
Got a question or problem with this link? Just enter your message and click on submit. No registration is required.
|
1841 0 bytes Excel VBA http://www.quantcode.com/ |
| Category: Excel |
View Full Details
|
Function Minimization using Nelder Mead Simplex |
| Submitter: vanna |
Date: 2008/12/31 |
|
|
Description:
This class is used for minimzing a user defined function in a module file. It uses Nelder mead simplex algorithm For example, consider mimizing this function: Public Function MyFunction(xVec As Variant) As Double
MyFunction = (xVec(1, 1) - 4) ^ 2 + (xVec(2, 1) - 2.7) ^ 4 + (xVec(3, 1) - 6.7) ^ 4
End Function Use the following code to get minimum:
ReDim initParams(1 To 3, 1 To 1)
initParams(1, 1) = 0
initParams(2, 1) = -1
initParams(3, 1) = -2.8
Dim nelderObj As New Nelder
result = nelderObj.SolveMaximum("MyFunction", initParams)
Optionally, accuracy or tolerance for convergence can be changed by setting eg., nelderObj.Tolerance_=0.00001 Demo for using this function
Got a question or problem with this link? Just enter your message and click on submit. No registration is required.
|
2367 0 bytes Excel VBA http://www.quantcode.com/ |
|