public CappedFlooredCoupon(FloatingRateCoupon underlying) : this(NQuantLibcPINVOKE.new_CappedFlooredCoupon__SWIG_2(FloatingRateCoupon.getCPtr(underlying)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Ejemplo n.º 2
0
        protected override void initializeDates()
        {
            // do not pass the spread here, as it might be a Quote i.e. it can dinamically change
            // input discount curve Handle might be empty now but it could be assigned a curve later;
            // use a RelinkableHandle here
            swap_ = new MakeVanillaSwap(tenor_, iborIndex_, 0.0, fwdStart_)
                    .withSettlementDays(settlementDays_.Value)
                    .withDiscountingTermStructure(discountRelinkableHandle_)
                    .withFixedLegDayCount(fixedDayCount_)
                    .withFixedLegTenor(new Period(fixedFrequency_))
                    .withFixedLegConvention(fixedConvention_)
                    .withFixedLegTerminationDateConvention(fixedConvention_)
                    .withFixedLegCalendar(calendar_)
                    .withFloatingLegCalendar(calendar_);

            earliestDate_ = swap_.startDate();

            // Usually...
            maturityDate_ = latestRelevantDate_ = swap_.maturityDate();

            // ...but due to adjustments, the last floating coupon might
            // need a later date for fixing
#if QL_USE_INDEXED_COUPON
            FloatingRateCoupon lastCoupon = (FloatingRateCoupon)swap_.floatingLeg()[swap_.floatingLeg().Count - 1];
            Date fixingValueDate          = iborIndex_.valueDate(lastFloating.fixingDate());
            Date endValueDate             = iborIndex_.maturityDate(fixingValueDate);
            latestDate_ = Date.Max(latestDate_, endValueDate);
#endif

            switch (pillarChoice_)
            {
            case Pillar.Choice.MaturityDate:
                pillarDate_ = maturityDate_;
                break;

            case Pillar.Choice.LastRelevantDate:
                pillarDate_ = latestRelevantDate_;
                break;

            case Pillar.Choice.CustomDate:
                // pillarDate_ already assigned at construction time
                Utils.QL_REQUIRE(pillarDate_ >= earliestDate_, () =>
                                 "pillar date (" + pillarDate_ + ") must be later " +
                                 "than or equal to the instrument's earliest date (" +
                                 earliestDate_ + ")");
                Utils.QL_REQUIRE(pillarDate_ <= latestRelevantDate_, () =>
                                 "pillar date (" + pillarDate_ + ") must be before " +
                                 "or equal to the instrument's latest relevant date (" +
                                 latestRelevantDate_ + ")");
                break;

            default:
                Utils.QL_FAIL("unknown Pillar::Choice(" + pillarChoice_ + ")");
                break;
            }

            latestDate_ = pillarDate_; // backward compatibility
        }
Ejemplo n.º 3
0
        public static FloatingRateCoupon as_floating_rate_coupon(CashFlow cf)
        {
            FloatingRateCoupon ret = new FloatingRateCoupon(NQuantLibcPINVOKE.as_floating_rate_coupon(CashFlow.getCPtr(cf)), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 4
0
        public void testAccessViolation()
        {
            // Testing dynamic cast of coupon in Black pricer...

            SavedSettings backup = new SavedSettings();

            Date todaysDate     = new Date(7, Month.April, 2010);
            Date settlementDate = new Date(9, Month.April, 2010);

            Settings.setEvaluationDate(todaysDate);
            Calendar calendar = new TARGET();

            Handle <YieldTermStructure> rhTermStructure = new Handle <YieldTermStructure>(
                Utilities.flatRate(settlementDate, 0.04875825, new Actual365Fixed()));

            double volatility = 0.10;
            Handle <OptionletVolatilityStructure> vol = new Handle <OptionletVolatilityStructure>(
                new ConstantOptionletVolatility(2,
                                                calendar,
                                                BusinessDayConvention.ModifiedFollowing,
                                                volatility,
                                                new Actual365Fixed()));

            IborIndex index3m = new USDLibor(new Period(3, TimeUnit.Months), rhTermStructure);

            Date               payDate   = new Date(20, Month.December, 2013);
            Date               startDate = new Date(20, Month.September, 2013);
            Date               endDate   = new Date(20, Month.December, 2013);
            double             spread    = 0.0115;
            IborCouponPricer   pricer    = new BlackIborCouponPricer(vol);
            FloatingRateCoupon coupon    = new FloatingRateCoupon(100, payDate, startDate, endDate, 2,
                                                                  index3m, 1.0, spread / 100);

            coupon.setPricer(pricer);

            try
            {
                // this caused an access violation in version 1.0
                coupon.amount();
            }
            catch (Exception)
            {
                // ok; proper exception thrown
            }
        }
Ejemplo n.º 5
0
        public CappedFlooredCoupon(FloatingRateCoupon underlying, double?cap = null, double?floor = null)
            : base(underlying.date(), underlying.nominal(), underlying.accrualStartDate(), underlying.accrualEndDate(), underlying.fixingDays, underlying.index(), underlying.gearing(), underlying.spread(), underlying.referencePeriodStart, underlying.referencePeriodEnd, underlying.dayCounter(), underlying.isInArrears())
        {
            underlying_ = underlying;
            isCapped_   = false;
            isFloored_  = false;

            if (gearing_ > 0)
            {
                if (cap != null)
                {
                    isCapped_ = true;
                    cap_      = cap;
                }
                if (floor != null)
                {
                    floor_     = floor;
                    isFloored_ = true;
                }
            }
            else
            {
                if (cap != null)
                {
                    floor_     = cap;
                    isFloored_ = true;
                }
                if (floor != null)
                {
                    isCapped_ = true;
                    cap_      = floor;
                }
            }
            if (isCapped_ && isFloored_)
            {
                Utils.QL_REQUIRE(cap >= floor, () =>
                                 "cap level (" + cap + ") less than floor level (" + floor + ")");
            }
            underlying.registerWith(update);
        }
Ejemplo n.º 6
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FloatingRateCoupon obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 7
0
        public void BuildCube(Portfolio portfolio, List <ValuationCalculator> calculators)
        {
            QLNet.Utils.QL_REQUIRE(portfolio.Size() > 0, () => "ValuationEngine: Error portfolio is empty");

            ObservationMode.Mode om = ObservationMode.Mode.Disable;
            double updateTime       = 0.0;
            double pricingTime      = 0.0;
            double fixingTime       = 0.0;
            int    samples          = 1;

            List <Date>  dates  = _dg.Dates();
            List <Trade> trades = portfolio.Trades();

            int numFRC = 0;

            // initialise state objects for each trade (required for path-dependent derivatives in particular)
            for (int i = 0; i < trades.Count; i++)
            {
                QLNet.Utils.QL_REQUIRE(trades[i].NpvCurrency() != "", () => "NPV currency not set for trade " + trades[i].Id());

                //DLOG("Initialise wrapper for trade " << trades[i]->id());
                trades[i].Instrument();// ->initialise(dates);

                // T0 values
                foreach (var calc in calculators)
                {
                    calc.CalculateT0(trades[i], i, _simMarket); //, outputCube);
                }
                // TODO: Fix me!
                if (om == ObservationMode.Mode.Unregister)
                {
                    foreach (var leg in trades[i].Legs())
                    {
                        for (int n = 0; n < leg.Count; n++)
                        {
                            FloatingRateCoupon frc = leg[n] as FloatingRateCoupon;
                            if (frc != null)
                            {
                                //frc.unregisterWith(frc.index());
                                //trades[i]->instrument()->qlInstrument()->unregisterWith(frc);
                                //// Unregister with eval dates
                                //frc->unregisterWith(Settings::instance().evaluationDate());
                                //frc->index()->unregisterWith(Settings::instance().evaluationDate());
                                //trades[i]->instrument()->qlInstrument()->unregisterWith(Settings::instance().evaluationDate());
                            }
                        }
                    }
                }
            }

            //    LOG("Total number of swaps = " << portfolio->size());
            //    LOG("Total number of FRC = " << numFRC);

            //    simMarket_->fixingManager()->initialise(portfolio);

            Stopwatch timer     = new Stopwatch();
            Stopwatch loopTimer = new Stopwatch();

            // We call Cube::samples() each time her to allow for dynamic stopping times
            // e.g. MC convergence tests
            for (int sample = 0; sample < samples; ++sample)
            {
                //updateProgress(sample, outputCube->samples());

                foreach (var trade in trades)
                {
                    //trade.Instrument().Reset();
                }

                // loop over Dates
                for (int i = 0; i < dates.Count; ++i)
                {
                    Date d = dates[i];

                    timer.Start();

                    //simMarket_->update(d);

                    // recalibrate models
                    //foreach (var b in modelBuilders_)
                    //{
                    //    if (om == ObservationMode::Mode::Disable)
                    //    {
                    //        b.second->recalculate();
                    //    }

                    //    b.second->recalibrate();
                    //}

                    updateTime += timer.ElapsedMilliseconds / 1000.0;

                    // loop over trades
                    timer.Restart();
                    for (int j = 0; j < trades.Count; ++j)
                    {
                        var trade = trades[j];

                        // We can avoid checking mode here and always call updateQlInstruments()
                        if (om == ObservationMode.Mode.Disable)
                        {
                            trade.Instrument().update(); // ->updateQlInstruments();
                        }

                        foreach (var calc in calculators)
                        {
                            calc.Calculate(trade, j, _simMarket, d, i); //, outputCube, d, i, sample);
                        }
                    }
                    pricingTime += timer.ElapsedMilliseconds / 1000.0;
                }

                timer.Restart();
                //simMarket_->fixingManager()->reset();
                fixingTime += timer.ElapsedMilliseconds / 1000.0;
            }

            //simMarket_->reset();
            //updateProgress(outputCube->samples(), outputCube->samples());
            //LOG("ValuationEngine completed: loop " << setprecision(2) << loopTimer.elapsed() << " sec, "
            //                                               << "pricing " << pricingTime << " sec, "
            //                                               << "update " << updateTime << " sec "
            //                                               << "fixing " << fixingTime);
        }
Ejemplo n.º 8
0
 public CappedFlooredCoupon(FloatingRateCoupon underlying) : this(NQuantLibcPINVOKE.new_CappedFlooredCoupon__SWIG_2(FloatingRateCoupon.getCPtr(underlying)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Ejemplo n.º 9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FloatingRateCoupon obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Ejemplo n.º 10
0
 public static FloatingRateCoupon as_floating_rate_coupon(CashFlow cf) {
   FloatingRateCoupon ret = new FloatingRateCoupon(NQuantLibcPINVOKE.as_floating_rate_coupon(CashFlow.getCPtr(cf)), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }