Skip to content

Commit

Permalink
Export makeQuoteHandle convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Apr 3, 2024
1 parent d56825f commit 7544046
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Python/examples/bermudan-swaption.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def calibrate(model, helpers, l, name):

# This is a flat yield term structure implying a 1x5 swap at 5%.

rate = ql.QuoteHandle(ql.SimpleQuote(0.04875825))
rate = ql.makeQuoteHandle(0.04875825)
termStructure = ql.YieldTermStructureHandle(ql.FlatForward(settlementDate, rate, ql.Actual365Fixed()))

# Define the ATM/OTM/ITM swaps:
Expand Down Expand Up @@ -151,7 +151,7 @@ def calibrate(model, helpers, l, name):
ql.SwaptionHelper(
maturity,
length,
ql.QuoteHandle(ql.SimpleQuote(vol)),
ql.makeQuoteHandle(vol),
index,
index.tenor(),
index.dayCounter(),
Expand Down
8 changes: 4 additions & 4 deletions Python/examples/bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

zcHelpers = [
ql.DepositRateHelper(
ql.QuoteHandle(ql.SimpleQuote(r)), tenor, fixingDays, calendar, ql.ModifiedFollowing, True, zcBondsDayCounter
ql.makeQuoteHandle(r), tenor, fixingDays, calendar, ql.ModifiedFollowing, True, zcBondsDayCounter
)
for (r, tenor) in zcQuotes
]
Expand Down Expand Up @@ -98,7 +98,7 @@
)
bondsHelpers.append(
ql.FixedRateBondHelper(
ql.QuoteHandle(ql.SimpleQuote(marketQuote)),
ql.makeQuoteHandle(marketQuote),
settlementDays,
100.0,
schedule,
Expand Down Expand Up @@ -139,7 +139,7 @@
depositDayCounter = ql.Actual360()
depositHelpers = [
ql.DepositRateHelper(
ql.QuoteHandle(ql.SimpleQuote(rate)), tenor, fixingDays, calendar, ql.ModifiedFollowing, True, depositDayCounter
ql.makeQuoteHandle(rate), tenor, fixingDays, calendar, ql.ModifiedFollowing, True, depositDayCounter
)
for rate, tenor in dQuotes
]
Expand All @@ -151,7 +151,7 @@
forwardStart = ql.Period(1, ql.Days)
swapHelpers = [
ql.SwapRateHelper(
ql.QuoteHandle(ql.SimpleQuote(rate)),
ql.makeQuoteHandle(rate),
tenor,
calendar,
swFixedLegFrequency,
Expand Down
2 changes: 1 addition & 1 deletion Python/examples/capsfloors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

strike = 0.02
cap = ql.Cap(ibor_leg, [strike])
vols = ql.QuoteHandle(ql.SimpleQuote(0.547295))
vols = ql.makeQuoteHandle(0.547295)
engine = ql.BlackCapFloorEngine(ts_handle, vols)
cap.setPricingEngine(engine)
print("Value of Caps given constant volatility:", cap.NPV())
2 changes: 1 addition & 1 deletion Python/examples/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

instruments = [
ql.SpreadCdsHelper(
ql.QuoteHandle(ql.SimpleQuote(s)),
ql.makeQuoteHandle(s),
tenor,
0,
calendar,
Expand Down
18 changes: 9 additions & 9 deletions Python/examples/gaussian1d-models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def calibration_data(basket, volatilities):
# For the volatility we assume a flat swaption volatility at 20%.

# %%
forward6mQuote = ql.QuoteHandle(ql.SimpleQuote(0.025))
oisQuote = ql.QuoteHandle(ql.SimpleQuote(0.02))
volQuote = ql.QuoteHandle(ql.SimpleQuote(0.2))
forward6mQuote = ql.makeQuoteHandle(0.025)
oisQuote = ql.makeQuoteHandle(0.02)
volQuote = ql.makeQuoteHandle(0.2)

# %%
dc = ql.Actual365Fixed()
Expand Down Expand Up @@ -172,8 +172,8 @@ def calibration_data(basket, volatilities):

# %%
stepDates = exerciseDates[:-1]
sigmas = [ql.QuoteHandle(ql.SimpleQuote(0.01)) for x in range(1, 10)]
reversion = [ql.QuoteHandle(ql.SimpleQuote(0.01))]
sigmas = [ql.makeQuoteHandle(0.01) for x in range(1, 10)]
reversion = [ql.makeQuoteHandle(0.01)]

# %% [markdown]
# The model's curve is set to the 6m forward curve. Note that the model adapts automatically to other curves where appropriate (e.g. if an index requires a different forwarding curve) or where explicitly specified (e.g. in a swaption pricing engine).
Expand All @@ -182,7 +182,7 @@ def calibration_data(basket, volatilities):
gsr = ql.Gsr(t0_curve, stepDates, sigmas, reversion)
swaptionEngine = ql.Gaussian1dSwaptionEngine(gsr, 64, 7.0, True, False, t0_Ois)
nonstandardSwaptionEngine = ql.Gaussian1dNonstandardSwaptionEngine(
gsr, 64, 7.0, True, False, ql.QuoteHandle(ql.SimpleQuote(0)), t0_Ois)
gsr, 64, 7.0, True, False, ql.makeQuoteHandle(0.0), t0_Ois)

# %%
swaption.setPricingEngine(nonstandardSwaptionEngine)
Expand Down Expand Up @@ -370,7 +370,7 @@ def calibration_data(basket, volatilities):
# %%
swaption4 = ql.FloatFloatSwaption(underlying4, exercise)
floatSwaptionEngine = ql.Gaussian1dFloatFloatSwaptionEngine(
gsr, 64, 7.0, True, False, ql.QuoteHandle(ql.SimpleQuote(0)), t0_Ois, True)
gsr, 64, 7.0, True, False, ql.makeQuoteHandle(0.0), t0_Ois, True)
swaption4.setPricingEngine(floatSwaptionEngine)

# %% [markdown]
Expand All @@ -379,7 +379,7 @@ def calibration_data(basket, volatilities):
# %%
leg0 = underlying4.leg(0)
leg1 = underlying4.leg(1)
reversionQuote = ql.QuoteHandle(ql.SimpleQuote(0.01))
reversionQuote = ql.makeQuoteHandle(0.01)
swaptionVolHandle = ql.SwaptionVolatilityStructureHandle(swaptionVol)
cmsPricer = ql.LinearTsrPricer(swaptionVolHandle, reversionQuote)
iborPricer = ql.BlackIborCouponPricer()
Expand Down Expand Up @@ -445,7 +445,7 @@ def calibration_data(basket, volatilities):

# %%
floatEngineMarkov = ql.Gaussian1dFloatFloatSwaptionEngine(
markov, 16, 7.0, True, False, ql.QuoteHandle(ql.SimpleQuote(0)), t0_Ois, True)
markov, 16, 7.0, True, False, ql.makeQuoteHandle(0.0), t0_Ois, True)

# %% [markdown]
# The option npv is the markov model is:
Expand Down
2 changes: 1 addition & 1 deletion Python/examples/isda-engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@

probabilityCurve.linkTo(
ql.FlatHazardRate(0,ql.WeekendsOnly(),
ql.QuoteHandle(ql.SimpleQuote(h)),
ql.makeQuoteHandle(h),
ql.Actual365Fixed()))

engine = ql.IsdaCdsEngine(probabilityCurve,recovery,discountCurve)
Expand Down
2 changes: 1 addition & 1 deletion Python/examples/slv.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
dc = ql.Actual365Fixed()

spot = 100
underlying = ql.QuoteHandle(ql.SimpleQuote(spot))
underlying = ql.makeQuoteHandle(spot)

riskFreeRate = ql.YieldTermStructureHandle(ql.FlatForward(settlementDate, 0.05, dc))
dividendYield = ql.YieldTermStructureHandle(ql.FlatForward(settlementDate, 0.025, dc))
Expand Down
2 changes: 1 addition & 1 deletion Python/examples/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
ql.ModifiedFollowing,
True,
dayCounter,
ql.QuoteHandle(ql.SimpleQuote(0.0)),
ql.makeQuoteHandle(0.0),
)
for d in futures.keys()
]
Expand Down
4 changes: 2 additions & 2 deletions Python/test/test_americanquantooption.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def testAmericanBSQuantoOption(self):
volTS = ql.BlackConstantVol(self.today, ql.TARGET(), 0.3, self.dc)

bsmProcess = ql.BlackScholesMertonProcess(
ql.QuoteHandle(ql.SimpleQuote(100)),
ql.makeQuoteHandle(100),
ql.YieldTermStructureHandle(self.divYieldTS),
ql.YieldTermStructureHandle(self.domesticTS),
ql.BlackVolTermStructureHandle(volTS))
Expand All @@ -81,7 +81,7 @@ def testAmericanHestonQuantoOption(self):
ql.HestonProcess(
ql.YieldTermStructureHandle(self.domesticTS),
ql.YieldTermStructureHandle(self.divYieldTS),
ql.QuoteHandle(ql.SimpleQuote(100)),
ql.makeQuoteHandle(100),
0.09, 1.0, 0.09, 1e-4, 0.0))

