本文整理汇总了Python中quantlib.instruments.option.VanillaOption.setPricingEngine方法的典型用法代码示例。如果您正苦于以下问题:Python VanillaOption.setPricingEngine方法的具体用法?Python VanillaOption.setPricingEngine怎么用?Python VanillaOption.setPricingEngine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quantlib.instruments.option.VanillaOption
的用法示例。
在下文中一共展示了VanillaOption.setPricingEngine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from quantlib.instruments.option import VanillaOption [as 别名]
# 或者: from quantlib.instruments.option.VanillaOption import setPricingEngine [as 别名]
def main():
# global data
todays_date = Date(15, May, 1998)
Settings.instance().evaluation_date = todays_date
settlement_date = Date(17, May ,1998)
risk_free_rate = FlatForward(
reference_date = settlement_date,
forward = 0.06,
daycounter = Actual365Fixed()
)
# option parameters
exercise = AmericanExercise(
earliest_exercise_date = settlement_date,
latest_exercise_date = Date(17, May, 1999)
)
payoff = PlainVanillaPayoff(Put, 40.0)
# market data
underlying = SimpleQuote(36.0)
volatility = BlackConstantVol(todays_date, TARGET(), 0.20, Actual365Fixed())
dividend_yield = FlatForward(
reference_date = settlement_date,
forward = 0.00,
daycounter = Actual365Fixed()
)
# report
header = '%19s' % 'method' + ' |' + \
' |'.join(['%17s' % tag for tag in ['value',
'estimated error',
'actual error' ] ])
print
print header
print '-'*len(header)
refValue = None
def report(method, x, dx = None):
e = '%.4f' % abs(x-refValue)
x = '%.5f' % x
if dx:
dx = '%.4f' % dx
else:
dx = 'n/a'
print '%19s' % method + ' |' + \
' |'.join(['%17s' % y for y in [x, dx, e] ])
# good to go
process = BlackScholesMertonProcess(
underlying, dividend_yield, risk_free_rate, volatility
)
option = VanillaOption(payoff, exercise)
refValue = 4.48667344
report('reference value',refValue)
# method: analytic
option.set_pricing_engine(BaroneAdesiWhaleyApproximationEngine(process))
report('Barone-Adesi-Whaley',option.net_present_value)
# method: finite differences
time_steps = 801
grid_points = 800
option.set_pricing_engine(FDAmericanEngine('CrankNicolson', process,time_steps,grid_points))
report('finite differences',option.net_present_value)
print 'This is work in progress.'
print 'Some pricing engines are not yet interfaced.'
return
option.set_pricing_engine(BjerksundStenslandEngine(process))
report('Bjerksund-Stensland',option.NPV())
# method: binomial
timeSteps = 801
option.setPricingEngine(BinomialVanillaEngine(process,'jr',timeSteps))
report('binomial (JR)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'crr',timeSteps))
report('binomial (CRR)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'eqp',timeSteps))
report('binomial (EQP)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'trigeorgis',timeSteps))
report('bin. (Trigeorgis)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'tian',timeSteps))
report('binomial (Tian)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'lr',timeSteps))
report('binomial (LR)',option.NPV())