Login  Register

Re: How to price the arithmetic option using python quantlib

Posted by Luigi Ballabio on Apr 18, 2017; 1:00pm
URL: http://quantlib.414.s1.nabble.com/How-to-price-the-arithmetic-option-using-python-quantlib-tp18180p18198.html

Hello,
    thanks for bringing this up.  There's a couple of things we should fix with the engine.  In the meantime:ut 

First, the discrete Asian option calculates the average price (the one that goes into the payoff) at a number of fixings dates specified by the contract. The Monte Carlo engine needs at least one of them to be in the future, otherwise everything is determined and there's no point in doing a Monte Carlo simulation. However, trying the calculation with missing fixing dates should raise an exception, not crash the program. We'll try to fix that in a future release, but in the meantime, passing a sensible list of dates will cause the calculation to succeed.

Second: depending on whether you use the Arithmetic or Geometric engine (it's not clear from your example) you'll need a different runningAccumulator value.  The Arithmetic average adds the fixings, so you need a starting value of 0; the Geometric average multiplies the fixings, so you need to start from 1 (a 0 will cause the NPV to be null). This, too, could be improved, meaning that when there's no past fixings the correct value should be chosen by the engine; but in the meantime, you can specify it yourself.

Luigi


On Tue, Apr 18, 2017 at 11:58 AM floatwing <[hidden email]> wrote:
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()



--
View this message in context: http://quantlib.10058.n7.nabble.com/How-to-price-the-arithmetic-option-using-python-quantlib-tp18180p18196.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users