예제 #1
0
        public DiscretizedSwap(VanillaSwap.Arguments args,
            Date referenceDate,
            DayCounter dayCounter)
        {
            arguments_ = args;
            fixedResetTimes_ = new InitializedList<double>(args.fixedResetDates.Count);
            for (int i = 0; i < fixedResetTimes_.Count; ++i)
                fixedResetTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.fixedResetDates[i]);

            fixedPayTimes_ = new InitializedList<double>(args.fixedPayDates.Count);
            for (int i = 0; i < fixedPayTimes_.Count; ++i)
                fixedPayTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.fixedPayDates[i]);

            floatingResetTimes_ = new InitializedList<double>(args.floatingResetDates.Count);
            for (int i = 0; i < floatingResetTimes_.Count; ++i)
                floatingResetTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.floatingResetDates[i]);

            floatingPayTimes_ = new InitializedList<double>(args.floatingPayDates.Count);
            for (int i = 0; i < floatingPayTimes_.Count; ++i)
                floatingPayTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            args.floatingPayDates[i]);
        }
예제 #2
0
        public BlackConstantVol(Date referenceDate, Calendar cal, Handle<Quote> volatility, DayCounter dc)
            : base(referenceDate, cal, BusinessDayConvention.Following, dc)
        {
            volatility_ = volatility;

            volatility_.registerWith(update);
        }
예제 #3
0
 public TermStructure(DayCounter dc)
 {
     moving_ = false;
     updated_ = true;
     settlementDays_ = default(int);
     dayCounter_ = dc;
 }
예제 #4
0
        public SwapRateHelper(double rate, Period tenor, Calendar calendar,
            Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
            IborIndex iborIndex)
            : this(rate, tenor, calendar, fixedFrequency, fixedConvention, fixedDayCount, iborIndex,
		                      	     new Handle<Quote>(), new Period(0, TimeUnit.Days))
        {
        }
예제 #5
0
        public BlackConstantVol(int settlementDays, Calendar cal, Handle<Quote> volatility, DayCounter dc)
            : base(settlementDays, cal, BusinessDayConvention.Following, dc)
        {
            volatility_ = volatility;

            volatility_.registerWith(update);
        }
예제 #6
0
        public SwaptionVolatilityDiscrete(List<Period> optionTenors,
            List<Period> swapTenors,
            int settlementDays,
            Calendar cal,
            BusinessDayConvention bdc,
            DayCounter dc)
            : base(settlementDays, cal, bdc, dc)
        {
            nOptionTenors_ = optionTenors.Count;
            optionTenors_ = optionTenors;
            optionDates_ = new InitializedList<Date>(nOptionTenors_);
            optionTimes_ = new InitializedList<double>(nOptionTenors_);
            optionDatesAsReal_ = new InitializedList<double>(nOptionTenors_);
            nSwapTenors_ = swapTenors.Count;
            swapTenors_ = swapTenors;
            swapLengths_ = new InitializedList<double>(nSwapTenors_);

            checkOptionTenors();
            initializeOptionDatesAndTimes();

            checkSwapTenors();
            initializeSwapLengths();

            optionInterpolator_ = new LinearInterpolation(optionTimes_,
                                            optionTimes_.Count,
                                            optionDatesAsReal_);
            optionInterpolator_.update();
            optionInterpolator_.enableExtrapolation();
            evaluationDate_ = Settings.evaluationDate();
            Settings.registerWith(update);
        }
예제 #7
0
 public BlackCapFloorEngine(Handle<YieldTermStructure> termStructure,
     double vol, DayCounter dc)
 {
     termStructure_ = termStructure;
      volatility_ = new Handle<OptionletVolatilityStructure>(new ConstantOptionletVolatility(0, new NullCalendar(), BusinessDayConvention.Following, vol, dc));
      termStructure_.registerWith(update );// registerWith(termStructure_);
 }
예제 #8
0
파일: Iborcoupon.cs 프로젝트: vdt/QLNet
 // Factory - for Leg generators
 public override CashFlow factory(double nominal, Date paymentDate, Date startDate, Date endDate, int fixingDays,
     InterestRateIndex index, double gearing, double spread,
     Date refPeriodStart, Date refPeriodEnd, DayCounter dayCounter, bool isInArrears)
 {
     return new IborCoupon(nominal, paymentDate, startDate, endDate, fixingDays,
             (IborIndex)index, gearing, spread, refPeriodStart, refPeriodEnd, dayCounter, isInArrears);
 }
예제 #9
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter,
            BusinessDayConvention paymentConvention, int fixingDays, List<double> gearings, List<double> spreads,
            List<double> caps, List<double> floors, bool inArrears, double redemption, Date issueDate)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            maturityDate_ = schedule.endDate();
            cashflows_ = new IborLeg(schedule, index)
                            .withPaymentDayCounter(paymentDayCounter)
                            .withFixingDays(fixingDays)
                            .withGearings(gearings)
                            .withSpreads(spreads)
                            .withCaps(caps)
                            .withFloors(floors)
                            .inArrears(inArrears)
                            .withNotionals(faceAmount)
                            .withPaymentAdjustment(paymentConvention);

            addRedemptionsToCashflows(new List<double>() { redemption });

            if (cashflows().Count == 0)
                throw new ApplicationException("bond with no cashflows!");
            if (redemptions_.Count != 1)
                throw new ApplicationException("multiple redemptions created");

            index.registerWith(update);
        }
