public void testSwaptionPricing()
        {
            //"Testing forward swap and swaption pricing...");

            //SavedSettings backup;

            const int size  = 10;
            const int steps = 8 * size;

            #if QL_USE_INDEXED_COUPON
            const double tolerance = 1e-6;
            #else
            const double tolerance = 1e-12;
            #endif

            List <Date>   dates = new List <Date>();
            List <double> rates = new List <double>();
            dates.Add(new Date(4, 9, 2005));
            dates.Add(new Date(4, 9, 2011));
            rates.Add(0.04);
            rates.Add(0.08);

            IborIndex index = makeIndex(dates, rates);

            LiborForwardModelProcess process = new LiborForwardModelProcess(size, index);

            LmCorrelationModel corrModel = new LmExponentialCorrelationModel(size, 0.5);

            LmVolatilityModel volaModel = new LmLinearExponentialVolatilityModel(process.fixingTimes(),
                                                                                 0.291, 1.483, 0.116, 0.00001);

            // set-up pricing engine
            process.setCovarParam((LfmCovarianceParameterization)
                                  new LfmCovarianceProxy(volaModel, corrModel));

            // set-up a small Monte-Carlo simulation to price swations
            List <double> tmp = process.fixingTimes();

            TimeGrid grid = new TimeGrid(tmp, steps);

            List <int> location = new List <int>();
            for (int i = 0; i < tmp.Count; ++i)
            {
                location.Add(grid.index(tmp[i]));
            }

            ulong     seed     = 42;
            const int nrTrails = 5000;
            LowDiscrepancy.icInstance = new InverseCumulativeNormal();

            IRNG rsg = (InverseCumulativeRsg <RandomSequenceGenerator <MersenneTwisterUniformRng>
                                              , InverseCumulativeNormal>)
                       new PseudoRandom().make_sequence_generator(process.factors() * (grid.size() - 1), seed);



            MultiPathGenerator <IRNG> generator = new MultiPathGenerator <IRNG>(process,
                                                                                grid,
                                                                                rsg, false);

            LiborForwardModel liborModel = new LiborForwardModel(process, volaModel, corrModel);

            Calendar              calendar   = index.fixingCalendar();
            DayCounter            dayCounter = index.forwardingTermStructure().link.dayCounter();
            BusinessDayConvention convention = index.businessDayConvention();

            Date settlement = index.forwardingTermStructure().link.referenceDate();

            SwaptionVolatilityMatrix m = liborModel.getSwaptionVolatilityMatrix();

            for (int i = 1; i < size; ++i)
            {
                for (int j = 1; j <= size - i; ++j)
                {
                    Date fwdStart    = settlement + new Period(6 * i, TimeUnit.Months);
                    Date fwdMaturity = fwdStart + new Period(6 * j, TimeUnit.Months);

                    Schedule schedule = new Schedule(fwdStart, fwdMaturity, index.tenor(), calendar,
                                                     convention, convention, DateGeneration.Rule.Forward, false);

                    double      swapRate    = 0.0404;
                    VanillaSwap forwardSwap = new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                                                              schedule, swapRate, dayCounter,
                                                              schedule, index, 0.0, index.dayCounter());
                    forwardSwap.setPricingEngine(new DiscountingSwapEngine(index.forwardingTermStructure()));

                    // check forward pricing first
                    double expected   = forwardSwap.fairRate();
                    double calculated = liborModel.S_0(i - 1, i + j - 1);

                    if (Math.Abs(expected - calculated) > tolerance)
                    {
                        Assert.Fail("Failed to reproduce fair forward swap rate"
                                    + "\n    calculated: " + calculated
                                    + "\n    expected:   " + expected);
                    }

                    swapRate    = forwardSwap.fairRate();
                    forwardSwap =
                        new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                                        schedule, swapRate, dayCounter,
                                        schedule, index, 0.0, index.dayCounter());
                    forwardSwap.setPricingEngine(new DiscountingSwapEngine(index.forwardingTermStructure()));

                    if (i == j && i <= size / 2)
                    {
                        IPricingEngine engine =
                            new LfmSwaptionEngine(liborModel, index.forwardingTermStructure());
                        Exercise exercise =
                            new EuropeanExercise(process.fixingDates()[i]);

                        Swaption swaption =
                            new Swaption(forwardSwap, exercise);
                        swaption.setPricingEngine(engine);

                        GeneralStatistics stat = new GeneralStatistics();

                        for (int n = 0; n < nrTrails; ++n)
                        {
                            Sample <MultiPath> path = (n % 2 != 0) ? generator.antithetic()
                                                     : generator.next();

                            //Sample<MultiPath> path = generator.next();
                            List <double> rates_ = new InitializedList <double>(size);
                            for (int k = 0; k < process.size(); ++k)
                            {
                                rates_[k] = path.value[k][location[i]];
                            }
                            List <double> dis = process.discountBond(rates_);

                            double npv = 0.0;
                            for (int k = i; k < i + j; ++k)
                            {
                                npv += (swapRate - rates_[k])
                                       * (process.accrualEndTimes()[k]
                                          - process.accrualStartTimes()[k]) * dis[k];
                            }
                            stat.add(Math.Max(npv, 0.0));
                        }

                        if (Math.Abs(swaption.NPV() - stat.mean())
                            > stat.errorEstimate() * 2.35)
                        {
                            Assert.Fail("Failed to reproduce swaption npv"
                                        + "\n    calculated: " + stat.mean()
                                        + "\n    expected:   " + swaption.NPV());
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public OptionletStripper1(CapFloorTermVolSurface parVolSurface, IborIndex index, double switchStrikes, double accuracy, uint maxIter, YieldTermStructureHandle discount) : this(NQuantLibcPINVOKE.new_OptionletStripper1__SWIG_3(CapFloorTermVolSurface.getCPtr(parVolSurface), IborIndex.getCPtr(index), switchStrikes, accuracy, maxIter, YieldTermStructureHandle.getCPtr(discount)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public MarkovFunctional(YieldTermStructureHandle termStructure, double reversion, DateVector volstepdates, DoubleVector volatilities, OptionletVolatilityStructureHandle capletVol, DateVector capletExpiries, IborIndex iborIndex) : this(NQuantLibcPINVOKE.new_MarkovFunctional__SWIG_3(YieldTermStructureHandle.getCPtr(termStructure), reversion, DateVector.getCPtr(volstepdates), DoubleVector.getCPtr(volatilities), OptionletVolatilityStructureHandle.getCPtr(capletVol), DateVector.getCPtr(capletExpiries), IborIndex.getCPtr(iborIndex)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 4
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(IborIndex obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 5
0
 public SwapRateHelper(double rate, Period tenor, Calendar calendar, Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount, IborIndex index, QuoteHandle spread, Period fwdStart, YieldTermStructureHandle discountingCurve) : this(NQuantLibcPINVOKE.new_SwapRateHelper__SWIG_4(rate, Period.getCPtr(tenor), Calendar.getCPtr(calendar), (int)fixedFrequency, (int)fixedConvention, DayCounter.getCPtr(fixedDayCount), IborIndex.getCPtr(index), QuoteHandle.getCPtr(spread), Period.getCPtr(fwdStart), YieldTermStructureHandle.getCPtr(discountingCurve)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
 public IBOROISBasisSwap(_IBOROISBasisSwap.Type type, double nominal, Schedule floatingSchedule, IborIndex iborIndex, DayCounter floatingDC, Schedule fixedSchedule, OvernightIndex overnightIndex, double spread, DayCounter fixedDC) : this(NQuantLibcPINVOKE.new_IBOROISBasisSwap__SWIG_2((int)type, nominal, Schedule.getCPtr(floatingSchedule), IborIndex.getCPtr(iborIndex), DayCounter.getCPtr(floatingDC), Schedule.getCPtr(fixedSchedule), OvernightIndex.getCPtr(overnightIndex), spread, DayCounter.getCPtr(fixedDC)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 7
0
        //-------------------------------------------------------------------------
        public override IborCapletFloorletVolatilityCalibrationResult calibrate(IborCapletFloorletVolatilityDefinition definition, ZonedDateTime calibrationDateTime, RawOptionData capFloorData, RatesProvider ratesProvider)
        {
            ArgChecker.isTrue(ratesProvider.ValuationDate.Equals(calibrationDateTime.toLocalDate()), "valuationDate of ratesProvider should be coherent to calibrationDateTime");
            ArgChecker.isTrue(definition is SabrIborCapletFloorletVolatilityBootstrapDefinition, "definition should be SabrIborCapletFloorletVolatilityBootstrapDefinition");
            SabrIborCapletFloorletVolatilityBootstrapDefinition bsDefinition = (SabrIborCapletFloorletVolatilityBootstrapDefinition)definition;
            IborIndex index           = bsDefinition.Index;
            LocalDate calibrationDate = calibrationDateTime.toLocalDate();
            LocalDate baseDate        = index.EffectiveDateOffset.adjust(calibrationDate, ReferenceData);
            LocalDate startDate       = baseDate.plus(index.Tenor);

            System.Func <Surface, IborCapletFloorletVolatilities> volatilitiesFunction = this.volatilitiesFunction(bsDefinition, calibrationDateTime, capFloorData);
            SurfaceMetadata metaData                = bsDefinition.createMetadata(capFloorData);
            IList <Period>  expiries                = capFloorData.Expiries;
            int             nExpiries               = expiries.Count;
            DoubleArray     strikes                 = capFloorData.Strikes;
            DoubleMatrix    errorsMatrix            = capFloorData.Error.orElse(DoubleMatrix.filled(nExpiries, strikes.size(), 1d));
            IList <double>  timeList                = new List <double>();
            IList <double>  strikeList              = new List <double>();
            IList <double>  volList                 = new List <double>();
            IList <ResolvedIborCapFloorLeg> capList = new List <ResolvedIborCapFloorLeg>();
            IList <double> priceList                = new List <double>();
            IList <double> errorList                = new List <double>();

            int[] startIndex = new int[nExpiries + 1];
            for (int i = 0; i < nExpiries; ++i)
            {
                LocalDate   endDate        = baseDate.plus(expiries[i]);
                DoubleArray volatilityData = capFloorData.Data.row(i);
                DoubleArray errors         = errorsMatrix.row(i);
                reduceRawData(bsDefinition, ratesProvider, strikes, volatilityData, errors, startDate, endDate, metaData, volatilitiesFunction, timeList, strikeList, volList, capList, priceList, errorList);
                startIndex[i + 1] = volList.Count;
                ArgChecker.isTrue(startIndex[i + 1] > startIndex[i], "no valid option data for {}", expiries[i]);
            }

            IList <CurveMetadata> metadataList   = bsDefinition.createSabrParameterMetadata();
            DoubleArray           timeToExpiries = DoubleArray.of(nExpiries, i => timeList[startIndex[i]]);

            BitArray @fixed  = new BitArray();
            bool     betaFix = false;
            Curve    betaCurve;
            Curve    rhoCurve;

            if (bsDefinition.BetaCurve.Present)
            {
                betaFix = true;
                @fixed.Set(1, true);
                betaCurve = bsDefinition.BetaCurve.get();
                rhoCurve  = InterpolatedNodalCurve.of(metadataList[2], timeToExpiries, DoubleArray.filled(nExpiries), bsDefinition.Interpolator, bsDefinition.ExtrapolatorLeft, bsDefinition.ExtrapolatorRight);
            }
            else
            {
                @fixed.Set(2, true);
                betaCurve = InterpolatedNodalCurve.of(metadataList[1], timeToExpiries, DoubleArray.filled(nExpiries), bsDefinition.Interpolator, bsDefinition.ExtrapolatorLeft, bsDefinition.ExtrapolatorRight);
                rhoCurve  = bsDefinition.RhoCurve.get();
            }
            InterpolatedNodalCurve alphaCurve = InterpolatedNodalCurve.of(metadataList[0], timeToExpiries, DoubleArray.filled(nExpiries), bsDefinition.Interpolator, bsDefinition.ExtrapolatorLeft, bsDefinition.ExtrapolatorRight);
            InterpolatedNodalCurve nuCurve    = InterpolatedNodalCurve.of(metadataList[3], timeToExpiries, DoubleArray.filled(nExpiries), bsDefinition.Interpolator, bsDefinition.ExtrapolatorLeft, bsDefinition.ExtrapolatorRight);
            Curve          shiftCurve         = bsDefinition.ShiftCurve;
            SabrParameters sabrParams         = SabrParameters.of(alphaCurve, betaCurve, rhoCurve, nuCurve, shiftCurve, bsDefinition.SabrVolatilityFormula);
            SabrParametersIborCapletFloorletVolatilities vols = SabrParametersIborCapletFloorletVolatilities.of(bsDefinition.Name, index, calibrationDateTime, sabrParams);
            double        totalChiSq = 0d;
            ZonedDateTime prevExpiry = calibrationDateTime.minusDays(1L);     // included if calibrationDateTime == fixingDateTime

            for (int i = 0; i < nExpiries; ++i)
            {
                DoubleArray start = computeInitialValues(ratesProvider, betaCurve, shiftCurve, timeList, volList, capList, startIndex, i, betaFix, capFloorData.DataType);
                UncoupledParameterTransforms transform = new UncoupledParameterTransforms(start, TRANSFORMS, @fixed);
                int nCaplets     = startIndex[i + 1] - startIndex[i];
                int currentStart = startIndex[i];
                System.Func <DoubleArray, DoubleArray>  valueFunction    = createPriceFunction(ratesProvider, vols, prevExpiry, capList, priceList, startIndex, nExpiries, i, nCaplets, betaFix);
                System.Func <DoubleArray, DoubleMatrix> jacobianFunction = createJacobianFunction(ratesProvider, vols, prevExpiry, capList, priceList, index.Currency, startIndex, nExpiries, i, nCaplets, betaFix);
                NonLinearTransformFunction transFunc = new NonLinearTransformFunction(valueFunction, jacobianFunction, transform);
                DoubleArray        adjustedPrices    = this.adjustedPrices(ratesProvider, vols, prevExpiry, capList, priceList, startIndex, i, nCaplets);
                DoubleArray        errors            = DoubleArray.of(nCaplets, n => errorList[currentStart + n]);
                LeastSquareResults res = solver.solve(adjustedPrices, errors, transFunc.FittingFunction, transFunc.FittingJacobian, transform.transform(start));
                LeastSquareResultsWithTransform resTransform = new LeastSquareResultsWithTransform(res, transform);
                vols        = updateParameters(vols, nExpiries, i, betaFix, resTransform.ModelParameters);
                totalChiSq += res.ChiSq;
                prevExpiry  = capList[startIndex[i + 1] - 1].FinalFixingDateTime;
            }
            return(IborCapletFloorletVolatilityCalibrationResult.ofLeastSquare(vols, totalChiSq));
        }
Esempio n. 8
0
 public CapHelper(Period length, QuoteHandle volatility, IborIndex index, Frequency fixedLegFrequency, DayCounter fixedLegDayCounter, bool includeFirstSwaplet, YieldTermStructureHandle termStructure) : this(NQuantLibcPINVOKE.new_CapHelper__SWIG_1(Period.getCPtr(length), QuoteHandle.getCPtr(volatility), IborIndex.getCPtr(index), (int)fixedLegFrequency, DayCounter.getCPtr(fixedLegDayCounter), includeFirstSwaplet, YieldTermStructureHandle.getCPtr(termStructure)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 9
0
 public FraRateHelper(double rate, uint monthsToStart, IborIndex index) : this(NQuantLibcPINVOKE.new_FraRateHelper__SWIG_3(rate, monthsToStart, IborIndex.getCPtr(index)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 10
0
 public static Leg IborLeg(DoubleVector nominals, Schedule schedule, IborIndex index) {
   Leg ret = new Leg(NQuantLibcPINVOKE.IborLeg__SWIG_8(DoubleVector.getCPtr(nominals), Schedule.getCPtr(schedule), IborIndex.getCPtr(index)), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Esempio n. 11
0
 public static Leg IborLeg(DoubleVector nominals, Schedule schedule, IborIndex index, DayCounter paymentDayCounter, BusinessDayConvention paymentConvention, UnsignedIntVector fixingDays, DoubleVector gearings, DoubleVector spreads, DoubleVector caps) {
   Leg ret = new Leg(NQuantLibcPINVOKE.IborLeg__SWIG_2(DoubleVector.getCPtr(nominals), Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(paymentDayCounter), (int)paymentConvention, UnsignedIntVector.getCPtr(fixingDays), DoubleVector.getCPtr(gearings), DoubleVector.getCPtr(spreads), DoubleVector.getCPtr(caps)), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Esempio n. 12
0
 public static Leg IborLeg(DoubleVector nominals, Schedule schedule, IborIndex index, DayCounter paymentDayCounter, BusinessDayConvention paymentConvention) {
   Leg ret = new Leg(NQuantLibcPINVOKE.IborLeg__SWIG_6(DoubleVector.getCPtr(nominals), Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(paymentDayCounter), (int)paymentConvention), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Esempio n. 13
0
 public ForwardRateAgreement(Date valueDate, Date maturityDate, Position.Type type, double strikeForwardRate, double notionalAmount, IborIndex index) : this(NQuantLibcPINVOKE.new_ForwardRateAgreement__SWIG_1(Date.getCPtr(valueDate), Date.getCPtr(maturityDate), (int)type, strikeForwardRate, notionalAmount, IborIndex.getCPtr(index)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 14
0
 public FuturesRateHelper(double price, Date immDate, IborIndex index) : this(NQuantLibcPINVOKE.new_FuturesRateHelper__SWIG_5(price, Date.getCPtr(immDate), IborIndex.getCPtr(index)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 15
0
 public NonstandardSwap(_VanillaSwap.Type type, DoubleVector fixedNominal, DoubleVector floatingNominal, Schedule fixedSchedule, DoubleVector fixedRate, DayCounter fixedDayCount, Schedule floatSchedule, IborIndex index, DoubleVector gearing, DoubleVector spread, DayCounter floatDayCount) : this(NQuantLibcPINVOKE.new_NonstandardSwap__SWIG_3((int)type, DoubleVector.getCPtr(fixedNominal), DoubleVector.getCPtr(floatingNominal), Schedule.getCPtr(fixedSchedule), DoubleVector.getCPtr(fixedRate), DayCounter.getCPtr(fixedDayCount), Schedule.getCPtr(floatSchedule), IborIndex.getCPtr(index), DoubleVector.getCPtr(gearing), DoubleVector.getCPtr(spread), DayCounter.getCPtr(floatDayCount)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 16
0
 public VanillaSwap(_VanillaSwap.Type type, double nominal, Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount, Schedule floatSchedule, IborIndex index, double spread, DayCounter floatingDayCount) : this(NQuantLibcPINVOKE.new_VanillaSwap((int)type, nominal, Schedule.getCPtr(fixedSchedule), fixedRate, DayCounter.getCPtr(fixedDayCount), Schedule.getCPtr(floatSchedule), IborIndex.getCPtr(index), spread, DayCounter.getCPtr(floatingDayCount)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 17
0
 public SwaptionHelper(Period maturity, Period length, QuoteHandle volatility, IborIndex index, Period fixedLegTenor, DayCounter fixedLegDayCounter, DayCounter floatingLegDayCounter, YieldTermStructureHandle termStructure) : this(NQuantLibcPINVOKE.new_SwaptionHelper__SWIG_1(Period.getCPtr(maturity), Period.getCPtr(length), QuoteHandle.getCPtr(volatility), IborIndex.getCPtr(index), Period.getCPtr(fixedLegTenor), DayCounter.getCPtr(fixedLegDayCounter), DayCounter.getCPtr(floatingLegDayCounter), YieldTermStructureHandle.getCPtr(termStructure)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 18
0
 public SwapIndex(string familyName, Period tenor, int settlementDays, Currency currency, Calendar calendar, Period fixedLegTenor, BusinessDayConvention fixedLegConvention, DayCounter fixedLegDayCounter, IborIndex iborIndex, YieldTermStructureHandle discountCurve) : this(NQuantLibcPINVOKE.new_SwapIndex__SWIG_1(familyName, Period.getCPtr(tenor), settlementDays, Currency.getCPtr(currency), Calendar.getCPtr(calendar), Period.getCPtr(fixedLegTenor), (int)fixedLegConvention, DayCounter.getCPtr(fixedLegDayCounter), IborIndex.getCPtr(iborIndex), YieldTermStructureHandle.getCPtr(discountCurve)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 19
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(IborIndex obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Esempio n. 20
0
 public IborIndex iborIndex() {
   IborIndex ret = new IborIndex(NQuantLibcPINVOKE.SwapIndex_iborIndex(swigCPtr), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public AmortizingFloatingRateBond(uint settlementDays, DoubleVector notional, Schedule schedule, IborIndex index, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention, uint fixingDays) : this(NQuantLibcPINVOKE.new_AmortizingFloatingRateBond__SWIG_6(settlementDays, DoubleVector.getCPtr(notional), Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(accrualDayCounter), (int)paymentConvention, fixingDays), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 22
0
 public IborCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, IborIndex index, double gearing, double spread, Date refPeriodStart, Date refPeriodEnd) : this(NQuantLibcPINVOKE.new_IborCoupon__SWIG_1(Date.getCPtr(paymentDate), nominal, Date.getCPtr(startDate), Date.getCPtr(endDate), fixingDays, IborIndex.getCPtr(index), gearing, spread, Date.getCPtr(refPeriodStart), Date.getCPtr(refPeriodEnd)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 23
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains {@code ImmutableRatesProvider} for specified valuation date.
 /// </summary>
 /// <param name="valuationDate">  the valuation date </param>
 /// <param name="index">  the index </param>
 /// <param name="timeSeries">  the time series </param>
 /// <returns> the rates provider </returns>
 public static ImmutableRatesProvider getRatesProvider(LocalDate valuationDate, IborIndex index, LocalDateDoubleTimeSeries timeSeries)
 {
     return(ImmutableRatesProvider.builder(valuationDate).discountCurve(EUR, EUR_DSC_CURVE).iborIndexCurve(index, EUR_FWD_CURVE).timeSeries(index, timeSeries).build());
 }
Esempio n. 24
0
 public IborCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, IborIndex index) : this(NQuantLibcPINVOKE.new_IborCoupon__SWIG_5(Date.getCPtr(paymentDate), nominal, Date.getCPtr(startDate), Date.getCPtr(endDate), fixingDays, IborIndex.getCPtr(index)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 25
0
 public FuturesRateHelper(QuoteHandle price, Date immDate, IborIndex index, QuoteHandle convexityAdjustment) : this(NQuantLibcPINVOKE.new_FuturesRateHelper__SWIG_3(QuoteHandle.getCPtr(price), Date.getCPtr(immDate), IborIndex.getCPtr(index), QuoteHandle.getCPtr(convexityAdjustment)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 26
0
        public void testInArrears()
        {
            // Testing in-arrears swap calculation
            CommonVars vars = new CommonVars();

            /* See Hull, 4th ed., page 550
             * Note: the calculation in the book is wrong (work out the adjustment and you'll get 0.05 + 0.000115 T1) */
            Date     maturity = vars.today + new Period(5, TimeUnit.Years);
            Calendar calendar = new NullCalendar();
            Schedule schedule = new Schedule(vars.today, maturity, new Period(Frequency.Annual), calendar,
                                             BusinessDayConvention.Following, BusinessDayConvention.Following,
                                             DateGeneration.Rule.Forward, false);
            DayCounter dayCounter = new SimpleDayCounter();

            List <double> nominals = new List <double>()
            {
                100000000.0
            };

            IborIndex index = new IborIndex("dummy", new Period(1, TimeUnit.Years), 0, new EURCurrency(), calendar,
                                            BusinessDayConvention.Following, false, dayCounter, vars.termStructure);
            double oneYear = 0.05;
            double r       = Math.Log(1.0 + oneYear);

            vars.termStructure.linkTo(Utilities.flatRate(vars.today, r, dayCounter));

            List <double> coupons = new List <double>()
            {
                oneYear
            };
            List <CashFlow> fixedLeg = new FixedRateLeg(schedule)
                                       .withCouponRates(coupons, dayCounter)
                                       .withNotionals(nominals);

            List <double> gearings   = new List <double>();
            List <double> spreads    = new List <double>();
            int           fixingDays = 0;

            double capletVolatility = 0.22;
            var    vol = new Handle <OptionletVolatilityStructure>(
                new ConstantOptionletVolatility(vars.today, new NullCalendar(),
                                                BusinessDayConvention.Following, capletVolatility, dayCounter));
            IborCouponPricer pricer = new BlackIborCouponPricer(vol);

            List <CashFlow> floatingLeg = new IborLeg(schedule, index)
                                          .withPaymentDayCounter(dayCounter)
                                          .withFixingDays(fixingDays)
                                          .withGearings(gearings)
                                          .withSpreads(spreads)
                                          .inArrears()
                                          .withNotionals(nominals);

            Utils.setCouponPricer(floatingLeg, pricer);

            Swap swap = new Swap(floatingLeg, fixedLeg);

            swap.setPricingEngine(new DiscountingSwapEngine(vars.termStructure));

            double storedValue = -144813.0;
            double tolerance   = 1.0;

            if (Math.Abs(swap.NPV() - storedValue) > tolerance)
            {
                QAssert.Fail("Wrong NPV calculation:\n"
                             + "    expected:   " + storedValue + "\n"
                             + "    calculated: " + swap.NPV());
            }
        }
Esempio n. 27
0
 public OptionletStripper1(CapFloorTermVolSurface parVolSurface, IborIndex index, double switchStrikes) : this(NQuantLibcPINVOKE.new_OptionletStripper1__SWIG_6(CapFloorTermVolSurface.getCPtr(parVolSurface), IborIndex.getCPtr(index), switchStrikes), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 28
0
 public ConvertibleFloatingRateBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, DoubleVector spreads, DayCounter dayCounter, Schedule schedule) : this(NQuantLibcPINVOKE.new_ConvertibleFloatingRateBond__SWIG_1(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, IborIndex.getCPtr(index), fixingDays, DoubleVector.getCPtr(spreads), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
        public void testCalibration()
        {
            //("Testing calibration of a Libor forward model...");

            //SavedSettings backup;

            const int    size      = 14;
            const double tolerance = 8e-3;

            double[] capVols = { 0.145708, 0.158465, 0.166248, 0.168672,
                                 0.169007, 0.167956, 0.166261, 0.164239,
                                 0.162082, 0.159923, 0.157781, 0.155745,
                                 0.153776, 0.151950, 0.150189, 0.148582,
                                 0.147034, 0.145598, 0.144248 };

            double[] swaptionVols = { 0.170595, 0.166844, 0.158306, 0.147444,
                                      0.136930, 0.126833, 0.118135, 0.175963,
                                      0.166359, 0.155203, 0.143712, 0.132769,
                                      0.122947, 0.114310, 0.174455, 0.162265,
                                      0.150539, 0.138734, 0.128215, 0.118470,
                                      0.110540, 0.169780, 0.156860, 0.144821,
                                      0.133537, 0.123167, 0.114363, 0.106500,
                                      0.164521, 0.151223, 0.139670, 0.128632,
                                      0.119123, 0.110330, 0.103114, 0.158956,
                                      0.146036, 0.134555, 0.124393, 0.115038,
                                      0.106996, 0.100064 };

            IborIndex index = makeIndex();
            LiborForwardModelProcess    process       = new LiborForwardModelProcess(size, index);
            Handle <YieldTermStructure> termStructure = index.forwardingTermStructure();

            // set-up the model
            LmVolatilityModel volaModel = new LmExtLinearExponentialVolModel(process.fixingTimes(),
                                                                             0.5, 0.6, 0.1, 0.1);

            LmCorrelationModel corrModel = new LmLinearExponentialCorrelationModel(size, 0.5, 0.8);

            LiborForwardModel model = new LiborForwardModel(process, volaModel, corrModel);

            int        swapVolIndex = 0;
            DayCounter dayCounter   = index.forwardingTermStructure().link.dayCounter();

            // set-up calibration helper
            List <CalibrationHelper> calibrationHelper = new List <CalibrationHelper>();

            int i;

            for (i = 2; i < size; ++i)
            {
                Period         maturity = i * index.tenor();
                Handle <Quote> capVol   = new Handle <Quote>(new SimpleQuote(capVols[i - 2]));

                CalibrationHelper caphelper = new CapHelper(maturity, capVol, index, Frequency.Annual,
                                                            index.dayCounter(), true, termStructure, CalibrationHelper.CalibrationErrorType.ImpliedVolError);

                caphelper.setPricingEngine(new AnalyticCapFloorEngine(model, termStructure));

                calibrationHelper.Add(caphelper);

                if (i <= size / 2)
                {
                    // add a few swaptions to test swaption calibration as well
                    for (int j = 1; j <= size / 2; ++j)
                    {
                        Period         len         = j * index.tenor();
                        Handle <Quote> swaptionVol = new Handle <Quote>(
                            new SimpleQuote(swaptionVols[swapVolIndex++]));

                        CalibrationHelper swaptionHelper =
                            new SwaptionHelper(maturity, len, swaptionVol, index,
                                               index.tenor(), dayCounter,
                                               index.dayCounter(),
                                               termStructure, CalibrationHelper.CalibrationErrorType.ImpliedVolError);

                        swaptionHelper.setPricingEngine(new LfmSwaptionEngine(model, termStructure));

                        calibrationHelper.Add(swaptionHelper);
                    }
                }
            }

            LevenbergMarquardt om = new LevenbergMarquardt(1e-6, 1e-6, 1e-6);

            //ConjugateGradient gc = new ConjugateGradient();

            model.calibrate(calibrationHelper,
                            om,
                            new EndCriteria(2000, 100, 1e-6, 1e-6, 1e-6),
                            new Constraint(),
                            new List <double>());

            // measure the calibration error
            double calculated = 0.0;

            for (i = 0; i < calibrationHelper.Count; ++i)
            {
                double diff = calibrationHelper[i].calibrationError();
                calculated += diff * diff;
            }

            if (Math.Sqrt(calculated) > tolerance)
            {
                Assert.Fail("Failed to calibrate libor forward model"
                            + "\n    calculated diff: " + Math.Sqrt(calculated)
                            + "\n    expected : smaller than  " + tolerance);
            }
        }
Esempio n. 30
0
 public DepositRateHelper(double rate, IborIndex i)
     : base(rate)
 {
     iborIndex_ = i.clone(termStructureHandle_);
     initializeDates();
 }
Esempio n. 31
0
 public NonstandardSwap(_VanillaSwap.Type type, DoubleVector fixedNominal, DoubleVector floatingNominal, Schedule fixedSchedule, DoubleVector fixedRate, DayCounter fixedDayCount, Schedule floatSchedule, IborIndex index, DoubleVector gearing, DoubleVector spread, DayCounter floatDayCount, bool intermediateCapitalExchange, bool finalCapitalExchange, BusinessDayConvention paymentConvention) : this(NQuantLibcPINVOKE.new_NonstandardSwap__SWIG_0((int)type, DoubleVector.getCPtr(fixedNominal), DoubleVector.getCPtr(floatingNominal), Schedule.getCPtr(fixedSchedule), DoubleVector.getCPtr(fixedRate), DayCounter.getCPtr(fixedDayCount), Schedule.getCPtr(floatSchedule), IborIndex.getCPtr(index), DoubleVector.getCPtr(gearing), DoubleVector.getCPtr(spread), DayCounter.getCPtr(floatDayCount), intermediateCapitalExchange, finalCapitalExchange, (int)paymentConvention), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 32
0
 //-------------------------------------------------------------------------
 public IborFutureOptionVolatilities volatilities(IborIndex index)
 {
     return(lookup.volatilities(index, marketData));
 }
Esempio n. 33
0
            // setup
            public CommonVars()
            {
                backup = new SavedSettings();

                Calendar calendar = new TARGET();

                Date referenceDate = calendar.adjust(Date.Today);

                Settings.setEvaluationDate(referenceDate);

                termStructure = new RelinkableHandle <YieldTermStructure>();
                termStructure.linkTo(Utilities.flatRate(referenceDate, 0.05, new Actual365Fixed()));

                // ATM Volatility structure
                List <Period> atmOptionTenors = new List <Period>();

                atmOptionTenors.Add(new Period(1, TimeUnit.Months));
                atmOptionTenors.Add(new Period(6, TimeUnit.Months));
                atmOptionTenors.Add(new Period(1, TimeUnit.Years));
                atmOptionTenors.Add(new Period(5, TimeUnit.Years));
                atmOptionTenors.Add(new Period(10, TimeUnit.Years));
                atmOptionTenors.Add(new Period(30, TimeUnit.Years));

                List <Period> atmSwapTenors = new List <Period>();

                atmSwapTenors.Add(new Period(1, TimeUnit.Years));
                atmSwapTenors.Add(new Period(5, TimeUnit.Years));
                atmSwapTenors.Add(new Period(10, TimeUnit.Years));
                atmSwapTenors.Add(new Period(30, TimeUnit.Years));

                Matrix m = new Matrix(atmOptionTenors.Count, atmSwapTenors.Count);

                m[0, 0] = 0.1300; m[0, 1] = 0.1560; m[0, 2] = 0.1390; m[0, 3] = 0.1220;
                m[1, 0] = 0.1440; m[1, 1] = 0.1580; m[1, 2] = 0.1460; m[1, 3] = 0.1260;
                m[2, 0] = 0.1600; m[2, 1] = 0.1590; m[2, 2] = 0.1470; m[2, 3] = 0.1290;
                m[3, 0] = 0.1640; m[3, 1] = 0.1470; m[3, 2] = 0.1370; m[3, 3] = 0.1220;
                m[4, 0] = 0.1400; m[4, 1] = 0.1300; m[4, 2] = 0.1250; m[4, 3] = 0.1100;
                m[5, 0] = 0.1130; m[5, 1] = 0.1090; m[5, 2] = 0.1070; m[5, 3] = 0.0930;

                atmVol = new Handle <SwaptionVolatilityStructure>(
                    new SwaptionVolatilityMatrix(calendar, BusinessDayConvention.Following, atmOptionTenors,
                                                 atmSwapTenors, m, new Actual365Fixed()));

                // Vol cubes
                List <Period> optionTenors = new List <Period>();

                optionTenors.Add(new Period(1, TimeUnit.Years));
                optionTenors.Add(new Period(10, TimeUnit.Years));
                optionTenors.Add(new Period(30, TimeUnit.Years));

                List <Period> swapTenors = new List <Period>();

                swapTenors.Add(new Period(2, TimeUnit.Years));
                swapTenors.Add(new Period(10, TimeUnit.Years));
                swapTenors.Add(new Period(30, TimeUnit.Years));

                List <double> strikeSpreads = new List <double>();

                strikeSpreads.Add(-0.020);
                strikeSpreads.Add(-0.005);
                strikeSpreads.Add(+0.000);
                strikeSpreads.Add(+0.005);
                strikeSpreads.Add(+0.020);

                int    nRows            = optionTenors.Count * swapTenors.Count;
                int    nCols            = strikeSpreads.Count;
                Matrix volSpreadsMatrix = new Matrix(nRows, nCols);

                volSpreadsMatrix[0, 0] = 0.0599;
                volSpreadsMatrix[0, 1] = 0.0049;
                volSpreadsMatrix[0, 2] = 0.0000;
                volSpreadsMatrix[0, 3] = -0.0001;
                volSpreadsMatrix[0, 4] = 0.0127;

                volSpreadsMatrix[1, 0] = 0.0729;
                volSpreadsMatrix[1, 1] = 0.0086;
                volSpreadsMatrix[1, 2] = 0.0000;
                volSpreadsMatrix[1, 3] = -0.0024;
                volSpreadsMatrix[1, 4] = 0.0098;

                volSpreadsMatrix[2, 0] = 0.0738;
                volSpreadsMatrix[2, 1] = 0.0102;
                volSpreadsMatrix[2, 2] = 0.0000;
                volSpreadsMatrix[2, 3] = -0.0039;
                volSpreadsMatrix[2, 4] = 0.0065;

                volSpreadsMatrix[3, 0] = 0.0465;
                volSpreadsMatrix[3, 1] = 0.0063;
                volSpreadsMatrix[3, 2] = 0.0000;
                volSpreadsMatrix[3, 3] = -0.0032;
                volSpreadsMatrix[3, 4] = -0.0010;

                volSpreadsMatrix[4, 0] = 0.0558;
                volSpreadsMatrix[4, 1] = 0.0084;
                volSpreadsMatrix[4, 2] = 0.0000;
                volSpreadsMatrix[4, 3] = -0.0050;
                volSpreadsMatrix[4, 4] = -0.0057;

                volSpreadsMatrix[5, 0] = 0.0576;
                volSpreadsMatrix[5, 1] = 0.0083;
                volSpreadsMatrix[5, 2] = 0.0000;
                volSpreadsMatrix[5, 3] = -0.0043;
                volSpreadsMatrix[5, 4] = -0.0014;

                volSpreadsMatrix[6, 0] = 0.0437;
                volSpreadsMatrix[6, 1] = 0.0059;
                volSpreadsMatrix[6, 2] = 0.0000;
                volSpreadsMatrix[6, 3] = -0.0030;
                volSpreadsMatrix[6, 4] = -0.0006;

                volSpreadsMatrix[7, 0] = 0.0533;
                volSpreadsMatrix[7, 1] = 0.0078;
                volSpreadsMatrix[7, 2] = 0.0000;
                volSpreadsMatrix[7, 3] = -0.0045;
                volSpreadsMatrix[7, 4] = -0.0046;

                volSpreadsMatrix[8, 0] = 0.0545;
                volSpreadsMatrix[8, 1] = 0.0079;
                volSpreadsMatrix[8, 2] = 0.0000;
                volSpreadsMatrix[8, 3] = -0.0042;
                volSpreadsMatrix[8, 4] = -0.0020;

                List <List <Handle <Quote> > > volSpreads = new InitializedList <List <Handle <Quote> > >(nRows);

                for (int i = 0; i < nRows; ++i)
                {
                    volSpreads[i] = new InitializedList <Handle <Quote> >(nCols);
                    for (int j = 0; j < nCols; ++j)
                    {
                        volSpreads[i][j] = new Handle <Quote>(new SimpleQuote(volSpreadsMatrix[i, j]));
                    }
                }

                iborIndex = new Euribor6M(termStructure);
                SwapIndex swapIndexBase      = new EuriborSwapIsdaFixA(new Period(10, TimeUnit.Years), termStructure);
                SwapIndex shortSwapIndexBase = new EuriborSwapIsdaFixA(new Period(2, TimeUnit.Years), termStructure);

                bool vegaWeightedSmileFit = false;

                SabrVolCube2 = new Handle <SwaptionVolatilityStructure>(
                    new SwaptionVolCube2(atmVol,
                                         optionTenors,
                                         swapTenors,
                                         strikeSpreads,
                                         volSpreads,
                                         swapIndexBase,
                                         shortSwapIndexBase,
                                         vegaWeightedSmileFit));
                SabrVolCube2.link.enableExtrapolation();

                List <List <Handle <Quote> > > guess = new InitializedList <List <Handle <Quote> > >(nRows);

                for (int i = 0; i < nRows; ++i)
                {
                    guess[i]    = new InitializedList <Handle <Quote> >(4);
                    guess[i][0] = new Handle <Quote>(new SimpleQuote(0.2));
                    guess[i][1] = new Handle <Quote>(new SimpleQuote(0.5));
                    guess[i][2] = new Handle <Quote>(new SimpleQuote(0.4));
                    guess[i][3] = new Handle <Quote>(new SimpleQuote(0.0));
                }
                List <bool> isParameterFixed = new InitializedList <bool>(4, false);

                isParameterFixed[1] = true;

                // FIXME
                bool isAtmCalibrated = false;

                SabrVolCube1 = new Handle <SwaptionVolatilityStructure>(
                    new SwaptionVolCube1x(atmVol,
                                          optionTenors,
                                          swapTenors,
                                          strikeSpreads,
                                          volSpreads,
                                          swapIndexBase,
                                          shortSwapIndexBase,
                                          vegaWeightedSmileFit,
                                          guess,
                                          isParameterFixed,
                                          isAtmCalibrated));
                SabrVolCube1.link.enableExtrapolation();

                yieldCurveModels = new List <GFunctionFactory.YieldCurveModel>();
                yieldCurveModels.Add(GFunctionFactory.YieldCurveModel.Standard);
                yieldCurveModels.Add(GFunctionFactory.YieldCurveModel.ExactYield);
                yieldCurveModels.Add(GFunctionFactory.YieldCurveModel.ParallelShifts);
                yieldCurveModels.Add(GFunctionFactory.YieldCurveModel.NonParallelShifts);
                yieldCurveModels.Add(GFunctionFactory.YieldCurveModel.NonParallelShifts); // for linear tsr model

                Handle <Quote> zeroMeanRev = new Handle <Quote>(new SimpleQuote(0.0));

                numericalPricers = new List <CmsCouponPricer>();
                analyticPricers  = new List <CmsCouponPricer>();
                for (int j = 0; j < yieldCurveModels.Count; ++j)
                {
                    if (j < yieldCurveModels.Count - 1)
                    {
                        numericalPricers.Add(new NumericHaganPricer(atmVol, yieldCurveModels[j], zeroMeanRev));
                    }
                    else
                    {
                        numericalPricers.Add(new LinearTsrPricer(atmVol, zeroMeanRev));
                    }

                    analyticPricers.Add(new AnalyticHaganPricer(atmVol, yieldCurveModels[j], zeroMeanRev));
                }
            }
Esempio n. 34
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains a convention based on the specified index.
 /// <para>
 /// The standard convention for an Ibor fixing deposit is based exclusively on the index.
 /// This creates an instance that contains the index.
 /// The instance is not dereferenced using the {@code FraConvention} name, as such
 /// the result of this method and <seealso cref="IborFixingDepositConvention#of(IborIndex)"/> can differ.
 /// </para>
 /// <para>
 /// Use the <seealso cref="#builder() builder"/> for unusual conventions.
 ///
 /// </para>
 /// </summary>
 /// <param name="index">  the index, the convention values are extracted from the index </param>
 /// <returns> the convention </returns>
 public static ImmutableIborFixingDepositConvention of(IborIndex index)
 {
     return(ImmutableIborFixingDepositConvention.builder().index(index).build());
 }
Esempio n. 35
0
 public IBOROISBasisSwap(_IBOROISBasisSwap.Type type, double nominal, Schedule floatingSchedule, IborIndex iborIndex, DayCounter floatingDC, Schedule fixedSchedule, OvernightIndex overnightIndex, double spread, DayCounter fixedDC, BusinessDayConvention paymentConvention, bool arithmeticAveragedCoupon) : this(NQuantLibcPINVOKE.new_IBOROISBasisSwap__SWIG_0((int)type, nominal, Schedule.getCPtr(floatingSchedule), IborIndex.getCPtr(iborIndex), DayCounter.getCPtr(floatingDC), Schedule.getCPtr(fixedSchedule), OvernightIndex.getCPtr(overnightIndex), spread, DayCounter.getCPtr(fixedDC), (int)paymentConvention, arithmeticAveragedCoupon), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 36
0
 //-----------------------------------------------------------------------
 /// <summary>
 /// Sets the Ibor index.
 /// <para>
 /// The floating rate to be paid or received is based on this index
 /// It will be a well known market index such as 'GBP-LIBOR-3M'.
 /// </para>
 /// </summary>
 /// <param name="index">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder index(IborIndex index)
 {
     JodaBeanUtils.notNull(index, "index");
     this.index_Renamed = index;
     return(this);
 }
Esempio n. 37
0
 public ForwardRateAgreement(Date valueDate, Date maturityDate, Position.Type type, double strikeForwardRate, double notionalAmount, IborIndex index) : this(NQuantLibcPINVOKE.new_ForwardRateAgreement__SWIG_1(Date.getCPtr(valueDate), Date.getCPtr(maturityDate), (int)type, strikeForwardRate, notionalAmount, IborIndex.getCPtr(index)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance based on a single mapping from index to volatility identifier.
 /// <para>
 /// The lookup provides volatilities for the specified index.
 ///
 /// </para>
 /// </summary>
 /// <param name="index">  the Ibor index </param>
 /// <param name="volatilityId">  the volatility identifier </param>
 /// <returns> the swaption lookup containing the specified mapping </returns>
 public static DefaultSwaptionMarketDataLookup of(IborIndex index, SwaptionVolatilitiesId volatilityId)
 {
     return(new DefaultSwaptionMarketDataLookup(ImmutableMap.of(index, volatilityId)));
 }
Esempio n. 39
0
 public CapHelper(Period length, QuoteHandle volatility, IborIndex index, Frequency fixedLegFrequency, DayCounter fixedLegDayCounter, bool includeFirstSwaplet, YieldTermStructureHandle termStructure) : this(NQuantLibcPINVOKE.new_CapHelper__SWIG_1(Period.getCPtr(length), QuoteHandle.getCPtr(volatility), IborIndex.getCPtr(index), (int)fixedLegFrequency, DayCounter.getCPtr(fixedLegDayCounter), includeFirstSwaplet, YieldTermStructureHandle.getCPtr(termStructure)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 40
0
 public VanillaSwap(_VanillaSwap.Type type, double nominal, Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount, Schedule floatSchedule, IborIndex index, double spread, DayCounter floatingDayCount) : this(NQuantLibcPINVOKE.new_VanillaSwap((int)type, nominal, Schedule.getCPtr(fixedSchedule), fixedRate, DayCounter.getCPtr(fixedDayCount), Schedule.getCPtr(floatSchedule), IborIndex.getCPtr(index), spread, DayCounter.getCPtr(floatingDayCount)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public AmortizingFloatingRateBond(uint settlementDays, DoubleVector notional, Schedule schedule, IborIndex index, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention, uint fixingDays, DoubleVector gearings, DoubleVector spreads, DoubleVector caps, DoubleVector floors, bool inArrears, Date issueDate) : this(NQuantLibcPINVOKE.new_AmortizingFloatingRateBond__SWIG_0(settlementDays, DoubleVector.getCPtr(notional), Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(accrualDayCounter), (int)paymentConvention, fixingDays, DoubleVector.getCPtr(gearings), DoubleVector.getCPtr(spreads), DoubleVector.getCPtr(caps), DoubleVector.getCPtr(floors), inArrears, Date.getCPtr(issueDate)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 42
0
 public CPISwap(_CPISwap.Type type, double nominal, bool subtractInflationNominal, double spread, DayCounter floatDayCount, Schedule floatSchedule, BusinessDayConvention floatRoll, uint fixingDays, IborIndex floatIndexPtr, double fixedRate, double baseCPI, DayCounter fixedDayCount, Schedule fixedSchedule, BusinessDayConvention fixedRoll, Period observationLag, ZeroInflationIndex fixedIndexPtr) : this(NQuantLibcPINVOKE.new_CPISwap__SWIG_2((int)type, nominal, subtractInflationNominal, spread, DayCounter.getCPtr(floatDayCount), Schedule.getCPtr(floatSchedule), (int)floatRoll, fixingDays, IborIndex.getCPtr(floatIndexPtr), fixedRate, baseCPI, DayCounter.getCPtr(fixedDayCount), Schedule.getCPtr(fixedSchedule), (int)fixedRoll, Period.getCPtr(observationLag), ZeroInflationIndex.getCPtr(fixedIndexPtr)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 43
0
        public void testIsdaEngine()
        {
            // Testing ISDA engine calculations for credit-default swaps

            SavedSettings backup = new SavedSettings();

            Date tradeDate = new Date(21, Month.May, 2009);

            Settings.setEvaluationDate(tradeDate);


            //build an ISDA compliant yield curve
            //data comes from Markit published rates
            List <RateHelper> isdaRateHelpers = new List <RateHelper>();

            int[]    dep_tenors = { 1, 2, 3, 6, 9, 12 };
            double[] dep_quotes = { 0.003081,
                                    0.005525,
                                    0.007163,
                                    0.012413,
                                    0.014,
                                    0.015488 };

            for (int i = 0; i < dep_tenors.Length; i++)
            {
                isdaRateHelpers.Add(new DepositRateHelper(dep_quotes[i], new Period(dep_tenors[i], TimeUnit.Months), 2,
                                                          new WeekendsOnly(), BusinessDayConvention.ModifiedFollowing, false, new Actual360())
                                    );
            }
            int[]    swap_tenors = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30 };
            double[] swap_quotes = { 0.011907,
                                     0.01699,
                                     0.021198,
                                     0.02444,
                                     0.026937,
                                     0.028967,
                                     0.030504,
                                     0.031719,
                                     0.03279,
                                     0.034535,
                                     0.036217,
                                     0.036981,
                                     0.037246,
                                     0.037605 };

            IborIndex isda_ibor = new IborIndex("IsdaIbor", new Period(3, TimeUnit.Months), 2, new USDCurrency(),
                                                new WeekendsOnly(), BusinessDayConvention.ModifiedFollowing, false, new Actual360());

            for (int i = 0; i < swap_tenors.Length; i++)
            {
                isdaRateHelpers.Add(new SwapRateHelper(swap_quotes[i], new Period(swap_tenors[i], TimeUnit.Years),
                                                       new WeekendsOnly(), Frequency.Semiannual, BusinessDayConvention.ModifiedFollowing, new Thirty360(),
                                                       isda_ibor));
            }

            RelinkableHandle <YieldTermStructure> discountCurve = new RelinkableHandle <YieldTermStructure>();

            discountCurve.linkTo(new PiecewiseYieldCurve <Discount, LogLinear>(0, new WeekendsOnly(), isdaRateHelpers,
                                                                               new Actual365Fixed()));


            RelinkableHandle <DefaultProbabilityTermStructure> probabilityCurve = new RelinkableHandle <DefaultProbabilityTermStructure>();

            Date[]   termDates = { new Date(20, Month.June, 2010),
                                   new Date(20,   Month.June, 2011),
                                   new Date(20,   Month.June, 2012),
                                   new Date(20,   Month.June, 2016),
                                   new Date(20,   Month.June, 2019) };
            double[] spreads    = { 0.001, 0.1 };
            double[] recoveries = { 0.2, 0.4 };

            double[] markitValues = { 97798.29358,  //0.001
                                      97776.11889,  //0.001
                                      -914971.5977, //0.1
                                      -894985.6298, //0.1
                                      186921.3594,  //0.001
                                      186839.8148,  //0.001
                                      -1646623.672, //0.1
                                      -1579803.626, //0.1
                                      274298.9203,
                                      274122.4725,
                                      -2279730.93,
                                      -2147972.527,
                                      592420.2297,
                                      591571.2294,
                                      -3993550.206,
                                      -3545843.418,
                                      797501.1422,
                                      795915.9787,
                                      -4702034.688,
                                      -4042340.999 };
#if !QL_USE_INDEXED_COUPON
            double tolerance = 1.0e-2; //TODO Check calculation , tolerance must be 1.0e-6;
#else
            /* The risk-free curve is a bit off. We might skip the tests
             * altogether and rely on running them with indexed coupons
             * disabled, but leaving them can be useful anyway. */
            double tolerance = 1.0e-3;
#endif

            int l = 0;

            for (int i = 0; i < termDates.Length; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        CreditDefaultSwap quotedTrade = new MakeCreditDefaultSwap(termDates[i], spreads[j])
                                                        .withNominal(10000000.0).value();

                        double h = quotedTrade.impliedHazardRate(0.0,
                                                                 discountCurve,
                                                                 new Actual365Fixed(),
                                                                 recoveries[k],
                                                                 1e-10,
                                                                 PricingModel.ISDA);

                        probabilityCurve.linkTo(new FlatHazardRate(0, new WeekendsOnly(), h, new Actual365Fixed()));

                        IsdaCdsEngine engine = new IsdaCdsEngine(probabilityCurve, recoveries[k], discountCurve);

                        CreditDefaultSwap conventionalTrade = new MakeCreditDefaultSwap(termDates[i], 0.01)
                                                              .withNominal(10000000.0)
                                                              .withPricingEngine(engine).value();

                        double x = conventionalTrade.notional().Value;
                        double y = conventionalTrade.fairUpfront();

                        double calculated = Math.Abs((x * y) - markitValues[l]);

                        QAssert.IsTrue(calculated <= tolerance);

                        l++;
                    }
                }
            }
        }
Esempio n. 44
0
 public FloatingRateBond(uint settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter, BusinessDayConvention paymentConvention, uint fixingDays, DoubleVector gearings, DoubleVector spreads, DoubleVector caps, DoubleVector floors, bool inArrears, double redemption, Date issueDate) : this(NQuantLibcPINVOKE.new_FloatingRateBond__SWIG_0(settlementDays, faceAmount, Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(paymentDayCounter), (int)paymentConvention, fixingDays, DoubleVector.getCPtr(gearings), DoubleVector.getCPtr(spreads), DoubleVector.getCPtr(caps), DoubleVector.getCPtr(floors), inArrears, redemption, Date.getCPtr(issueDate)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 45
0
 public SwaptionHelper(Period maturity, Period length, QuoteHandle volatility, IborIndex index, Period fixedLegTenor, DayCounter fixedLegDayCounter, DayCounter floatingLegDayCounter, YieldTermStructureHandle termStructure) : this(NQuantLibcPINVOKE.new_SwaptionHelper__SWIG_1(Period.getCPtr(maturity), Period.getCPtr(length), QuoteHandle.getCPtr(volatility), IborIndex.getCPtr(index), Period.getCPtr(fixedLegTenor), DayCounter.getCPtr(fixedLegDayCounter), DayCounter.getCPtr(floatingLegDayCounter), YieldTermStructureHandle.getCPtr(termStructure)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 46
0
 public FloatingRateBond(uint settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter, BusinessDayConvention paymentConvention, uint fixingDays, DoubleVector gearings) : this(NQuantLibcPINVOKE.new_FloatingRateBond__SWIG_6(settlementDays, faceAmount, Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(paymentDayCounter), (int)paymentConvention, fixingDays, DoubleVector.getCPtr(gearings)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 47
0
        /// <summary>
        /// Obtains {@code SabrParametersIborCapletFloorletVolatilities} with constant SABR parameters for specified valuation date.
        /// </summary>
        /// <param name="valuationDate">  the valuation date </param>
        /// <param name="index">  the index </param>
        /// <returns> the volatility provider </returns>
        public static SabrParametersIborCapletFloorletVolatilities getVolatilitiesFlatParameters(LocalDate valuationDate, IborIndex index)
        {
            ZonedDateTime dateTime = valuationDate.atStartOfDay(ZoneOffset.UTC);

            return(SabrParametersIborCapletFloorletVolatilities.of(NAME, index, dateTime, SABR_PARAM_FLAT));
        }
Esempio n. 48
0
 public FloatingRateBond(uint settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter) : this(NQuantLibcPINVOKE.new_FloatingRateBond__SWIG_9(settlementDays, faceAmount, Schedule.getCPtr(schedule), IborIndex.getCPtr(index), DayCounter.getCPtr(paymentDayCounter)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 49
0
 public SwapRateHelper(double rate, Period tenor, Calendar calendar, Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount, IborIndex index) : this(NQuantLibcPINVOKE.new_SwapRateHelper__SWIG_7(rate, Period.getCPtr(tenor), Calendar.getCPtr(calendar), (int)fixedFrequency, (int)fixedConvention, DayCounter.getCPtr(fixedDayCount), IborIndex.getCPtr(index)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 50
0
 public DepositRateHelper(double rate, IborIndex index) : this(NQuantLibcPINVOKE.new_DepositRateHelper__SWIG_3(rate, IborIndex.getCPtr(index)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }