2016-11-23 66 views
0

我創建了一個用戶表單,允許用戶更改涉及定價期權(執行價格,波動率等)的各種變量,並允許用戶更改所需的模擬在價格(或在這種情況下的平均價格)。但是,一旦我點擊OK按鈕,我無法在我的代碼中調用公用潛艇。任何關於我在做什麼錯誤的建議將不勝感激。 [我也包括下面我的用戶表格的照片]使用Simulaitons爲歐洲期權定價

User Form

Option Explicit 
     Private cancel As Boolean 

     Public Function ShowInputsDialog(currentPrice As Single, _ 
     exercisePrice As Single, riskfreeRate As Double, _ 
     volatility As Single, duration As Single, simulation As Double) As Boolean 

    Call Initialize 
    Me.Show 
    If Not cancel Then 

    'Capture the other inputs. 
     currentPrice = txtCurrentPrice.Text 
     exercisePrice = txtExercisePrice.Text 
     riskfreeRate = txtRiskfreeRate.Text 
     volatility = txtVolatility.Text 
     duaration = txtDuration.Text 
     simulation = txtSimulation.Text 

    ShowInputsDialog = Not cancel 
    Unload Me 
    End Function 

    Public Sub ErrorCheck() 
    ' Perform error checking for user inputs. 

    If IsNumeric(currentPrice) = False Or currentPrice < 0 Then 
     MsgBox ("Please enter a numeric value for the Current Price") 
    End If 
    If IsNumeric(exercisePrice) = False Or exercusePrice < 0 Then 
     MsgBox ("Please enter a positive numeric value for the exercise price") 
    End If 
    If IsNumeric(riskfreeRate) = False Then 
     MsgBox ("Please enter a numerical value for the risk-free rate") 
    End If 
    If IsNumeric(volatility) = False Then 
     MsgBox ("Please enter a numerical value for the Standard deviation") 
    End If 
    If IsNumeric(duration) = False Then 
     MsgBox ("Please enter a numerical valye for duration") 
    End If 

    End Sub 

    Public Sub Call_Eur(currentPrice As Single, _ 
     exercisePrice As Single, riskfreeRate As Double, _ 
     volatility As Single, duration As Single, simulation As Double) 
     Dim stockPrice As Single 
     Dim CallcashflowTermination As Single 
     Dim PutcashflowTermination As Single 
     Dim CalldiscountedValue As Double 
     Dim PutdiscountedValue As Double 
     Dim i As Integer 
     Dim CallMean As Double 
     Dim PutMean As Double 
     Dim arrayCallPrice() As Integer 
     Dim arrayPutPrice() As Integer 
    For i = 1 To simulation 
    ' stock price 
    stockPrice = currentPrice * Exp((riskfreeRate - 0.5 * volatility^2) * duration + volatility * Application.WorksheetFunction.Norm_Inv(Rnd(), 0, 1) * Sqr(duration)) 

    ' option cash flow at termination 
    CallcashflowTermination = Application.WorksheetFunction.Max(0, stockPrice - exercisePrice) 
    PutcashflowTerminatio = Application.WorksheetFunction.Funciton.Max(0, exercisePrice - stockPrice) 

    ' discounted value of the option 
    CalldiscountedValue = CallcashflowTermination * Exp(-duration * riskfreeRate) 
    PutdiscountedValue = PutcashflowTermination * Exp(-duration * riskfreeRate) 

    arrayCallPrice(i) = CalldiscountedValue 
    arrayPutPrice(i) = PutdiscountedValue 

    CallMean = Application.WorsheetFunction.Average(arrayCallPrice) 
    PutMean = Application.WorksheetFunction.Average(arrayPutPrice) 

    Next i 

    MsgBox "The Call option price is " & CallMean & " the Put option price is " & PutMean 

End Sub 
Private Sub CmdCancel_Click() 
    Me.Hide 
    cancel = True 
End Sub 

Private Sub CmdOK_Click() '<--- ERROR!!! 
Call Call_Eur(currentPrice As Single, _ 
     exercisePrice As Single, riskfreeRate As Double, _ 
     volatility As Single, duration As Single, simulation As Double) 
End Sub 

Private Sub UserForm_Click() 

End Sub 
+0

您調用Call_Eur的方式是錯誤的語法。調用子程序時,您不必定義參數的類型。 –

+0

@ A.S.H當我沒有定義參數時,它仍然給我一個語法錯誤。我可以用其他方式稱呼它嗎? –

+0

我認爲你需要以不同的方式定義('Dim')變量('exercisePrice','riskfreeRate'等),即全局範圍。 –

回答

0

大紅旗!!!!

enter image description here

當調用的子程序。你需要將值傳遞給它。不重新定義它的參數。

Private Sub CmdOK_Click() '<--- ERROR!!! 
    Call Call_Eur(12.50, 13.43, 14, 33.56, 100, 13.67) 
End Sub 

我更喜歡刪除括號,而不是使用Call。

Private Sub CmdOK_Click() '<--- ERROR!!! 
    Call_Eur 12.50, 13.43, 14, 33.56, 100, 13.67 
End Sub