fdmHestonVanillaEngine = ql.FdHestonVanillaEngine(
Expand Down
2 changes: 1 addition & 1 deletion Python/test/test_assetswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setUp(self):
self.swaptionVolatilityStructure = ql.SwaptionVolatilityStructureHandle(
ql.ConstantSwaptionVolatility(self.today, ql.NullCalendar(), ql.Following, 0.2, ql.Actual365Fixed())
)
self.meanReversionQuote = ql.QuoteHandle(ql.SimpleQuote(0.01))
self.meanReversionQuote = ql.makeQuoteHandle(0.01)
self.cmspricer = ql.AnalyticHaganPricer(
self.swaptionVolatilityStructure, ql.GFunctionFactory.Standard, self.meanReversionQuote
)
Expand Down
5 changes: 2 additions & 3 deletions Python/test/test_capfloor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def setUp(self):
self.cap = ql.Cap(self.ibor_leg, [self.strike])
self.cap_npv = 8.54

self.black_vol = ql.QuoteHandle(ql.SimpleQuote(0.6))
self.black_vol = ql.makeQuoteHandle(0.6)

def tearDown(self):
ql.Settings.instance().evaluationDate = ql.Date()
Expand Down Expand Up @@ -94,8 +94,7 @@ def testBachelierCapFloorEngine(self):

bpvol = self.black_vol.value() * self.flat_forward_rate
bachelier_engine = ql.BachelierCapFloorEngine(self.term_structure_handle,
ql.QuoteHandle(
ql.SimpleQuote(bpvol)))
ql.makeQuoteHandle(bpvol))