예제 #10
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index,
            DayCounter paymentDayCounter, BusinessDayConvention paymentConvention, int fixingDays,
            List<double> gearings, List<double> spreads)
            : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following,
				   fixingDays, gearings, spreads, new List<double>(), new List<double>(), false, 100, null)
        {
        }
예제 #11
0
        public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule,
            List<double> coupons, DayCounter accrualDayCounter,
            BusinessDayConvention paymentConvention, double redemption, Date issueDate)
            : this(settlementDays, faceAmount, schedule, coupons, accrualDayCounter,
				   paymentConvention, redemption, issueDate, new Calendar())
        {
        }
예제 #12
0
파일: BasisSwap.cs 프로젝트: ariesy/QLNet
 // constructor
 public BasisSwap(Type type, double nominal,
     Schedule float1Schedule, IborIndex iborIndex1, double spread1, DayCounter float1DayCount,
     Schedule float2Schedule, IborIndex iborIndex2, double spread2, DayCounter float2DayCount)
     : this(type, nominal, float1Schedule, iborIndex1, spread1, float1DayCount,
                        float2Schedule, iborIndex2, spread2, float2DayCount, null)
 {
 }
예제 #13
0
        // constructors
        public FloatingRateCoupon(double nominal, 
            Date paymentDate,
            Date startDate,
            Date endDate,
            int fixingDays,
            InterestRateIndex index,
            double gearing = 1.0,
            double spread = 0.0,
            Date refPeriodStart = null,
            Date refPeriodEnd = null,
            DayCounter dayCounter = null,
            bool isInArrears = false)
            : base(nominal, paymentDate, startDate, endDate, refPeriodStart, refPeriodEnd)
        {
            index_ = index;
             dayCounter_ = dayCounter ?? index_.dayCounter() ?? new DayCounter();
             fixingDays_ = fixingDays == default(int) ? index.fixingDays() : fixingDays;
             gearing_ = gearing;
             spread_ = spread;
             isInArrears_ = isInArrears;

             if (gearing_ == 0) throw new ArgumentException("Null gearing not allowed");

             // add as observer
             index_.registerWith(update);
             Settings.registerWith(update);
        }
예제 #14
0
 public FlatForward(Date referenceDate, double forward, DayCounter dayCounter, Compounding compounding, Frequency frequency)
     : base(referenceDate, new Calendar(), dayCounter)
 {
     forward_ = new SimpleQuote(forward);
     compounding_ = compounding;
     frequency_ = frequency;
 }
예제 #15
0
 public YoYInflationCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, YoYInflationIndex yoyIndex, Period observationLag, DayCounter dayCounter, double gearing, double spread, Date refPeriodStart, Date refPeriodEnd)
     : base(paymentDate, nominal, startDate, endDate, fixingDays, yoyIndex, observationLag, dayCounter, refPeriodStart, refPeriodEnd)
 {
     yoyIndex_ = yoyIndex;
     gearing_ = gearing;
     spread_ = spread;
 }
예제 #16
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, 
            DayCounter paymentDayCounter)
            : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following,
                   0, new List<double>() { 1 }, new List<double>() { 0 }, new List<double>(), new List<double>(),
				   false, 100, null)
        {
        }
예제 #17
0
 public CapletVarianceCurve( Date referenceDate,
     List<Date> dates,
     List<double> capletVolCurve,
     DayCounter dayCounter)
     : base(referenceDate, new Calendar(), BusinessDayConvention.Following, new DayCounter())
 {
     blackCurve_=new BlackVarianceCurve(referenceDate, dates, capletVolCurve, dayCounter, false);
 }
예제 #18
0
        public LocalConstantVol(int settlementDays, Calendar calendar, Handle<Quote> volatility, DayCounter dayCounter)
            : base(settlementDays,calendar)
        {
            volatility_ = volatility;
            dayCounter_ = dayCounter;

            volatility_.registerWith(update);
        }
예제 #19
0
        public LocalConstantVol(Date referenceDate, Handle<Quote> volatility, DayCounter dc)
            : base(referenceDate)
        {
            volatility_ = volatility;
            dayCounter_ = dc;

            volatility_.registerWith(update);
        }
예제 #20
0
 public DailyTenorLibor(string familyName, int settlementDays, Currency currency, Calendar financialCenterCalendar, DayCounter dayCounter, Handle<YieldTermStructure> h)
     : base(familyName, new Period(1, TimeUnit.Days), settlementDays, currency, new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), financialCenterCalendar, JointCalendar.JointCalendarRule.JoinHolidays), Utils.liborConvention(new Period(1, TimeUnit.Days)), Utils.liborEOM(new Period(1, TimeUnit.Days)), dayCounter, h)
 {
     if (!(currency != new EURCurrency()))
     {
         throw new ApplicationException("for EUR Libor dedicated EurLibor constructor must be used");
     }
 }
예제 #21
0
        //! fixed reference date, floating market data
        public ConstantOptionletVolatility(Date referenceDate, Calendar cal, BusinessDayConvention bdc,
            Handle<Quote> vol, DayCounter dc)
            : base(referenceDate, cal, bdc, dc)
        {
            volatility_ = vol;

            volatility_.registerWith(update);
        }
예제 #22
0
 public DepositRateHelper(double rate, Period tenor, int fixingDays, Calendar calendar,
     BusinessDayConvention convention, bool endOfMonth, DayCounter dayCounter)
     : base(rate)
 {
     iborIndex_ = new IborIndex("no-fix", tenor, fixingDays, new Currency(), calendar, convention,
                                endOfMonth, dayCounter, termStructureHandle_);
     initializeDates();
 }
