2017-01-04 7 views
0
で一日を前進させるためにどのように

私の理解で一日を進めるためには、あなたがこのような何かを行うことですオプション:Quantlib

import QuantLib as ql  

# option data 
maturity_date = ql.Date(15, 1, 2016) 
spot_price = 127.62 
strike_price = 130 
volatility = 0.20 # the historical vols for a year 
dividend_rate = 0.0163 
option_type = ql.Option.Call 

risk_free_rate = 0.001 
day_count = ql.Actual365Fixed() 
#calendar = ql.UnitedStates() 
calendar = ql.TARGET() 

calculation_date = ql.Date(8, 5, 2015) 
ql.Settings.instance().evaluationDate = calculation_date 

# construct the European Option 
payoff = ql.PlainVanillaPayoff(option_type, strike_price) 
exercise = ql.EuropeanExercise(maturity_date) 
european_option = ql.VanillaOption(payoff, exercise) 

spot_handle = ql.QuoteHandle(
    ql.SimpleQuote(spot_price) 
) 

flat_ts = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, risk_free_rate, day_count) 
) 

dividend_yield = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, dividend_rate, day_count) 
) 

flat_vol_ts = ql.BlackVolTermStructureHandle(
    ql.BlackConstantVol(calculation_date, calendar, volatility, day_count) 
) 

bsm_process = ql.BlackScholesMertonProcess(spot_handle, 
              dividend_yield, 
              flat_ts, 
              flat_vol_ts) 

european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process)) 
bs_price = european_option.NPV() 
print "The theoretical European price is ", bs_price 

payoff = ql.PlainVanillaPayoff(option_type, strike_price) 
settlement = calculation_date 
am_exercise = ql.AmericanExercise(settlement, maturity_date) 
american_option = ql.VanillaOption(payoff, am_exercise) 

#Once you have the american option object you can value them using the binomial tree method: 

binomial_engine = ql.BinomialVanillaEngine(bsm_process, "crr", 100) 
american_option.setPricingEngine(binomial_engine) 
print "The theoretical American price is ", american_option.NPV()         

ql.Settings.instance().evaluation_date = calculation_date + 1 

print "The theoretical European price is ", european_option.NPV() 
print "The theoretical American price is ", american_option.NPV() 

[[email protected] python]$ python european_option.py 
The theoretical European price is 6.74927181246 
The theoretical American price is 6.85858045945 
The theoretical European price is 6.74927181246 
The theoretical American price is 6.85858045945 
[[email protected] python]$ 

EDITは

は、以下の提案どおりにコードを変更しましたが、一日の変更はcomputatで違いはありませんイオン。

[[email protected] python]$ python advance_day.py 
The theoretical European price is 6.74927181246 
The theoretical American price is 6.85858045945 
The theoretical European price is 6.74927181246 
The theoretical American price is 6.85858045945 
[[email protected] python]$ 

ここでは、提案ごとにコードが変更されています。

import QuantLib as ql  

# option data 
maturity_date = ql.Date(15, 1, 2016) 
spot_price = 127.62 
strike_price = 130 
volatility = 0.20 # the historical vols for a year 
dividend_rate = 0.0163 
option_type = ql.Option.Call 

risk_free_rate = 0.001 
day_count = ql.Actual365Fixed() 
#calendar = ql.UnitedStates() 
calendar = ql.TARGET() 

calculation_date = ql.Date(8, 5, 2015) 
ql.Settings.instance().evaluationDate = calculation_date 

# construct the European Option 
payoff = ql.PlainVanillaPayoff(option_type, strike_price) 
exercise = ql.EuropeanExercise(maturity_date) 
european_option = ql.VanillaOption(payoff, exercise) 

spot_handle = ql.QuoteHandle(
    ql.SimpleQuote(spot_price) 
) 

flat_ts = ql.YieldTermStructureHandle(
    ql.FlatForward(0, calendar, risk_free_rate, day_count) 
) 

dividend_yield = ql.YieldTermStructureHandle(
    ql.FlatForward(0, calendar, dividend_rate, day_count) 
) 

flat_vol_ts = ql.BlackVolTermStructureHandle(
    ql.BlackConstantVol(0, calendar, volatility, day_count) 
) 

bsm_process = ql.BlackScholesMertonProcess(spot_handle, 
              dividend_yield, 
              flat_ts, 
              flat_vol_ts) 

european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process)) 
bs_price = european_option.NPV() 
print "The theoretical European price is ", bs_price 

payoff = ql.PlainVanillaPayoff(option_type, strike_price) 
settlement = calculation_date 
am_exercise = ql.AmericanExercise(settlement, maturity_date) 
american_option = ql.VanillaOption(payoff, am_exercise) 

#Once you have the american option object you can value them using the binomial tree method: 

binomial_engine = ql.BinomialVanillaEngine(bsm_process, "crr", 100) 
american_option.setPricingEngine(binomial_engine) 
print "The theoretical American price is ", american_option.NPV()         

ql.Settings.instance().evaluation_date = calculation_date + 1 
# Also tried calendar.advance(calculation_date,1,ql.Days) 

print "The theoretical European price is ", european_option.NPV() 
print "The theoretical American price is ", american_option.NPV() 

答えて

1

計算日が全てであるとは限りません。参照日付が固定されるように(つまり、日付を取るコンストラクタを呼び出す;詳細についてはthis post、例についてはthis videoを参照)、曲線を設定しています。

基準日を指定すると、計算日とは関係なく使用されます。これは、必ずしも同じではないためです(たとえば、今日の日付ではなく、スポット日付に基づいて金利曲線を設定したい場合など)。したがって、計算日を変更しても、曲線から返されるボラティリティとレートは、依然として移動していない基準日との相対的なものになります。

目的の効果を得るには、評価日とともに移動するようにカーブを作成します。例えば、代わりに

ql.FlatForward(calculation_date, risk_free_rate, day_count) 

のためにあなたは、基準日が計算日として「0営業日計算日後」、または他の言葉で、と指定されていることを意味

ql.FlatForward(0, calendar, risk_free_rate, day_count) 

を使用することができます。ボラティリティ曲線も同様のコンストラクタを持ちます。

+0

私はフォローしていません。元の投稿のEDITセクションを参照してください。 1日の前進と後の出力は同じです。 – Ivan

+0

新しい日付を設定するときは、 'evaluation_date'ではなく' evaluationDate'でなければなりません。私はあまりにも初めてそれを逃した。残念ながら、Pythonはあなたに新しい属性を追加しているだけであることを警告していません...ただし、オリジナルのスクリプトではオプション値は変更されません。 –

+0

私はそれを働かせました。ありがとう! – Ivan

関連する問題