关于处理子数组(多列数组的一列数组)的问题
我将RFR_array(100行,1列)发送给计算折扣率的函数。
我称之为“飞行中”:
for z is 1:100, loop TempArrayR(z, 1) = CreateDiscArray(RFR_array)(z, 1) end for loop
现在我制作一个阵列(100个,4个col)
我指定一个col表示数组的“2”。即,此处选择“USD”或CurrNumber为2,仅使用较大的多货币阵列的第2列来构建折扣因子。找不到合适的代码,在这里
我称之为“飞行中”:
for z is 1:100, loop TempArrayR(z, 1) = CreateDiscArray(RFR_array(,2))(z, 1) end for loop
完整代码如下:
Dim CurrNumber As Double
If Curr = "USD" Then
CurrNumber = 2
ElseIf Curr = "CAD" Then
CurrNumber = 1
ElseIf Curr = "GBP" Then
CurrNumber = 3
ElseIf Curr = "EUR" Then
CurrNumber = 4
End If
Dim RFR_array_one_curr() As Variant
Dim RFR_array() As Variant
Dim q As Integer
For q = 0 To 100 Step 1
If q = 0 Then RFR_array(0, 1) = 0
If q > 0 Then RFR_array(q, 1) = Application.WorksheetFunction.Index(RFR_Array_all, q, CurrNumber - 1)
Next q
RFR_array_one_curr = RFR_array
Dim z As Integer
For z = 0 To zDim Step 1
If z = 0 Then TempArrayR(0, 1) = 1
If z > 0 Then TempArrayR(z, 1) = CreateDiscArray(RFR_array_one_curr)(z, 1)
Next z
Disc_array = TempArrayR
`
CreateDiscArray(RFR_array_one_curr)出错是一个参考错误。
`
Function CreateDiscArray(RFR_array As Range)
' INPUT: a column of risk-free rates one per year [1,100].
Dim MyArray() As Variant
MyArray = RFR_array.Value
Dim xDimRate As Integer
xDimRate = UBound(MyArray, 1)
ReDim TempArray(LBound(MyArray) To UBound(MyArray), LBound(MyArray, 2) To UBound(MyArray, 2)) As Variant
Dim i As Long
For i = 1 To xDimRate Step 1
TempArray(i, 1) = DiscFact(MyArray(i, 1), i)
Next i
CreateDiscArray = TempArray
End Function
`