예제 #23
0
        //! floating reference date, floating market data
        public ConstantOptionletVolatility(int settlementDays, Calendar cal, BusinessDayConvention bdc,
            Handle<Quote> vol, DayCounter dc)
            : base(settlementDays, cal, bdc, dc)
        {
            volatility_ = vol;

            volatility_.registerWith(update);
        }
예제 #24
0
        public FlatForward(Date referenceDate, Quote forward, DayCounter dayCounter, Compounding compounding, Frequency frequency)
            : base(referenceDate, new Calendar(), dayCounter)
        {
            forward_ = forward;
            compounding_ = compounding;
            frequency_ = frequency;

            forward_.registerWith(update);
        }
예제 #25
0
 public BlackSwaptionEngine( Handle<YieldTermStructure> termStructure,
     Handle<Quote> vol, DayCounter dc)
 {
     termStructure_ = termStructure;
     volatility_ = new Handle<SwaptionVolatilityStructure>(new ConstantSwaptionVolatility(
                      0, new NullCalendar(), BusinessDayConvention.Following, vol, dc));
     termStructure_.registerWith(update);
     volatility_.registerWith(update);
 }
 //! floating reference date, fixed market data
 public ConstantCapFloorTermVolatility(int settlementDays,
     Calendar cal,
     BusinessDayConvention bdc,
     double volatility,
     DayCounter dc)
     : base(settlementDays, cal, bdc, dc)
 {
     volatility_ = new Handle<Quote>(new SimpleQuote(volatility));
 }
 // fixed reference date, fixed market data
 public ConstantCapFloorTermVolatility(Date referenceDate,
     Calendar cal,
     BusinessDayConvention bdc,
     double volatility,
     DayCounter dc)
     : base(referenceDate, cal, bdc, dc)
 {
     volatility_ = new Handle<Quote>(new SimpleQuote(volatility));
 }
예제 #28
0
 //! floating reference date, fixed market data
 public ConstantSwaptionVolatility(int settlementDays,
     Calendar cal,
     BusinessDayConvention bdc,
     double vol,
     DayCounter dc)
     : base(settlementDays, cal, bdc, dc)
 {
     volatility_ = new Handle<Quote>(new SimpleQuote(vol));
     maxSwapTenor_ = new Period(100, TimeUnit.Years);
 }
예제 #29
0
        public FRARateHelper(double rate, int monthsToStart, int monthsToEnd, int fixingDays, Calendar calendar,
            BusinessDayConvention convention, bool endOfMonth, DayCounter dayCounter)
            : base(rate)
        {
            periodToStart_ = new Period(monthsToStart, TimeUnit.Months);

            if (!(monthsToEnd > monthsToStart)) throw new ArgumentException("monthsToEnd must be grater than monthsToStart");
            iborIndex_ = new IborIndex("no-fix", new Period(monthsToEnd - monthsToStart, TimeUnit.Months), fixingDays,
                                       new Currency(), calendar, convention, endOfMonth, dayCounter, termStructureHandle_);
            initializeDates();
        }
예제 #30
0
        // double gearing = 1.0, double spread = 0.0,
        // Date refPeriodStart = Date(), Date refPeriodEnd = Date(), DayCounter dayCounter = DayCounter());
        public AverageBMACoupon(double nominal, Date paymentDate, Date startDate, Date endDate, BMAIndex index,
            double gearing, double spread, Date refPeriodStart, Date refPeriodEnd, DayCounter dayCounter)
            : base(nominal, paymentDate, startDate, endDate, index.fixingDays(), index, gearing, spread,
						 refPeriodStart, refPeriodEnd, dayCounter, false)
        {
            fixingSchedule_ = index.fixingSchedule(
                                index.fixingCalendar()
                                    .advance(startDate, new Period(-index.fixingDays() + bmaCutoffDays, TimeUnit.Days),
                                                   BusinessDayConvention.Preceding), endDate);
            setPricer(new AverageBMACouponPricer());
        }
