# @see http://quantlib.org/reference/_equity_option_8cpp-example.html
# @author Richard Gomes & S. Chekanov
from org.jquantlib import *
from org.jquantlib.exercise import EuropeanExercise,AmericanExercise
from org.jquantlib.instruments import Option,PlainVanillaPayoff,VanillaOption,EuropeanOption
from org.jquantlib.pricingengines.vanilla import BjerksundStenslandApproximationEngine,BaroneAdesiWhaleyApproximationEngine,BaroneAdesiWhaleyApproximationEngine
from org.jquantlib.methods.lattices import *
from org.jquantlib.pricingengines import *
from org.jquantlib.time import Month,Date
from org.jquantlib.time.calendars import Target
from org.jquantlib.daycounters import Actual365Fixed
from org.jquantlib.quotes import SimpleQuote,Handle
from org.jquantlib.termstructures.yieldcurves import FlatForward
from org.jquantlib.termstructures.volatilities import *
from org.jquantlib.processes import *
from org.jquantlib.pricingengines.vanilla import JuQuadraticApproximationEngine
# setup dates
calendar =Target()
todaysDate = Date(15, Month.May, 1998)
settlementDate = Date(17, Month.May, 1998)
Settings().setEvaluationDate(todaysDate)
# options
type=Option.Type.Put
strike = 40
underlying = 36
riskFreeRate = 0.06
volatility = 0.2
dividendYield = 0
maturity = Date(17, Month.May, 1999)
dayCounter = Actual365Fixed()
# Define exercise for European Options and setEvaluationDate(todaysDate);
europeanExercise =EuropeanExercise(maturity)
americanExercise = AmericanExercise(settlementDate, maturity);
payoff = PlainVanillaPayoff(type, strike)
underlyingH = Handle(SimpleQuote(underlying))
flatDividendTS =Handle(FlatForward(settlementDate, dividendYield, dayCounter))
flatTermStructure =Handle(FlatForward(settlementDate, riskFreeRate, dayCounter))
flatVolTS = Handle(BlackConstantVol(settlementDate, calendar, volatility, dayCounter))
bsmProcess = BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS)
# Black-Scholes for European
europeanOption = EuropeanOption(payoff, europeanExercise)
method = "Black-Scholes"
europeanOption.setPricingEngine(AnalyticEuropeanEngine(bsmProcess))
print method, europeanOption.NPV()
Ads help maintain this website.