2017-01-04 3 views
0

Mein Verständnis ist, voraus, dass, um den Tag zu fördern, können Sie etwas tun:, wie der Tag in quantlib

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

Allerdings, wenn ich den folgenden Code ausführen, erhalte ich den gleichen Wert für die Optionen:

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

den Code geändert, wie pro unten vorgeschlagen, aber der Tag Änderung keinen Unterschied in der Computat macht Ion.

[[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]$ 

Hier sind die Codeänderungen nach den Vorschlägen.

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() 

Antwort

1

Das Datum der Berechnung ist nicht alles, was es ist. Sie richten Ihre Kurven so ein, dass ihr Referenzdatum fest ist (dh, Sie rufen den Konstruktor auf, der ein Datum entgegennimmt, siehe this post für Details oder this video für ein Beispiel).

Wenn Sie ein Referenzdatum angeben, wird dieses unabhängig vom Berechnungsdatum verwendet. Das liegt daran, dass sie nicht unbedingt identisch sind (z. B. möchten Sie, dass eine Zinskurve auf dem Kassatag statt auf dem heutigen Datum basiert). Selbst wenn Sie das Berechnungsdatum ändern, bleiben die Volatilität und die Renditen, die von den Kurven zurückgegeben werden, immer noch relativ zu ihrem Referenzdatum, das sich nicht bewegt hat.

Um den gewünschten Effekt zu erhalten, können Sie die Kurven so erstellen, dass sie sich mit dem Bewertungsdatum bewegen. zum Beispiel, statt

ql.FlatForward(calculation_date, risk_free_rate, day_count) 

können Sie

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

verwenden, was bedeutet, dass das Referenzdatum als „0 Werktag nach dem Rechnungsdatum“ angegeben ist, oder in anderen Worten, wie Berechnungstag . Die Volatilitätskurve hat einen ähnlichen Konstruktor.

+0

Ich folge nicht. Siehe den EDIT-Abschnitt im ursprünglichen Post. Die Ausgabe vor und nach dem Vorrücken des Tages ist gleich. – Ivan

+0

Wenn Sie das neue Datum einstellen, sollte es 'evaluationDate', nicht' evaluation_date' sein. Ich habe es auch beim ersten Mal vermisst. Unglücklicherweise warnt Python Sie nicht, dass Sie nur ein neues Attribut hinzufügen ... Das Problem, die Referenzdaten der Kurven nicht zu korrigieren, gilt trotzdem: Mit Ihrem ursprünglichen Skript würden sich die Optionswerte nicht ändern. –

+0

Ich habe es zur Arbeit gebracht. Vielen Dank! – Ivan