1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Dim impvol(IV(0).Count) As Double
Dim predictors1 As Double()() = New Double(2)() {} ' MN,DTE
Dim predictors2 As Double()() = New Double(2)() {} ' STRIKE,DTE
Try
For i = 1 To MN(0).Count
predictors1(i) = New Double() {CType(MN(0).Item(i), Double), CType(IV(0).Item(i), Double)}
Next
For i = 1 To Strike(0).Count
predictors2(i) = New Double() {CType(Strike(0).Item(i), Double), CType(IV(0).Item(i), Double)}
Next
For i = 1 To UBound(impvol)
impvol(i) = CType(IV(0).Item(i), Double)
Next
Catch exc As Exception
MessageBox.Show("Conversion Error (Vol Surface)")
Exit Sub
End Try
' Model Surface is Y = a + bX1 + cX2 + dX1X2 + eX1^2 + fX2^2
' The following inline model functions are needed here to regress the 3D surface
'Dim p0 As Func(Of Double, Double) = Function(x) 1
'Dim p1 As Func(Of Double, Double) = Function(x) x
'Dim p2 As Func(Of Double(), Double) = Function(x) x(1) * x(2)
'Dim p3 As Func(Of Double, Double) = Function(x) x ^ 2
Dim p0 = Function(x As Double) 1
Dim p1 = Function(x As Double) x
Dim p2 = Function(x As Double, y As Double) x * y
Dim p3 = Function(x As Double) x ^ 2
Dim regparams1() As Double = MathNet.Numerics.Fit.LinearMultiDim(predictors1, impvol,
p0, p1(predictors1(0)), p1(predictors1(1)), p2(predictors1(0), predictors1(1)), p3(predictors1(0)), p3(predictors1(1)))
Dim regparams() As Double = MathNet.Numerics.Fit.LinearMultiDim(predictors1, impvol, Numerics.LinearRegression.DirectRegressionMethod.QR) |
Partager