私は、コールオプションの価格を、必要な条件下でBlack-Scholes式を使用して明示的に計算するプログラムを作成しています。コードを実行するとエラーが発生します。ValueError:数学的なドメインエラー - Black-Scholesオプション評価
何が原因なのかよく分かりません。してください、すべての助けは非常に大いに感謝しています。
## This program is to perform an explicit Black-Scholes hedge using the formula:
##
## If a stock has a constant volatility of 18% and constant drift of 8%, with
## continuously compounded interest rates constant at 6%, what is the value of
## an option to buy the stock for $25 in two years time, given a current stock
## price of $20?
##
## The description fits the Black-Scholes conditions. Thus, using s = 20, k = $25,
## sigma = 0.18, r = 0.06, and t= 2, we can calculate V_0 = $1.221. We will verify
## that this result is correct:
##
import numpy as np
from math import exp, log
from scipy.stats import norm
import matplotlib.pyplot as plt
# Parameters
s = 20 # current stock price
k = 25 #strike price of the option in dollars
sigma = 0.18 # constant volatility
r = 0.06 # constant interest rate
T = 2 # expiry date of contract, 2 years time
def V(s,T):
return s * norm.cdf((log(s/k) + (r + 0.5 * pow(sigma,2)) * T)/(sigma * np.sqrt(T)))
- k * exp(-r * T) * norm.cdf( (log(s/k) + (r - 0.5 * pow(sigma,2.0)) * T)/(sigma * np.sqrt(T)))
V_0 = V(s,T) # the value of our option at time t=0 is the same at expiry T
print V_0
これは私が自分のコードを実行したときに、私が得るものである:ここで、これまでに私のコードです「とValueError:数学ドメインエラー」と、それは私が定義された関数の値を返す行を指します。ありがとう!
通常、負の数のログをとっているときにエラーが発生します。すべての値をチェックして、各関数に正しいドメインを使用していることを確認してください。 –
'log(s/k)= log(0.8)'です。しかし、ありがとうございました – Javier
他の機能の1つがドメイン外の入力を受信している可能性があります。負の数の平方根(あなたのようには見えませんが)でもそのエラーが発生します。 'scipy'パッケージの' norm.cdf'については分かりませんが、ドメイン制限があるかもしれません。 –