[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/21/2008 at 04:22AM PDT, ID: 23749275
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

how can i use this for var program?

Asked by tomonoric in Visual Basic Programming, Palm OS Programming

Tags: excel, ecxel2000, vba program

hi

I have a rather unusual question: I downloaded a function code of vba.
this function program is about monte calro sumiration of value at risk.
but actually i cant use thisfunction code.i understand only sub code. dose anyone have any idea how to use thisp program practically?
Any help would be most apreciated!
Many thanx and best regards  


'Written by P.Urbani based on a spreadsheet by Carol Alexander.
'This function will produce a Monte Carlo Value at Risk simulation.
'The inputs are:
'VC - Variance Co Variance matrix
'PosnWeights - The actual posn values
'Iterations - Number of simulations to perform recomend (3000+)
'CL - The Confidence Level required typically 0.95,0.97 or 0.99
't - The holding period (same units as source data)

Function MC_Var(VC As Variant, PosnWeights As Variant, Iterations As Variant, CL As Variant, time As Variant) As Variant
Dim X, i, j As Variant
X = VC.Columns.Count
'STEP ONE READ IN VC
Dim matrix As Variant
ReDim matrix(X, X)
For k = 1 To X
For l = 1 To X
matrix(k, l) = VC(k, l)
Next l
Next k
'STEP TWO PERFROM CHOLESKY DECOMPOSITION ON VC MATRIX
Dim CMAT() As Variant
Dim a() As Variant
Dim M() As Variant
Dim y As Single

ReDim CMAT(X, X)
ReDim a(X, X)
ReDim M(X, X)

For i = 1 To X
For j = 1 To X
a(i, j) = matrix(i, j)
M(i, j) = 0
Next j
Next i

For i = 1 To X
For j = i To X
y = a(i, j)
For O = 1 To (i - 1)
y = y - M(i, O) * M(j, O)
Next O
If j = i Then
M(i, i) = Sqr(y)
Else
M(j, i) = y / M(i, i)
End If
Next j
Next i

CMAT = M


'STEP THREE TRANSPOSE CMAT
Dim Temparr3() As Variant
ReDim Temparr3(X, X)
Temparr3 = Application.WorksheetFunction.Transpose(CMAT)


'STEP FOUR GENERATE (1 x X) VECTOR OF RANDOM STD NORMAL DEVIATES
'STEP FIVE MULTIPLY RND VECTOR BY TRANSPOSE OF CHOLESKY MATRIX

Dim RMAT() As Variant
Dim PLMAT() As Variant
Dim WVMAT() As Variant
Dim Temparr() As Variant
Dim Temparr6() As Variant

S = Iterations

ReDim RMAT(1, X)
ReDim WVMAT(1, X)
ReDim PLMAT(S, 1)
ReDim Temparr6(1, 1)
t = time
t = Sqr(t)
For p = 1 To S - 1 '(use this to loop around entire process)
For q = 1 To X
'Application.Volatile
e = Application.WorksheetFunction.NormSInv(Rnd())
RMAT(1, q) = e * t
Next q

'for normaly distributed use Application.WorksheetFunction.NormInv(Rnd(),mu,sigma)
'for random letters use Chr(65 + Int(26 * Rnd))
'for std normal use Application.WorksheetFunction.NormSInv(Rnd())

'STEP SIX MULTIPLY RMAT BY TRANSPOSE OF CMAT TO GET WVMAT
TEMPARR4 = Application.WorksheetFunction.MMult(RMAT, Temparr3)
WVMAT = TEMPARR4

'STEP SEVEN MULITPLY WVMAT BY TRANSPOSE OF POSNWEIGHTS TO GET P&LMAT

Dim Temparr5() As Variant
ReDim Temparr5(1, X)
Temparr5 = Application.WorksheetFunction.Transpose(PosnWeights)
Temparr6 = Application.WorksheetFunction.MMult(WVMAT, Temparr5)
PLMAT(p, 1) = Temparr6(1)
Next p


'STEP EIGHT SORT P&L VALUES

'ReDim HOLD(1, 1) As Variant
'ReDim SRTD(S, 1) As Variant
'ReDim BTAR(f, 1) As Variant

'R = S
'For h = 1 To R - 1
'HOLD(h, 1) = PLMAT(h, 1)


'Next h
'sort
'For i = 1 To R - 1
' For j = i + 1 To R - 1
' If HOLD(j) >= HOLD(i) Then
' SRTD = HOLD(i) ' swap routine
' HOLD(i) = HOLD(j)
' HOLD(j) = SRTD
' 'Put below target values into new array
' If j < f Then
' BTAR(j) = HOLD
' End If
' End If
' Next j
'Next i


'TAKE 1-CL PERCENTILE = VaR
Dim final() As Variant
ReDim final(1, 1)
final(1, 1) = Application.WorksheetFunction.Percentile(PLMAT, CL)

'AVERAGE OF VALUES BEYOND VaR = Conditional VaR

MC_Var = final 'PLMAT(S - 1, 1)
End Function

[+][-]09/21/08 08:07 AM, ID: 22534922

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic Programming, Palm OS Programming
Tags: excel, ecxel2000, vba program
Sign Up Now!
Solution Provided By: mdougan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11/08/09 02:23 PM, ID: 25772254

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 / EE_QW_2_20070628