ByRef argument type mismatch
24.02.2017 11:56:17
Fabian
ich habe folgende Macro geschrieben, wenn ich Sie aktivieren will kommt aber immer ein
"ByRef argument type mismatch" als Fehler. Ich komme einfach nicht drauf, an welchen Stellen es nicht passt.
Besten Dank und ein schönes Wochenende.
Fabian
Option Explicit
Sub IFD()
'Input parameters from worksheet
Dim iMax As Integer: iMax = Range("B3").Value
Dim jMax As Integer: jMax = Range("B2").Value
Dim maturity As Double: maturity = Range("B4").Value
Dim strike As Double: strike = Range("B5").Value
Dim riskFree As Double: riskFree = Range("B6").Value
Dim sigma As Double: sigma = Range("B7").Value
Dim dprice As Double: dprice = Range("B8").Value
Dim qcontract As Double: qcontract = Range("B10").Value
Dim knock As Double: knock = Range("B11").Value
Dim settle As Double: settle = Range("B12").Value
'Perform the matrix calculation
Dim Fvec() As Double: ReDim Fvec(0 To jMax)
Call CalAccumulatorPrices(knock, settle, qcontract, maturity, strike, riskFree, sigma, iMax, _
jMax, dprice, Fvec())
'Put results back to worksheet
Dim i As Integer
For i = 0 To jMax: Range("C15").Offset(i, 0) = Fvec(i): Next i
End Sub
Sub CalAccumulatorPrices(knock As Double, settle As Double, qcontract As Double, maturity As _
Double, strike As Double, riskFree As Double, sigma As Double, _
iMax As Integer, jMax As Integer, dprice As Double, ByRef Fvec() As Double)
Dim dtime As Double: dtime = maturity / iMax
Dim Lr As Integer
Dim i As Integer
Dim CIRsigma As Double: CIRsigma = sigma * (Lr * dprice) ^ 1 / 2
'Construct the matrix P and Q
Dim Pmatrix() As Double: ReDim Pmatrix(0 To jMax, 0 To jMax)
Dim Qmatrix() As Double: ReDim Qmatrix(0 To jMax, 0 To jMax)
Pmatrix(0, 0) = Exp(riskFree * dtime)
Pmatrix(jMax, jMax) = 1
Qmatrix(0, 0) = 0
Qmatrix(jMax, jMax) = 1
For Lr = 1 To jMax - 1
Pmatrix(Lr, Lr - 1) = 0.25 * ((Lr * riskFree * dtime) - (Lr ^ 2 * CIRsigma ^ 2 * dtime))
Pmatrix(Lr, Lr) = 1 + 0.5 * (riskFree * dtime) + (Lr ^ 2 * CIRsigma ^ 2 * dtime)
Pmatrix(Lr, Lr + 1) = -0.25 * ((Lr * riskFree * dtime) + (Lr ^ 2 * CIRsigma ^ 2 * dtime))
Next Lr
For Lr = 1 To jMax - 1
Qmatrix(Lr, Lr - 1) = -0.25 * ((Lr * riskFree * dtime) - (Lr ^ 2 * CIRsigma ^ 2 * dtime))
Qmatrix(Lr, Lr) = 1 - 0.5 * (riskFree * dtime) + (Lr ^ 2 * CIRsigma ^ 2 * dtime)
Qmatrix(Lr, Lr + 1) = 0.25 * ((Lr * riskFree * dtime) + (Lr ^ 2 * CIRsigma ^ 2 * dtime))
Next Lr
'Initialize the option vector according to the payoff condition
For Lr = 0 To jMax: Fvec(Lr) = Payoff(Lr * dprice, strike) * qcontract: Next Lr
'Perform the iteration
For i = 1 To iMax
Call SolveAxb(Pmatrix, Qmatrix, Fvec, Fvec, jMax + 1, 0, 0, 0)
Call Boundary(Fvec, jMax, dprice, knock, settle)
Next i
End Sub
'Put option payoff condition
Function Payoff(strike As Double, price As Double) As Double
Payoff = (price - strike)
End Function
'Accumulator settlement day and knock out feature
Sub Boundary(ByRef Fvec() As Double, i As Integer, knock As Double, jMax As Integer, settle As _
Double, dprice As Double)
Dim Lr As Integer
Dim ReferenceV As Double: ReferenceV = iMax / settle
If (i Mod ReferenceV) = 0 Then
Lr = 0
Do While Lr = knock Then
Fvec(Lr) = 0
End If
Lr = Lr + 1
Loop
End If
End Sub