예제 #31
0
            // setup
            public CommonVars()
            {
                backup    = new SavedSettings();
                cleaner   = new IndexHistoryCleaner();
                nominalUK = new RelinkableHandle <YieldTermStructure>();
                cpiUK     = new RelinkableHandle <ZeroInflationTermStructure>();
                hcpi      = new RelinkableHandle <ZeroInflationTermStructure>();
                zciisD    = new List <Date>();
                zciisR    = new List <double>();
                hii       = new RelinkableHandle <ZeroInflationIndex>();

                nominals = new InitializedList <double>(1, 1000000);
                // option variables
                frequency = Frequency.Annual;
                // usual setup
                volatility = 0.01;
                length     = 7;
                calendar   = new UnitedKingdom();
                convention = BusinessDayConvention.ModifiedFollowing;
                Date today = new Date(25, Month.November, 2009);

                evaluationDate = calendar.adjust(today);
                Settings.setEvaluationDate(evaluationDate);
                settlementDays = 0;
                fixingDays     = 0;
                settlement     = calendar.advance(today, settlementDays, TimeUnit.Days);
                startDate      = settlement;
                dcZCIIS        = new ActualActual();
                dcNominal      = new ActualActual();

                // uk rpi index
                //      fixing data
                Date     from        = new Date(20, Month.July, 2007);
                Date     to          = new Date(20, Month.November, 2009);
                Schedule rpiSchedule = new MakeSchedule().from(from).to(to)
                                       .withTenor(new Period(1, TimeUnit.Months))
                                       .withCalendar(new UnitedKingdom())
                                       .withConvention(BusinessDayConvention.ModifiedFollowing).value();

                double[] fixData =
                {
                    206.1,  207.3, 208.0, 208.9, 209.7, 210.9,
                    209.8,  211.4, 212.1, 214.0, 215.1, 216.8,
                    216.5,  217.2, 218.4, 217.7,   216,
                    212.9,  210.1, 211.4, 211.3, 211.5,
                    212.8,  213.4, 213.4, 213.4, 214.4,
                    -999.0, -999.0
                };

                // link from cpi index to cpi TS
                bool interp = false;// this MUST be false because the observation lag is only 2 months

                // for ZCIIS; but not for contract if the contract uses a bigger lag.
                ii = new UKRPI(interp, hcpi);
                for (int i = 0; i < rpiSchedule.Count; i++)
                {
                    ii.addFixing(rpiSchedule[i], fixData[i], true); // force overwrite in case multiple use
                }

                Datum[] nominalData =
                {
                    new Datum(new Date(26, Month.November,  2009),   0.475),
                    new Datum(new Date(2,  Month.December,  2009), 0.47498),
                    new Datum(new Date(29, Month.December,  2009), 0.49988),
                    new Datum(new Date(25, Month.February,  2010), 0.59955),
                    new Datum(new Date(18, Month.March,     2010), 0.65361),
                    new Datum(new Date(25, Month.May,       2010), 0.82830),
                    new Datum(new Date(17, Month.June,      2010),     0.7),
                    new Datum(new Date(16, Month.September, 2010), 0.78960),
                    new Datum(new Date(16, Month.December,  2010), 0.93762),
                    new Datum(new Date(17, Month.March,     2011), 1.12037),
                    new Datum(new Date(22, Month.September, 2011), 1.52011),
                    new Datum(new Date(25, Month.November,  2011), 1.78399),
                    new Datum(new Date(26, Month.November,  2012), 2.41170),
                    new Datum(new Date(25, Month.November,  2013), 2.83935),
                    new Datum(new Date(25, Month.November,  2014), 3.12888),
                    new Datum(new Date(25, Month.November,  2015), 3.34298),
                    new Datum(new Date(25, Month.November,  2016), 3.50632),
                    new Datum(new Date(27, Month.November,  2017), 3.63666),
                    new Datum(new Date(26, Month.November,  2018), 3.74723),
                    new Datum(new Date(25, Month.November,  2019), 3.83988),
                    new Datum(new Date(25, Month.November,  2021), 4.00508),
                    new Datum(new Date(25, Month.November,  2024), 4.16042),
                    new Datum(new Date(26, Month.November,  2029), 4.15577),
                    new Datum(new Date(27, Month.November,  2034), 4.04933),
                    new Datum(new Date(25, Month.November,  2039), 3.95217),
                    new Datum(new Date(25, Month.November,  2049), 3.80932),
                    new Datum(new Date(25, Month.November,  2059), 3.80849),
                    new Datum(new Date(25, Month.November,  2069), 3.72677),
                    new Datum(new Date(27, Month.November,  2079), 3.63082)
                };
                int nominalDataLength = 30 - 1;

                List <Date>   nomD = new List <Date>();
                List <double> nomR = new List <double>();

                for (int i = 0; i < nominalDataLength; i++)
                {
                    nomD.Add(nominalData[i].date);
                    nomR.Add(nominalData[i].rate / 100.0);
                }
                YieldTermStructure nominal = new InterpolatedZeroCurve <Linear>(nomD, nomR, dcNominal);

                nominalUK.linkTo(nominal);

                // now build the zero inflation curve
                observationLag                   = new Period(2, TimeUnit.Months);
                contractObservationLag           = new Period(3, TimeUnit.Months);
                contractObservationInterpolation = InterpolationType.Flat;

                Datum[] zciisData =
                {
                    new Datum(new Date(25, Month.November, 2010),  3.0495),
                    new Datum(new Date(25, Month.November, 2011),    2.93),
                    new Datum(new Date(26, Month.November, 2012),  2.9795),
                    new Datum(new Date(25, Month.November, 2013),   3.029),
                    new Datum(new Date(25, Month.November, 2014),  3.1425),
                    new Datum(new Date(25, Month.November, 2015),   3.211),
                    new Datum(new Date(25, Month.November, 2016),  3.2675),
                    new Datum(new Date(25, Month.November, 2017),  3.3625),
                    new Datum(new Date(25, Month.November, 2018),   3.405),
                    new Datum(new Date(25, Month.November, 2019),    3.48),
                    new Datum(new Date(25, Month.November, 2021),   3.576),
                    new Datum(new Date(25, Month.November, 2024),   3.649),
                    new Datum(new Date(26, Month.November, 2029),   3.751),
                    new Datum(new Date(27, Month.November, 2034), 3.77225),
                    new Datum(new Date(25, Month.November, 2039),    3.77),
                    new Datum(new Date(25, Month.November, 2049),   3.734),
                    new Datum(new Date(25, Month.November, 2059), 3.714)
                };
                zciisDataLength = 17;
                for (int i = 0; i < zciisDataLength; i++)
                {
                    zciisD.Add(zciisData[i].date);
                    zciisR.Add(zciisData[i].rate);
                }

                // now build the helpers ...
                List <BootstrapHelper <ZeroInflationTermStructure> > helpers = makeHelpers(zciisData, zciisDataLength, ii,
                                                                                           observationLag, calendar, convention, dcZCIIS);

                // we can use historical or first ZCIIS for this
                // we know historical is WAY off market-implied, so use market implied flat.
                double baseZeroRate = zciisData[0].rate / 100.0;
                PiecewiseZeroInflationCurve <Linear> pCPIts = new PiecewiseZeroInflationCurve <Linear>(
                    evaluationDate, calendar, dcZCIIS, observationLag, ii.frequency(), ii.interpolated(), baseZeroRate,
                    new Handle <YieldTermStructure>(nominalUK), helpers);

                pCPIts.recalculate();
                cpiUK.linkTo(pCPIts);

                // make sure that the index has the latest zero inflation term structure
                hcpi.linkTo(pCPIts);
            }
