2016-11-23 6 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

変数( 'exercisePrice'、' riskfreeRate'など)を別の方法で、つまりグローバルスコープとして定義( 'Dim')する必要があると思います。 –

答えて

0

BIG RED FLAG [Iはまた、以下の私のユーザーフォームの画像が含まれている] !!!!

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 
関連する問題