|
From: Luigi B. <lui...@gm...> - 2024-01-16 10:38:17
|
Hello,
it looks like it should work, but I can't really try your code since
it's missing a few bits (the code for build_ql_schedule and
schedule_builder.build_schedule). Any chance you can provide a runnable
example? Thanks!
Luigi
On Mon, Dec 18, 2023 at 12:39 AM Chilamakuri, Pavani <Chi...@eb...>
wrote:
> OFFICIAL USE
>
>
>
> Having issues instantiating a Vanilla swap using ql.VanillaSwap. I read
> online and tried ql.Actual365Fixed() as well as
> q.Actual365Fixed(q.Actual365Fixed.Standard). Not sure if the daycounter is
> the problem or the EUR3M_index. I also tried index_curve_handle and no
> luck. My goal is to get the par swap rate.
>
> I cannot seem to find a resolution and no idea exactly which argument to
> ql.ValillaSwap has the problem:
>
> Exception has occurred: TypeError Wrong number or type of arguments for
> overloaded function 'new_VanillaSwap'. Possible C/C++ prototypes are:
> VanillaSwap::VanillaSwap(Swap::Type,Real,Schedule const &,Rate,DayCounter
> const &,Schedule const &,ext::shared_ptr< IborIndex > const
> &,Spread,DayCounter const &,boost::optional< bool >)
> VanillaSwap::VanillaSwap(Swap::Type,Real,Schedule const &,Rate,DayCounter
> const &,Schedule const &,ext::shared_ptr< IborIndex > const
> &,Spread,DayCounter const &) File
> "C:\Pavani\aValidations\AMC_SwapSingleCcy_Bermudan\PythonCode\ASwapSingleCcyBermPricer_v2\swap.py",
> line 136, in get_par_swap_rate ir_swap =
> ql.VanillaSwap(ql.VanillaSwap.Receiver, notional, fixed_schedule, File
>
>
>
>
>
> My code below:
>
> def get_par_swap_rate(self, exp_date, market_index: YieldCurve, market_disc: YieldCurve, calendar):
>
> ql_mat_dates = []
>
> maturity_date = exp_date + relativedelta(years=1)
>
> schedule_builder = build_ql_schedule()
>
> fixed_tenor = "1Y"
>
> fixed_calendar = "TAR"
>
> fixed_convention = "MODFOLLOWING"
>
> fixed_schedule = schedule_builder.build_schedule(exp_date,
>
> maturity_date,
>
> fixed_tenor,
>
> fixed_calendar,
>
> fixed_convention,
>
> fixed_convention,
>
> date_generation =
> ql.DateGeneration.Forward,
>
> end_of_month = False)
>
> floating_tenor = "3M"
>
> floating_calendar = "TAR"
>
> floating_convention = "MODFOLLOWING"
>
>
>
> floating_schedule = schedule_builder.build_schedule(exp_date,
>
> maturity_date,
>
> floating_tenor,
>
> floating_calendar,
>
>
> floating_convention,
>
> floating_convention,
>
> date_generation =
> ql.DateGeneration.Forward,
>
> end_of_month = False)
>
>
>
>
>
> notional = 50000000
>
> currency = 'EUR'
>
> fixed_rate = 0.00192
>
> # fixed_rate = 0.025
>
> fixed_leg_daycount = ql.Actual365Fixed()
>
> float_spread = -0.0033
>
> float_leg_daycount = ql.Actual360()
>
>
>
> startDateList = exp_date.year, exp_date.month, exp_date.day
>
> # parse python datetime.date into QuantLib date format
>
> ql_start_date = ql.Date(startDateList[2], startDateList[1],
> startDateList[0])
>
>
>
> # set up index_curve in QuantLib
>
> index_tenors = market_index.tenors
>
> for tnr in index_tenors:
>
> period = ql.Period(tnr, ql.Days)
>
> ql_mat_date = ql_start_date + period
>
> ql_mat_dates.append(ql_mat_date)
>
> index_rates = market_index.rates
>
> ql_day_count = ql.Actual365Fixed(ql.Actual365Fixed.Standard)
>
> ql_calendar = ql.TARGET()
>
> interpolation = ql.Linear()
>
> compounding = ql.Compounded
>
> compounding_frequency = ql.Daily
>
> index_term_structure = ql.ZeroCurve( ql_mat_dates, index_rates,
> ql_day_count,
>
> ql_calendar, interpolation,
>
> compounding, compounding_frequency)
>
> index_curve_handle = ql.YieldTermStructureHandle(index_term_structure)
>
>
>
> # set up index_curve in QuantLib
>
> ql_mat_dates.clear()
>
> discount_tenors = market_disc.tenors
>
> for tnr in discount_tenors:
>
> period = ql.Period(tnr, ql.Days)
>
> ql_mat_date = ql_start_date + period
>
> ql_mat_dates.append(ql_mat_date)
>
> disc_curve_rates = market_disc.rates
>
> ql_day_count = ql.Actual365Fixed(ql.Actual365Fixed.Standard)
>
> ql_calendar = ql.TARGET()
>
> interpolation = ql.Linear()
>
> compounding = ql.Compounded
>
> compounding_frequency = ql.Daily
>
> disc_term_structure = ql.ZeroCurve(ql_mat_dates, disc_curve_rates,
> ql_day_count,
>
> ql_calendar, interpolation,
>
> compounding, compounding_frequency)
>
> disc_curve_handle = ql.YieldTermStructureHandle(disc_term_structure)
>
>
>
> EUR3M_index = ql.Euribor3M(index_curve_handle)
>
> libor3M_index = ql.USDLibor(ql.Period(3, ql.Months),
> index_curve_handle)
>
> #swap = ql.VanillaSwap(
>
> # ql.VanillaSwap.Payer, 10000.0,
>
> # fixed_schedule, 0.02, ql.Thirty360(ql.Thirty360.BondBasis),
>
> # floating_schedule, index, 0.0, ql.Actual360()
>
> # )
>
> ir_swap = ql.VanillaSwap(ql.VanillaSwap.Receiver, notional,
> fixed_schedule,
>
> fixed_rate, fixed_leg_daycount,
> floating_schedule,
>
> EUR3M_index, float_spread, float_leg_daycount)
>
> swap_engine = ql.DiscountingSwapEngine(disc_curve_handle)
>
> ir_swap.setPricingEngine(swap_engine)
>
> par_swap_rate = ir_swap.fairRate()
>
> return par_swap_rate
>
>
>
>
>
> Best Regards,
>
> Pav
>
> Phone: +44(0)7769003342
>
>
>
>
>
> OFFICIAL USE
>
>
>
> To learn more about EBRD classifications, visit *www.ebrd.com/ic
> <http://www.ebrd.com/ic>*
>
> ______________________________________________________________
>
> This message may contain privileged information. If you have received this
> message by mistake, please keep it confidential and return it to the
> sender.
>
> Although we have taken steps to minimise the risk of transmitting software
> viruses, the EBRD accepts no liability for any loss or damage caused by
> computer viruses and would advise you to carry out your own virus checks.
>
> The contents of this e-mail do not necessarily represent the views of the
> EBRD.
>
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|