예제 #32
0
 //philippe2009_17
 public static BlackVolTermStructure flatVol(Quote vol, DayCounter dc)
 {
     return(new BlackConstantVol(0, new NullCalendar(), new Handle <Quote>(vol), dc));
 }
예제 #33
0
 //! fixed reference date, fixed market data
 public ConstantOptionletVolatility(Date referenceDate, Calendar cal, BusinessDayConvention bdc,
                                    double vol, DayCounter dc)
     : base(referenceDate, cal, bdc, dc)
 {
     volatility_ = new Handle <Quote>(new SimpleQuote(vol));
 }
 public PiecewiseLinearZero(Date referenceDate, RateHelperVector instruments, DayCounter dayCounter, QuoteHandleVector jumps, DateVector jumpDates, double accuracy, Linear i) : this(NQuantLibcPINVOKE.new_PiecewiseLinearZero__SWIG_0(Date.getCPtr(referenceDate), RateHelperVector.getCPtr(instruments), DayCounter.getCPtr(dayCounter), QuoteHandleVector.getCPtr(jumps), DateVector.getCPtr(jumpDates), accuracy, Linear.getCPtr(i)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public PiecewiseLinearZero(int settlementDays, Calendar calendar, RateHelperVector instruments, DayCounter dayCounter, QuoteHandleVector jumps, DateVector jumpDates, double accuracy) : this(NQuantLibcPINVOKE.new_PiecewiseLinearZero__SWIG_6(settlementDays, Calendar.getCPtr(calendar), RateHelperVector.getCPtr(instruments), DayCounter.getCPtr(dayCounter), QuoteHandleVector.getCPtr(jumps), DateVector.getCPtr(jumpDates), accuracy), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public ConstantSwaptionVolatility(Date referenceDate, Calendar cal, BusinessDayConvention bdc, QuoteHandle volatility, DayCounter dc) : this(NQuantLibcPINVOKE.new_ConstantSwaptionVolatility__SWIG_5(Date.getCPtr(referenceDate), Calendar.getCPtr(cal), (int)bdc, QuoteHandle.getCPtr(volatility), DayCounter.getCPtr(dc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public ZabrShortMaturityNormalSmileSection(Date d, double forward, DoubleVector zabrParameters, DayCounter dc) : this(NQuantLibcPINVOKE.new_ZabrShortMaturityNormalSmileSection__SWIG_5(Date.getCPtr(d), forward, DoubleVector.getCPtr(zabrParameters), DayCounter.getCPtr(dc)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #38
0
        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, tmp.Count, 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 <IPath> path = (n % 2 != 0) ? generator.antithetic()
                                                     : generator.next();
                            MultiPath value = path.value as MultiPath;
                            Utils.QL_REQUIRE(value != null, () => "Invalid Path");
                            //Sample<MultiPath> path = generator.next();
                            List <double> rates_ = new InitializedList <double>(size);
                            for (int k = 0; k < process.size(); ++k)
                            {
                                rates_[k] = 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());
                        }
                    }
                }
            }
        }
예제 #39
0
        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);
            }
        }