self.cap.setPricingEngine(bachelier_engine)

Expand Down
8 changes: 4 additions & 4 deletions Python/test/test_cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
ql.Settings.instance().evaluationDate = self.referenceDate
self.termStructure = ql.RelinkableYieldTermStructureHandle()
self.termStructure.linkTo(
ql.FlatForward(self.referenceDate, ql.QuoteHandle(ql.SimpleQuote(0.05)), ql.Actual365Fixed())
ql.FlatForward(self.referenceDate, ql.makeQuoteHandle(0.05), ql.Actual365Fixed())
)
self.yieldCurveModels = []
self.numericalPricers = []
Expand Down Expand Up @@ -95,7 +95,7 @@ def setUp(self):
for i in range(self.nRows):
self.volSpreadsRow = []
for j in range(self.nCols):
self.volSpreadsRow.append(ql.QuoteHandle(ql.SimpleQuote(self.volSpreadsMatrix[i][j])))
self.volSpreadsRow.append(ql.makeQuoteHandle(self.volSpreadsMatrix[i][j]))
self.volSpreads.append(self.volSpreadsRow)

self.iborIndex = ql.Euribor6M(self.termStructure)
Expand Down Expand Up @@ -133,7 +133,7 @@ def setUp(self):
for i in range(self.nRows):
self.guessRow = []
for j in range(4):
self.guessRow.append(ql.QuoteHandle(ql.SimpleQuote(self.guessMatrix[i][j])))
self.guessRow.append(ql.makeQuoteHandle(self.guessMatrix[i][j]))
self.guess.append(self.guessRow)

