|
From: Luigi B. <lui...@gm...> - 2024-01-26 15:29:03
|
Hi, unfortunately the type for both the vol spreads and the parameter
guesses is a bit clumsy—it's std::vector<std::vector<Handle<Quote>>>.
Before creating the cube you'll have to write
volSpreads = [[ql.QuoteHandle(ql.SimpleQuote(x)) for x in row] for row in
volSpreads]
paramGuesses = [[ql.QuoteHandle(ql.SimpleQuote(x)) for x in row] for row in
[(0.1,0.1,0.1,0.1)] * 6]
after which the following call works:
ql.SabrSwaptionVolatilityCube( swaptionVolHandle,
optionTenors,
swapTenors,
strikeSpreads,
volSpreads,
swapIndexBase,
shortSwapIndexBase,
vegaWeightedSmileFit,
paramGuesses,
(False, False, False, False),
True
)
Hope this helps,
Luigi
On Sat, Dec 23, 2023 at 1:39 AM Renren Dong <dr...@gm...> wrote:
> Hi Quantlib Users,
>
> I am very new to QuantLib and its Python interface, so apologies if this
> was obvious.
>
> I was trying to figure out how to use ql.SabrSwaptionVolatilityCube, I
> can't seem to find a working example on how to work.
>
> Here are the closest I got so far.
>
> many thanks in advance,
> thank you
> -Renren
>
>
>
> optionTenors = ['1y', '2y', '3y']
> swapTenors = [ '5Y', '10Y']
>
> normal_vols = [
> [50, 60],
> [70, 80],
> [90, 95]]
>
> normal_vols = [[vol / 10000 for vol in row] for row in normal_vols]
> swapTenors = [ql.Period(tenor) for tenor in swapTenors]
> optionTenors = [ql.Period(tenor) for tenor in optionTenors]
> normal_vols = [[vol / 10000 for vol in row] for row in normal_vols]
>
>
> calendar = ql.TARGET()
> bdc = ql.ModifiedFollowing
> dayCounter = ql.ActualActual(1)
>
> swaptionVolMatrix = ql.SwaptionVolatilityMatrix(calendar
> , bdc
> , optionTenors
> , swapTenors
> , ql.Matrix(normal_vols)
> , dayCounter
> , False
> , ql.Normal)
>
> swaptionVolHandle = ql.SwaptionVolatilityStructureHandle(swaptionVolMatrix)
>
>
> strikeSpreads = [ -0.01, 0.0, 0.01]
> volSpreads = [
> [0.5, 0.55, 0.6],
> [0.5, 0.55, 0.6],
> [0.5, 0.55, 0.6],
> [0.5, 0.55, 0.6],
> [0.5, 0.55, 0.6],
> [0.5, 0.55, 0.6],
> ]
>
> ###
>
> oisQuote = ql.QuoteHandle(ql.SimpleQuote(0.04))
>
> ytsOis = ql.FlatForward(today, oisQuote, ql.Actual360())
> ytsOis.enableExtrapolation()
> t0_Ois = ql.YieldTermStructureHandle(ytsOis)
>
> swapIndexBase = ql.EuriborSwapIsdaFixA(ql.Period(1, ql.Years), t0_Ois,
> t0_Ois)
> shortSwapIndexBase = ql.EuriborSwapIsdaFixA(ql.Period(1, ql.Years),
> t0_Ois, t0_Ois)
>
>
> ##
> vegaWeightedSmileFit = False
>
> ql.SabrSwaptionVolatilityCube( swaptionVolHandle,
> optionTenors,
> swapTenors,
> strikeSpreads,
> volSpreads,
> swapIndexBase,
> shortSwapIndexBase,
> vegaWeightedSmileFit,
> [(0.1,0.1,0.1,0.1) ] * 6,
> (False, False, False, False),
> True
> )
>
>
>
>
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|