예제 #40
0
 public SwaptionVolatilityMatrix(Calendar calendar, BusinessDayConvention bdc, PeriodVector optionTenors, PeriodVector swapTenors, Matrix vols, DayCounter dayCounter) : this(NQuantLibcPINVOKE.new_SwaptionVolatilityMatrix__SWIG_2(Calendar.getCPtr(calendar), (int)bdc, PeriodVector.getCPtr(optionTenors), PeriodVector.getCPtr(swapTenors), Matrix.getCPtr(vols), DayCounter.getCPtr(dayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #41
0
 public SwaptionVolatilityMatrix(Date referenceDate, DateVector dates, PeriodVector lengths, Matrix vols, DayCounter dayCounter) : this(NQuantLibcPINVOKE.new_SwaptionVolatilityMatrix__SWIG_0(Date.getCPtr(referenceDate), DateVector.getCPtr(dates), PeriodVector.getCPtr(lengths), Matrix.getCPtr(vols), DayCounter.getCPtr(dayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #42
0
 public static YieldTermStructure flatRate(Date today, Quote forward, DayCounter dc)
 {
     return(new FlatForward(today, forward, dc));
 }
예제 #43
0
 //philippe2009_17
 public static YieldTermStructure flatRate(double forward, DayCounter dc)
 {
     return(flatRate(new SimpleQuote(forward), dc));
 }
예제 #44
0
 public PiecewiseYieldCurve(Date referenceDate, List <RateHelper> instruments,
                            DayCounter dayCounter, List <Handle <Quote> > jumps, List <Date> jumpDates)
     : this(referenceDate, instruments, dayCounter, jumps, jumpDates, 1.0e-12, new Interpolator(), new BootStrap())
 {
 }
 public ConstantSwaptionVolatility(uint settlementDays, Calendar cal, BusinessDayConvention bdc, double volatility, DayCounter dc, VolatilityType type) : this(NQuantLibcPINVOKE.new_ConstantSwaptionVolatility__SWIG_7(settlementDays, Calendar.getCPtr(cal), (int)bdc, volatility, DayCounter.getCPtr(dc), (int)type), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public CPISwap(CPISwap.Type type, double nominal, bool subtractInflationNominal, double spread, DayCounter floatDayCount, Schedule floatSchedule, BusinessDayConvention floatRoll, uint fixingDays, IborIndex floatIndex, double fixedRate, double baseCPI, DayCounter fixedDayCount, Schedule fixedSchedule, BusinessDayConvention fixedRoll, Period observationLag, ZeroInflationIndex fixedIndex) : this(NQuantLibcPINVOKE.new_CPISwap__SWIG_2((int)type, nominal, subtractInflationNominal, spread, DayCounter.getCPtr(floatDayCount), Schedule.getCPtr(floatSchedule), (int)floatRoll, fixingDays, IborIndex.getCPtr(floatIndex), fixedRate, baseCPI, DayCounter.getCPtr(fixedDayCount), Schedule.getCPtr(fixedSchedule), (int)fixedRoll, Period.getCPtr(observationLag), ZeroInflationIndex.getCPtr(fixedIndex)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public ConstantSwaptionVolatility(Date referenceDate, Calendar cal, BusinessDayConvention bdc, double volatility, DayCounter dc, VolatilityType type, double shift) : this(NQuantLibcPINVOKE.new_ConstantSwaptionVolatility__SWIG_9(Date.getCPtr(referenceDate), Calendar.getCPtr(cal), (int)bdc, volatility, DayCounter.getCPtr(dc), (int)type, shift), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #48
0
 public YearOnYearInflationSwap(_YearOnYearInflationSwap.Type type, double nominal, Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCounter, Schedule yoySchedule, YoYInflationIndex index, Period lag, double spread, DayCounter yoyDayCounter, Calendar paymentCalendar) : this(NQuantLibcPINVOKE.new_YearOnYearInflationSwap__SWIG_1((int)type, nominal, Schedule.getCPtr(fixedSchedule), fixedRate, DayCounter.getCPtr(fixedDayCounter), Schedule.getCPtr(yoySchedule), YoYInflationIndex.getCPtr(index), Period.getCPtr(lag), spread, DayCounter.getCPtr(yoyDayCounter), Calendar.getCPtr(paymentCalendar)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public PiecewiseLinearZero(Date referenceDate, RateHelperVector instruments, DayCounter dayCounter) : this(NQuantLibcPINVOKE.new_PiecewiseLinearZero__SWIG_4(Date.getCPtr(referenceDate), RateHelperVector.getCPtr(instruments), DayCounter.getCPtr(dayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #50
0
 public static YieldTermStructure flatRate(Date today, double forward, DayCounter dc)
 {
     return(new FlatForward(today, new SimpleQuote(forward), dc));
 }
예제 #51
0
 public void setConventions()
 {
     calendar   = new TARGET();
     optionBdc  = BusinessDayConvention.ModifiedFollowing;
     dayCounter = new Actual365Fixed();
 }
예제 #52
0
        static void Main()
        {
            DateTime timer = DateTime.Now;

            /*********************
            ***  MARKET DATA  ***
            *********************/

            RelinkableHandle <YieldTermStructure> euriborTermStructure = new RelinkableHandle <YieldTermStructure>();
            IborIndex euribor3m = new Euribor3M(euriborTermStructure);

            Date todaysDate = new Date(23, Month.May, 2006);

            Settings.setEvaluationDate(todaysDate);

            Calendar calendar       = euribor3m.fixingCalendar();
            int      fixingDays     = euribor3m.fixingDays();
            Date     settlementDate = calendar.advance(todaysDate, fixingDays, TimeUnit.Days);

            Console.WriteLine("Today: " + todaysDate.DayOfWeek + ", " + todaysDate);
            Console.WriteLine("Settlement date: " + settlementDate.DayOfWeek + ", " + settlementDate);


            // 3 month term FRA quotes (index refers to monthsToStart)
            double[] threeMonthFraQuote = new double[10];

            threeMonthFraQuote[1] = 0.030;
            threeMonthFraQuote[2] = 0.031;
            threeMonthFraQuote[3] = 0.032;
            threeMonthFraQuote[6] = 0.033;
            threeMonthFraQuote[9] = 0.034;

            /********************
            ***    QUOTES    ***
            ********************/

            // SimpleQuote stores a value which can be manually changed;
            // other Quote subclasses could read the value from a database
            // or some kind of data feed.


            // FRAs
            SimpleQuote fra1x4Rate  = new SimpleQuote(threeMonthFraQuote[1]);
            SimpleQuote fra2x5Rate  = new SimpleQuote(threeMonthFraQuote[2]);
            SimpleQuote fra3x6Rate  = new SimpleQuote(threeMonthFraQuote[3]);
            SimpleQuote fra6x9Rate  = new SimpleQuote(threeMonthFraQuote[6]);
            SimpleQuote fra9x12Rate = new SimpleQuote(threeMonthFraQuote[9]);

            RelinkableHandle <Quote> h1x4  = new RelinkableHandle <Quote>();  h1x4.linkTo(fra1x4Rate);
            RelinkableHandle <Quote> h2x5  = new RelinkableHandle <Quote>();  h2x5.linkTo(fra2x5Rate);
            RelinkableHandle <Quote> h3x6  = new RelinkableHandle <Quote>();  h3x6.linkTo(fra3x6Rate);
            RelinkableHandle <Quote> h6x9  = new RelinkableHandle <Quote>();  h6x9.linkTo(fra6x9Rate);
            RelinkableHandle <Quote> h9x12 = new RelinkableHandle <Quote>(); h9x12.linkTo(fra9x12Rate);

            /*********************
            ***  RATE HELPERS ***
            *********************/

            // RateHelpers are built from the above quotes together with
            // other instrument dependant infos.  Quotes are passed in
            // relinkable handles which could be relinked to some other
            // data source later.

            DayCounter            fraDayCounter = euribor3m.dayCounter();
            BusinessDayConvention convention    = euribor3m.businessDayConvention();
            bool endOfMonth = euribor3m.endOfMonth();

            RateHelper fra1x4 = new FraRateHelper(h1x4, 1, 4,
                                                  fixingDays, calendar, convention,
                                                  endOfMonth, fraDayCounter);

            RateHelper fra2x5 = new FraRateHelper(h2x5, 2, 5,
                                                  fixingDays, calendar, convention,
                                                  endOfMonth, fraDayCounter);

            RateHelper fra3x6 = new FraRateHelper(h3x6, 3, 6,
                                                  fixingDays, calendar, convention,
                                                  endOfMonth, fraDayCounter);

            RateHelper fra6x9 = new FraRateHelper(h6x9, 6, 9,
                                                  fixingDays, calendar, convention,
                                                  endOfMonth, fraDayCounter);

            RateHelper fra9x12 = new FraRateHelper(h9x12, 9, 12,
                                                   fixingDays, calendar, convention,
                                                   endOfMonth, fraDayCounter);


            /*********************
            **  CURVE BUILDING **
            *********************/

            // Any DayCounter would be fine.
            // ActualActual::ISDA ensures that 30 years is 30.0
            DayCounter termStructureDayCounter = new ActualActual(ActualActual.Convention.ISDA);

            double tolerance = 1.0e-15;

            // A FRA curve
            List <RateHelper> fraInstruments = new List <RateHelper>();

            fraInstruments.Add(fra1x4);
            fraInstruments.Add(fra2x5);
            fraInstruments.Add(fra3x6);
            fraInstruments.Add(fra6x9);
            fraInstruments.Add(fra9x12);

            YieldTermStructure fraTermStructure = new PiecewiseYieldCurve <Discount, LogLinear>(
                settlementDate, fraInstruments, termStructureDayCounter,
                new List <Handle <Quote> >(), new List <Date>(), tolerance);


            // Term structures used for pricing/discounting
            RelinkableHandle <YieldTermStructure> discountingTermStructure = new RelinkableHandle <YieldTermStructure>();

            discountingTermStructure.linkTo(fraTermStructure);


            /***********************
            ***  construct FRA's ***
            ***********************/

            Calendar fraCalendar = euribor3m.fixingCalendar();
            BusinessDayConvention fraBusinessDayConvention = euribor3m.businessDayConvention();

            Position.Type fraFwdType    = Position.Type.Long;
            double        fraNotional   = 100.0;
            const int     FraTermMonths = 3;

            int[] monthsToStart = new [] { 1, 2, 3, 6, 9 };

            euriborTermStructure.linkTo(fraTermStructure);

            Console.WriteLine("\nTest FRA construction, NPV calculation, and FRA purchase\n");

            int i;

            for (i = 0; i < monthsToStart.Length; i++)
            {
                Date fraValueDate = fraCalendar.advance(
                    settlementDate, monthsToStart[i], TimeUnit.Months,
                    fraBusinessDayConvention);

                Date fraMaturityDate = fraCalendar.advance(
                    fraValueDate, FraTermMonths, TimeUnit.Months,
                    fraBusinessDayConvention);

                double fraStrikeRate = threeMonthFraQuote[monthsToStart[i]];

                ForwardRateAgreement myFRA = new ForwardRateAgreement(fraValueDate, fraMaturityDate,
                                                                      fraFwdType, fraStrikeRate,
                                                                      fraNotional, euribor3m,
                                                                      discountingTermStructure);

                Console.WriteLine("3m Term FRA, Months to Start: " + monthsToStart[i]);

                Console.WriteLine("strike FRA rate: {0:0.00%}", fraStrikeRate);
                Console.WriteLine("FRA 3m forward rate: {0:0.00%}", myFRA.forwardRate());
                Console.WriteLine("FRA market quote: {0:0.00%}", threeMonthFraQuote[monthsToStart[i]]);
                Console.WriteLine("FRA spot value: " + myFRA.spotValue());
                Console.WriteLine("FRA forward value: " + myFRA.forwardValue());
                Console.WriteLine("FRA implied Yield: {0:0.00%}",
                                  myFRA.impliedYield(myFRA.spotValue(), myFRA.forwardValue(), settlementDate, Compounding.Simple, fraDayCounter));
                Console.WriteLine("market Zero Rate: {0:0.00%}",
                                  discountingTermStructure.link.zeroRate(fraMaturityDate, fraDayCounter, Compounding.Simple));
                Console.WriteLine("FRA NPV [should be zero]: {0}\n", myFRA.NPV());
            }



            Console.WriteLine("\n");
            Console.WriteLine("Now take a 100 basis-point upward shift in FRA quotes and examine NPV\n");


            const double BpsShift = 0.01;

            threeMonthFraQuote[1] = 0.030 + BpsShift;
            threeMonthFraQuote[2] = 0.031 + BpsShift;
            threeMonthFraQuote[3] = 0.032 + BpsShift;
            threeMonthFraQuote[6] = 0.033 + BpsShift;
            threeMonthFraQuote[9] = 0.034 + BpsShift;

            fra1x4Rate.setValue(threeMonthFraQuote[1]);
            fra2x5Rate.setValue(threeMonthFraQuote[2]);
            fra3x6Rate.setValue(threeMonthFraQuote[3]);
            fra6x9Rate.setValue(threeMonthFraQuote[6]);
            fra9x12Rate.setValue(threeMonthFraQuote[9]);


            for (i = 0; i < monthsToStart.Length; i++)
            {
                Date fraValueDate = fraCalendar.advance(
                    settlementDate, monthsToStart[i], TimeUnit.Months,
                    fraBusinessDayConvention);

                Date fraMaturityDate = fraCalendar.advance(
                    fraValueDate, FraTermMonths, TimeUnit.Months,
                    fraBusinessDayConvention);

                double fraStrikeRate = threeMonthFraQuote[monthsToStart[i]] - BpsShift;

                ForwardRateAgreement myFRA = new ForwardRateAgreement(fraValueDate, fraMaturityDate,
                                                                      fraFwdType, fraStrikeRate,
                                                                      fraNotional, euribor3m,
                                                                      discountingTermStructure);

                Console.WriteLine("3m Term FRA, 100 notional, Months to Start: " + monthsToStart[i]);
                Console.WriteLine("strike FRA rate: {0:0.00%}", fraStrikeRate);
                Console.WriteLine("FRA 3m forward rate: {0:0.00%}", myFRA.forwardRate());
                Console.WriteLine("FRA market quote: {0:0.00%}", threeMonthFraQuote[monthsToStart[i]]);
                Console.WriteLine("FRA spot value: " + myFRA.spotValue());
                Console.WriteLine("FRA forward value: " + myFRA.forwardValue());
                Console.WriteLine("FRA implied Yield: {0:0.00%}",
                                  myFRA.impliedYield(myFRA.spotValue(), myFRA.forwardValue(), settlementDate, Compounding.Simple, fraDayCounter));
                Console.WriteLine("market Zero Rate: {0:0.00%}",
                                  discountingTermStructure.link.zeroRate(fraMaturityDate, fraDayCounter, Compounding.Simple));
                Console.WriteLine("FRA NPV [should be positive]: {0}\n", myFRA.NPV());
            }

            Console.WriteLine(" \nRun completed in {0}", DateTime.Now - timer);
            Console.WriteLine();

            Console.Write("Press any key to continue ...");
            Console.ReadKey();
        }
 public PiecewiseLinearZero(int settlementDays, Calendar calendar, RateHelperVector instruments, DayCounter dayCounter) : this(NQuantLibcPINVOKE.new_PiecewiseLinearZero__SWIG_9(settlementDays, Calendar.getCPtr(calendar), RateHelperVector.getCPtr(instruments), DayCounter.getCPtr(dayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #54
0
 public static BlackVolTermStructure flatVol(Date today, double vol, DayCounter dc)
 {
     return(flatVol(today, new SimpleQuote(vol), dc));
 }
예제 #55
0
 //! floating reference date, fixed market data
 public ConstantOptionletVolatility(int settlementDays, Calendar cal, BusinessDayConvention bdc,
                                    double vol, DayCounter dc)
     : base(settlementDays, cal, bdc, dc)
 {
     volatility_ = new Handle <Quote>(new SimpleQuote(vol));
 }
예제 #56
0
 public PiecewiseYieldCurve(Date referenceDate, List <RateHelper> instruments,
                            DayCounter dayCounter, List <Handle <Quote> > jumps,
                            List <Date> jumpDates, double accuracy, Interpolator i)
     : this(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, i, new BootStrap())
 {
 }
예제 #57
0
 //public InterpolatedYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments,
 //                              DayCounter dayCounter) :
 //    this(settlementDays, calendar, instruments, dayCounter, new SimpleQuote()) { }
 //public InterpolatedYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments,
 //                              DayCounter dayCounter, Quote turnOfYearEffect) :
 //    this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, 1.0e-12) { }
 //List<Handle<Quote>> jumps = std::vector<Handle<Quote> >(),
 //List<Date> jumpDates = std::vector<Date>(),
 public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List <RateHelper> instruments,
                            DayCounter dayCounter, List <Handle <Quote> > jumps, List <Date> jumpDates, double accuracy)
     : this(settlementDays, calendar, instruments, dayCounter, jumps, jumpDates, accuracy,
            new Interpolator(), new BootStrap())
 {
 }
예제 #58
0
 public DefaultDensityCurve(DateVector dates, DoubleVector densities, DayCounter dayCounter) : this(NQuantLibcPINVOKE.new_DefaultDensityCurve__SWIG_2(DateVector.getCPtr(dates), DoubleVector.getCPtr(densities), DayCounter.getCPtr(dayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #59
0
 public INonCompoundedInterestRate ImpliedRate(double factor,
                                               double time,
                                               DayCounter dayCounter) /* do smth*/ }
예제 #60
0
 public static YieldTermStructure flatRate(Quote forward, DayCounter dc)
 {
     return(new FlatForward(0, new NullCalendar(), forward, dc));
 }