GrantLocke35
New Member
- Joined
- Dec 8, 2015
- Messages
- 4
hi guys, I would be extremely grateful for any support in solving this problem. In short I have created a cube of data, it is a series (Sx300, Px5,Tx50). S = simulations, p=portfolio and t is time horizon. In short it is a series of 300 stochastic simulations for each portfolio for each year. I need to calculate a confidence interval for each P for each T. This means I need to reference a column (p) and calculate the 90th percentile on each of the time horizons. I am trying to use an Index function but cannot see how it can reference a 3rd dimension - seems to only work in two!
Code:
Sub Forecasting_System()
Dim OUT1() As Variant
Dim OUT2() As Variant
Dim OUT3() As Variant
Dim OUT4() As Variant
Dim OUT5() As Variant
Dim Time_H As Integer
Dim Simulations As Integer
Dim OUT_Param() As Variant
Dim Annual_Contribution As Variant
Dim Lump_Sum As Variant
Dim Output_Table() As Double
Dim Percentile() As Double
Simulations = Range("Simulations")
ReDim Output_Table(1 To Simulations, 1 To 5, 1 To 50)
ReDim Percentile(1 To 5, 1 To 3, 1 To 50)
ReDim OUT_Param(1 To 5, 1 To 2)
OUT_Param = Range("Out_Param")
For Z = 1 To 50 ' Time horizon
x = 1
y = 1
For y = 1 To 5 ' Number of portfolios
For x = 1 To Simulations ' Number of simulations
Output_Table(x, y, Z) = 1
Next x
Next y
Next Z
x = 1
y = 1
Z = 1
For Z = 1 To 50
Time_H = Z
Lump_Sum = Range("Lump_Sum")
Annual_Contribution = Range("Mnthly_Contribution") * 12
For x = 1 To Simulations
a = 1
For a = 1 To Time_H
Output_Table(x, 1, Z) = (Output_Table(x, 1, Z) * (1 + Application.WorksheetFunction.NormInv(Rnd(), OUT_Param(2, 1), OUT_Param(2, 2))))
Output_Table(x, 2, Z) = (Output_Table(x, 2, Z) * (1 + Application.WorksheetFunction.NormInv(Rnd(), OUT_Param(2, 1), OUT_Param(2, 2))))
Output_Table(x, 3, Z) = (Output_Table(x, 3, Z) * (1 + Application.WorksheetFunction.NormInv(Rnd(), OUT_Param(3, 1), OUT_Param(3, 2))))
Output_Table(x, 4, Z) = (Output_Table(x, 4, Z) * (1 + Application.WorksheetFunction.NormInv(Rnd(), OUT_Param(4, 1), OUT_Param(4, 2))))
Output_Table(x, 5, Z) = (Output_Table(x, 5, Z) * (1 + Application.WorksheetFunction.NormInv(Rnd(), OUT_Param(5, 1), OUT_Param(5, 2))))
Next a
Next x
Next Z
x = 1
Z = 1
For Z = 1 To 50
x=1
For x=1 to 5
Percentile(Z, 1, 1) = Application.WorksheetFunction.Percentile(Application.WorksheetFunction.Index(Output_Table,0,Output_table(1,x,z), 0.9) ' This is where my problem is here. You can see that z is a reference to the depth of the cube, i.e. time horizon 1 to 50.
Next Z
End Sub