Re: How to price the arithmetic option using python quantlib
Posted by floatwing on Apr 18, 2017; 7:39am
URL: http://quantlib.414.s1.nabble.com/How-to-price-the-arithmetic-option-using-python-quantlib-tp18180p18196.html
Thank you for your reply first! I am not asking for the next step. I mean there might be argument errors in the MCDiscreteGeometricAPEngine function(the arguments the function needs is hard to find in python), event when i set the fixingDates = [Date(30,12,2017)] for example.By the way, what does 'fixingDates' mean? I will attatch the new code to the poster, can you have a check what's wrong to my code?It result in the python kernel died.Codes are as follows:
from QuantLib import *
import matplotlib.pyplot as plt
#global data
stday = 12
stmonth = March
styear = 2017
todaysDate = Date(stday, stmonth, styear)
Settings.instance().evaluationDate = todaysDate
calendar = China()
dayCounter = Actual365Fixed()
settlementDate = todaysDate
riskFreeRate = FlatForward(settlementDate, 0.035, dayCounter)
#option parameters
edday = 28
edmonth = March
edyear = 2017
K = 8
exercise = EuropeanExercise(Date(edday, edmonth, edyear))
payoff = PlainVanillaPayoff(Option.Call, K)
#market data
underlying = SimpleQuote(9)
volatility = BlackConstantVol(todaysDate, calendar, 0.20, dayCounter)
dividendYield = FlatForward(settlementDate, 0.001, dayCounter)
process1 = BlackScholesMertonProcess(QuoteHandle(underlying),
YieldTermStructureHandle(dividendYield),
YieldTermStructureHandle(riskFreeRate),
BlackVolTermStructureHandle(volatility))
process2 = GeneralizedBlackScholesProcess(QuoteHandle(underlying),
YieldTermStructureHandle(dividendYield),
YieldTermStructureHandle(riskFreeRate),
BlackVolTermStructureHandle(volatility))
#asian settings
#try:
averageType = Average().Arithmetic
runningAccumulator = 0
pastFixings = 0
fixingDates = [settlementDate]
option = DiscreteAveragingAsianOption(averageType, runningAccumulator,
pastFixings,
fixingDates,
payoff,
exercise)
stepPerYear = 12
MCstr = 'PseudoRandom'
isBB = True
isAV = True
isCV = True
nrequire = 10000
tolerance = 0.0002
nmax = 15000
seed = 100
seednum = LecuyerUniformRng(1000).next().value()
priceEngine1 = MCDiscreteArithmeticAPEngine(process2, MCstr, isBB, isAV, isCV, nrequire, tolerance, nmax, seed)
priceEngine2 = MCDiscreteGeometricAPEngine(process2, MCstr, isBB, isAV, 100,0.005, 150, 50)# may need a argument(maxTimeStepsPerYear)
option.setPricingEngine(priceEngine2)
print option.delta()