self.isParameterFixed = [False, True, False, False]
Expand Down Expand Up @@ -164,7 +164,7 @@ def setUp(self):
ql.GFunctionFactory.NonParallelShifts,
]

self.zeroMeanRev = ql.QuoteHandle(ql.SimpleQuote(0.0))
self.zeroMeanRev = ql.makeQuoteHandle(0.0)

self.numericalPricers = {}
self.analyticPricers = {}
Expand Down
2 changes: 1 addition & 1 deletion Python/test/test_coupons.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

def flat_rate(rate):
return ql.FlatForward(
2, CAL, ql.QuoteHandle(ql.SimpleQuote(rate)), ql.Actual365Fixed())
2, CAL, ql.makeQuoteHandle(rate), ql.Actual365Fixed())


def create_ibor_leg(ibor_idx, start, end, payment_lag=0):
Expand Down
4 changes: 2 additions & 2 deletions Python/test/test_equityindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

def flat_rate(rate):
return ql.FlatForward(
2, CAL, ql.QuoteHandle(ql.SimpleQuote(rate)), DCT)
2, CAL, ql.makeQuoteHandle(rate), DCT)


class EquityIndexTest(unittest.TestCase):
Expand All @@ -37,7 +37,7 @@ def setUp(self):

self.interest_handle = ql.YieldTermStructureHandle(flat_rate(0.03))
self.dividend_handle = ql.YieldTermStructureHandle(flat_rate(0.01))
spot_handle = ql.QuoteHandle(ql.SimpleQuote(8690.0))
spot_handle = ql.makeQuoteHandle(8690.0)

ql.IndexManager.instance().clearHistory("eq_idx")
self.equity_idx = ql.EquityIndex(
Expand Down
4 changes: 2 additions & 2 deletions Python/test/test_fdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def testAmericanOptionPricing(self):

exercise = ql.AmericanExercise(todaysDate, maturityDate)

spot = ql.QuoteHandle(ql.SimpleQuote(100.0))
spot = ql.makeQuoteHandle(100.0)
volatility = ql.BlackConstantVol(todaysDate, ql.TARGET(), 0.20, dc)

process = ql.BlackScholesMertonProcess(
Expand Down Expand Up @@ -522,7 +522,7 @@ def testBSMRNDCalculator(self):
s0 = 100

process = ql.BlackScholesMertonProcess(
ql.QuoteHandle(ql.SimpleQuote(s0)),
ql.makeQuoteHandle(s0),
ql.YieldTermStructureHandle(
ql.FlatForward(todaysDate, q, dc)),
ql.YieldTermStructureHandle(
Expand Down
2 changes: 1 addition & 1 deletion Python/test/test_inflation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_inflation_swap_helper(
business_day_convention=BDC,
day_counter=DAY_COUNTER):
maturity = CAL.advance(reference_date, inflation_data[0])
quote = ql.QuoteHandle(ql.SimpleQuote(inflation_data[1]))
quote = ql.makeQuoteHandle(inflation_data[1])
return ql.ZeroCouponInflationSwapHelper(
quote,
observation_lag,
Expand Down
4 changes: 2 additions & 2 deletions Python/test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def testFdHestonHullWhite(self):
a = 0.00883
sig = 0.00631

underlying = ql.QuoteHandle(ql.SimpleQuote(s0))
underlying = ql.makeQuoteHandle(s0)

option = ql.VanillaOption(
ql.PlainVanillaPayoff(ql.Option.Call, s0),
Expand Down Expand Up @@ -86,7 +86,7 @@ def testAnalyticHestonHullWhite(self):
expected = 40.028973

s0 = 100
underlying = ql.QuoteHandle(ql.SimpleQuote(s0))
underlying = ql.makeQuoteHandle(s0)

hull_white_model = ql.HullWhite(r, a, sig)
heston_model = ql.HestonModel(
Expand Down
20 changes: 10 additions & 10 deletions Python/test/test_ratehelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):
self.settlement_days = 3
self.face_amount = 100.0
self.redemption = 100.0
self.quote_handle = ql.QuoteHandle(ql.SimpleQuote(100.0))
self.quote_handle = ql.makeQuoteHandle(100.0)

self.issue_date = ql.Date(2, 1, 2008)
self.maturity_date = ql.Date(2, 1, 2018)
Expand Down Expand Up @@ -339,7 +339,7 @@ def build_pln_fx_swap_curve(self, base_ccy_yts, fx_swaps, fx_spot):

fxSwapHelpers = [
ql.FxSwapRateHelper(
ql.QuoteHandle(ql.SimpleQuote(fx_swaps[(n, unit)])),
ql.makeQuoteHandle(fx_swaps[(n, unit)]),
ql.QuoteHandle(spotFx),
ql.Period(n, unit),
spot_date_lag,
Expand Down Expand Up @@ -482,8 +482,8 @@ def testFxMarketConventionsForCrossRateONPeriod(self):
# Settlement should be on a day where all three centers are operating
# and follow EndOfMonth rule
on_rate_helper = ql.FxSwapRateHelper(
ql.QuoteHandle(ql.SimpleQuote(fwd_points)),
ql.QuoteHandle(ql.SimpleQuote(self.fx_spot_quote_EURPLN)),
ql.makeQuoteHandle(fwd_points),
ql.makeQuoteHandle(self.fx_spot_quote_EURPLN),
on_period,
fixing_days,
joint_calendar,
Expand Down Expand Up @@ -546,8 +546,8 @@ def testFxMarketConventionsForDatesInEURUSD_ON_Period(self):
trading_calendar = ql.UnitedStates(ql.UnitedStates.GovernmentBond)

on_rate_helper = ql.FxSwapRateHelper(
ql.QuoteHandle(ql.SimpleQuote(fwd_points)),
ql.QuoteHandle(ql.SimpleQuote(self.fx_spot_quote_EURUSD)),
ql.makeQuoteHandle(fwd_points),
ql.makeQuoteHandle(self.fx_spot_quote_EURUSD),
on_period,
fixing_days,
calendar,
Expand Down Expand Up @@ -586,8 +586,8 @@ def testFxMarketConventionsForDatesInEURUSD_ShortEnd(self):
trading_calendar = ql.UnitedStates(ql.UnitedStates.GovernmentBond)

rate_helper = ql.FxSwapRateHelper(
ql.QuoteHandle(ql.SimpleQuote(fwd_points)),
ql.QuoteHandle(ql.SimpleQuote(self.fx_spot_quote_EURUSD)),
ql.makeQuoteHandle(fwd_points),
ql.makeQuoteHandle(self.fx_spot_quote_EURUSD),
period,
fixing_days,
calendar,
Expand All @@ -606,7 +606,7 @@ def tearDown(self):

def flat_rate(rate):
return ql.FlatForward(
0, ql.NullCalendar(), ql.QuoteHandle(ql.SimpleQuote(rate)), ql.Actual365Fixed())
0, ql.NullCalendar(), ql.makeQuoteHandle(rate), ql.Actual365Fixed())


class CrossCurrencyBasisSwapRateHelperTest(unittest.TestCase):
Expand Down Expand Up @@ -649,7 +649,7 @@ def buildRateHelper(
is_fx_base_ccy_collateral_ccy,
is_basis_on_fx_base_ccy_leg):
tenor, rate = quote_tuple
quote_handle = ql.QuoteHandle(ql.SimpleQuote(rate * self.basis_point))
quote_handle = ql.makeQuoteHandle(rate * self.basis_point)
return ql.ConstNotionalCrossCurrencyBasisSwapRateHelper(
quote_handle,
tenor,
Expand Down
2 changes: 1 addition & 1 deletion Python/test/test_slv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
self.dc = ql.Actual365Fixed()
self.riskFreeRate = ql.YieldTermStructureHandle(ql.FlatForward(self.settlementDate, 0.05, self.dc))
self.dividendYield = ql.YieldTermStructureHandle(ql.FlatForward(self.settlementDate, 0.025, self.dc))
self.underlying = ql.QuoteHandle(ql.SimpleQuote(100.0))
self.underlying = ql.makeQuoteHandle(100.0)

def tearDown(self):
ql.Settings.instance().evaluationDate = ql.Date()
Expand Down
Loading

0 comments on commit 7544046

Please sign in to comment.