public BlackConstantVol(int settlementDays, Calendar cal, Handle<Quote> volatility, DayCounter dc) : base(settlementDays, cal, BusinessDayConvention.Following, dc) { volatility_ = volatility; volatility_.registerWith(update); }
//! fixed-rate bond /*! \ingroup instruments \test calculations are tested by checking results against cached values. */ //! simple annual compounding coupon rates public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule,List<double> coupons, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following, double redemption = 100, Date issueDate = null,Calendar paymentCalendar = null, Period exCouponPeriod = null, Calendar exCouponCalendar = null, BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted, bool exCouponEndOfMonth = false) : base(settlementDays, paymentCalendar == null ? schedule.calendar() : paymentCalendar, issueDate) { frequency_ = schedule.tenor().frequency(); dayCounter_ = accrualDayCounter; maturityDate_ = schedule.endDate(); cashflows_ = new FixedRateLeg(schedule) .withCouponRates(coupons, accrualDayCounter) .withExCouponPeriod(exCouponPeriod, exCouponCalendar, exCouponConvention, exCouponEndOfMonth) .withPaymentCalendar(calendar_) .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"); }
// results //private double? fairSpread1_; //private double? fairSpread2_; // 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) { }
public BlackConstantVol(Date referenceDate, Calendar cal, Handle<Quote> volatility, DayCounter dc) : base(referenceDate, cal, BusinessDayConvention.Following, dc) { volatility_ = volatility; volatility_.registerWith(update); }
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]); }
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); }
public AmortizingFixedRateBond( int settlementDays, List<double> notionals, Schedule schedule, List<double> coupons, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following, Date issueDate = null) :base(settlementDays, schedule.calendar(), issueDate) { frequency_ = schedule.tenor().frequency(); dayCounter_ = accrualDayCounter; schedule_ = schedule; maturityDate_ = schedule.endDate(); cashflows_ = new FixedRateLeg(schedule) .withCouponRates(coupons, accrualDayCounter) .withNotionals(notionals) .withPaymentAdjustment(paymentConvention).value(); addRedemptionsToCashflows(); if ( cashflows().empty()) throw new ApplicationException("bond with no cashflows!"); }
public AmortizingFixedRateBond( int settlementDays, Calendar calendar, double faceAmount, Date startDate, Period bondTenor, Frequency sinkingFrequency, double coupon, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following, Date issueDate = null) :base(settlementDays, calendar, issueDate) { frequency_ = sinkingFrequency; dayCounter_ = accrualDayCounter; Utils.QL_REQUIRE( bondTenor.length() > 0,() => "bond tenor must be positive. " + bondTenor + " is not allowed." ); maturityDate_ = startDate + bondTenor; maturityDate_ = startDate + bondTenor; schedule_ = sinkingSchedule(startDate, bondTenor, sinkingFrequency, calendar); cashflows_ = new FixedRateLeg(schedule_) .withCouponRates(coupon, accrualDayCounter) .withNotionals(sinkingNotionals(bondTenor, sinkingFrequency, coupon, faceAmount)) .withPaymentAdjustment(paymentConvention).value(); addRedemptionsToCashflows(); }
public CallableBondConstantVolatility(int settlementDays, Calendar calendar, double volatility, DayCounter dayCounter) :base(settlementDays, calendar) { volatility_ = new Handle<Quote>(new SimpleQuote(volatility)); dayCounter_ = dayCounter; maxBondTenor_ = new Period(100,TimeUnit.Years); }
public CallableBondConstantVolatility(Date referenceDate, double volatility, DayCounter dayCounter) :base(referenceDate) { volatility_ = new Handle<Quote>(new SimpleQuote(volatility)); dayCounter_ = dayCounter; maxBondTenor_ = new Period(100,TimeUnit.Years); }
// setup public CommonVars() { // force garbage collection // garbage collection in .NET is rather weird and we do need when we run several tests in a row GC.Collect(); // data calendar = new TARGET(); settlementDays = 2; today = new Date(9, Month.June, 2009); compounding = Compounding.Continuous; dayCount = new Actual360(); settlementDate = calendar.advance(today, settlementDays, TimeUnit.Days); Settings.setEvaluationDate(today); int[] ts = new int[] { 13, 41, 75, 165, 256, 345, 524, 703 }; double[] r = new double[] { 0.035, 0.033, 0.034, 0.034, 0.036, 0.037, 0.039, 0.040 }; List<double> rates = new List<double>() { 0.035 }; List<Date> dates = new List<Date>() { settlementDate }; for (int i = 0; i < 8; ++i) { dates.Add(calendar.advance(today, ts[i], TimeUnit.Days)); rates.Add(r[i]); } termStructure = new InterpolatedZeroCurve<Linear>(dates, rates, dayCount); }
public void BuildDates(QLNet.Calendar calendar, QLNet.DayCounter dc) { _dates.Resize(_tenors.Count); Date today = Settings.evaluationDate(); for (int i = 0; i < _tenors.Count; i++) { if (_tenors[i].units() == TimeUnit.Days) { _dates[i] = calendar.adjust(today + _tenors[i]); } else { _dates[i] = calendar.advance(today, _tenors[i], BusinessDayConvention.Following, true); } } QLNet.Utils.QL_REQUIRE(_dates.Count == _tenors.Count, () => "Date/Tenor mismatch"); // Build times _times.Resize(_dates.Count); for (int i = 0; i < _dates.Count; i++) { _times[i] = dc.yearFraction(today, _dates[i]); } _timeGrid = new TimeGrid(_times, _times.Count); // Log the date grid //log(); }
// 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 == null ? new DayCounter() : dayCounter ; fixingDays_ = fixingDays == default(int) ? index.fixingDays() : fixingDays; gearing_ = gearing; spread_ = spread; isInArrears_ = isInArrears; if (gearing_ == 0) throw new ArgumentException("Null gearing not allowed"); if (dayCounter_.empty()) dayCounter_ = index_.dayCounter(); // add as observer index_.registerWith(update); Settings.registerWith(update); }
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) { }
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) { }
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; }
public DiscretizedCallableFixedRateBond(CallableBond.Arguments args, Date referenceDate, DayCounter dayCounter) { arguments_ = args; redemptionTime_ = dayCounter.yearFraction(referenceDate, args.redemptionDate); for (int i = 0; i < args.couponDates.Count ; ++i) couponTimes_.Add(dayCounter.yearFraction(referenceDate, args.couponDates[i])); for (int i = 0; i < args.callabilityDates.Count ; ++i) callabilityTimes_.Add( dayCounter.yearFraction(referenceDate, args.callabilityDates[i])); // similar to the tree swaption engine, we collapse similar coupon // and exercise dates to avoid mispricing. Delete if unnecessary. for (int i = 0; i < callabilityTimes_.Count; i++) { double exerciseTime = callabilityTimes_[i]; for (int j = 0; j < couponTimes_.Count ; j++) { if (withinNextWeek(exerciseTime, couponTimes_[j])) couponTimes_[j] = exerciseTime; } } }
public TermStructure(DayCounter dc) { moving_ = false; updated_ = true; settlementDays_ = default(int); dayCounter_ = dc; }
// 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 CmsCoupon(nominal, paymentDate, startDate, endDate, fixingDays, (SwapIndex)index, gearing, spread, refPeriodStart, refPeriodEnd, dayCounter, isInArrears); }
SwaptionHelper( Date exerciseDate, Period length, Handle<Quote> volatility, IborIndex index, Period fixedLegTenor, DayCounter fixedLegDayCounter, DayCounter floatingLegDayCounter, Handle<YieldTermStructure> termStructure, CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError, double? strike = null, double nominal = 1.0) : base(volatility, termStructure, errorType) { exerciseDate_ = exerciseDate; endDate_ = null; maturity_ = new Period(0,TimeUnit.Days); length_ = length; fixedLegTenor_ = fixedLegTenor; index_ = index; fixedLegDayCounter_ = fixedLegDayCounter; floatingLegDayCounter_ = floatingLegDayCounter; strike_ = strike; nominal_ = nominal; index_.registerWith( update ); }
// constructors public FixedRateCoupon(double nominal, Date paymentDate, double rate, DayCounter dayCounter, Date accrualStartDate, Date accrualEndDate, Date refPeriodStart = null, Date refPeriodEnd = null,double? amount = null) : base(nominal, paymentDate, accrualStartDate, accrualEndDate, refPeriodStart, refPeriodEnd, amount) { rate_ = new InterestRate(rate, dayCounter, Compounding.Simple,Frequency.Annual); }
// There are three ways in which a term structure can keep // track of its reference date. The first is that such date // is fixed; the second is that it is determined by advancing // the current date of a given number of business days; and // the third is that it is based on the reference date of // some other structure. // // In the first case, the constructor taking a date is to be // used; the default implementation of referenceDate() will // then return such date. In the second case, the constructor // taking a number of days and a calendar is to be used; // referenceDate() will return a date calculated based on the // current evaluation date, and the term structure and its // observers will be notified when the evaluation date // changes. In the last case, the referenceDate() method must // be overridden in derived classes so that it fetches and // return the appropriate date. //! default constructor /*! \warning term structures initialized by means of this constructor must manage their own reference date by overriding the referenceDate() method. */ public TermStructure(DayCounter dc = null) { moving_ = false; updated_ = true; settlementDays_ = null; dayCounter_ = dc; }
public BlackSwaptionEngine(Handle<YieldTermStructure> termStructure, double vol, DayCounter dc ) { termStructure_ = termStructure; volatility_ = new Handle<SwaptionVolatilityStructure>(new ConstantSwaptionVolatility(0, new NullCalendar(), BusinessDayConvention.Following, vol, dc)); termStructure_.registerWith(update); }
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); }
public CallableBondConstantVolatility(Date referenceDate, Handle<Quote> volatility, DayCounter dayCounter) :base(referenceDate) { volatility_ = volatility; dayCounter_ = dayCounter; maxBondTenor_ = new Period(100,TimeUnit.Years); volatility_.registerWith(update); }
public IborIndex(string familyName, Period tenor, int settlementDays, Currency currency, Calendar fixingCalendar, BusinessDayConvention convention, bool endOfMonth, DayCounter dayCounter) : this(familyName, tenor, settlementDays, currency, fixingCalendar, convention, endOfMonth, dayCounter, new Handle<YieldTermStructure>()) { }
public CallableBondConstantVolatility(int settlementDays, Calendar calendar, Handle<Quote> volatility,DayCounter dayCounter) :base(settlementDays, calendar) { volatility_ = volatility; dayCounter_ = dayCounter; maxBondTenor_ = new Period(100,TimeUnit.Years); volatility_.registerWith(update); }
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); }
//! 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); }
public LocalConstantVol(int settlementDays, Calendar calendar, Handle<Quote> volatility, DayCounter dayCounter) : base(settlementDays,calendar) { volatility_ = volatility; dayCounter_ = dayCounter; volatility_.registerWith(update); }
//! 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); }
protected ZeroYieldStructure(DayCounter dc = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null) : base(dc, jumps, jumpDates) { }
protected ZeroYieldStructure(Date referenceDate, Calendar calendar = null, DayCounter dc = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null) : base(referenceDate, calendar, dc, jumps, jumpDates) { }
protected ZeroYieldStructure(int settlementDays, Calendar calendar, DayCounter dc = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null) : base(settlementDays, calendar, dc, jumps, jumpDates) { }
public AverageBMALeg withPaymentDayCounter(DayCounter dayCounter) { paymentDayCounter_ = dayCounter; return(this); }
//! calculate the reference date based on the global evaluation date public SwaptionVolatilityStructure(int settlementDays, Calendar cal, BusinessDayConvention bdc, DayCounter dc = null) : base(settlementDays, cal, bdc, dc) { }
//! initialize with a fixed reference date public VolatilityTermStructure(Date referenceDate, Calendar cal, BusinessDayConvention bdc, DayCounter dc = null) : base(referenceDate, cal, dc) { bdc_ = bdc; }
// other initializers public FixedRateLeg withCouponRates(double couponRate, DayCounter paymentDayCounter) { return(withCouponRates(couponRate, paymentDayCounter, Compounding.Simple, Frequency.Annual)); }
private int bmaCutoffDays = 0; // to be verified // 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()); }
/*! \warning term structures initialized by means of this * constructor must manage their own reference date * by overriding the referenceDate() method. */ public VolatilityTermStructure(BusinessDayConvention bdc, DayCounter dc = null) : base(dc) { bdc_ = bdc; }
public override void calculate() { double basisPoint = 1.0e-4; Date exerciseDate = arguments_.exercise.date(0); // the part of the swap preceding exerciseDate should be truncated // to avoid taking into account unwanted cashflows VanillaSwap swap = arguments_.swap; double strike = swap.fixedRate; // using the forecasting curve swap.setPricingEngine(new DiscountingSwapEngine(swap.iborIndex().forwardingTermStructure())); double atmForward = swap.fairRate(); // Volatilities are quoted for zero-spreaded swaps. // Therefore, any spread on the floating leg must be removed // with a corresponding correction on the fixed leg. if (swap.spread.IsNotEqual(0.0)) { double correction = swap.spread * Math.Abs(swap.floatingLegBPS() / swap.fixedLegBPS()); strike -= correction; atmForward -= correction; results_.additionalResults["spreadCorrection"] = correction; } else { results_.additionalResults["spreadCorrection"] = 0.0; } results_.additionalResults["strike"] = strike; results_.additionalResults["atmForward"] = atmForward; // using the discounting curve swap.setPricingEngine(new DiscountingSwapEngine(termStructure_)); double annuity = 0; switch (arguments_.settlementType) { case Settlement.Type.Physical: { annuity = Math.Abs(swap.fixedLegBPS()) / basisPoint; break; } case Settlement.Type.Cash: { List <CashFlow> fixedLeg = swap.fixedLeg(); FixedRateCoupon firstCoupon = (FixedRateCoupon)fixedLeg[0]; DayCounter dayCount = firstCoupon.dayCounter(); double fixedLegCashBPS = CashFlows.bps(fixedLeg, new InterestRate(atmForward, dayCount, QLNet.Compounding.Compounded, Frequency.Annual), false, termStructure_.link.referenceDate()); annuity = Math.Abs(fixedLegCashBPS / basisPoint); break; } default: Utils.QL_FAIL("unknown settlement type"); break; } results_.additionalResults["annuity"] = annuity; // the swap length calculation might be improved using the value date // of the exercise date double swapLength = volatility_.link.swapLength(exerciseDate, arguments_.floatingPayDates.Last()); results_.additionalResults["swapLength"] = swapLength; double variance = volatility_.link.blackVariance(exerciseDate, swapLength, strike); double stdDev = Math.Sqrt(variance); results_.additionalResults["stdDev"] = stdDev; Option.Type w = (arguments_.type == VanillaSwap.Type.Payer) ? Option.Type.Call : Option.Type.Put; results_.value = Utils.blackFormula(w, strike, atmForward, stdDev, annuity); double exerciseTime = volatility_.link.timeFromReference(exerciseDate); results_.additionalResults["vega"] = Math.Sqrt(exerciseTime) * Utils.blackFormulaStdDevDerivative(strike, atmForward, stdDev, annuity); }
public InterpolatedHazardRateCurve(List <Date> dates, List <double> hazardRates, DayCounter dayCounter, Interpolator interpolator) : base(dates[0], null, dayCounter) { dates_ = dates; if (interpolator == null) { interpolator_ = new Interpolator(); } else { interpolator_ = interpolator; } initialize(); }
public FixedRateLeg withFirstPeriodDayCounter(DayCounter dayCounter) { firstPeriodDC_ = dayCounter; return(this); }
protected override void performCalculations() { List <BTP> btps = basket_.btps(); List <Handle <Quote> > quotes = basket_.cleanPriceQuotes(); Date bondSettlementDate = btps[0].settlementDate(); for (int i = 0; i < basket_.size(); ++i) { yields_[i] = BondFunctions.yield(btps[i], quotes[i].link.value(), new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, bondSettlementDate, // accuracy, maxIterations, guess 1.0e-10, 100, yields_[i]); durations_[i] = BondFunctions.duration(btps[i], yields_[i], new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, Duration.Type.Modified, bondSettlementDate); } duration_ = 0; basket_.weights().ForEach((ii, vv) => duration_ += vv * yields()[ii]); //duration_ = std::inner_product(basket_->weights().begin(), // basket_->weights().end(), // durations_.begin(), 0.0); int settlDays = 2; DayCounter fixedDayCount = swaps_[0].fixedDayCount(); equivalentSwapIndex_ = nSwaps_ - 1; swapRates_[0] = swaps_[0].fairRate(); FixedRateBond swapBond = new FixedRateBond(settlDays, 100.0, // faceAmount swaps_[0].fixedSchedule(), new List <double>() { swapRates_[0].Value }, fixedDayCount, BusinessDayConvention.Following, // paymentConvention 100.0); // redemption swapBondYields_[0] = BondFunctions.yield(swapBond, 100.0, // floating leg NPV including end payment new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, bondSettlementDate, // accuracy, maxIterations, guess 1.0e-10, 100, swapBondYields_[0].Value); swapBondDurations_[0] = BondFunctions.duration(swapBond, swapBondYields_[0].Value, new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, Duration.Type.Modified, bondSettlementDate); for (int i = 1; i < nSwaps_; ++i) { swapRates_[i] = swaps_[i].fairRate(); FixedRateBond swapBond2 = new FixedRateBond(settlDays, 100.0, // faceAmount swaps_[i].fixedSchedule(), new List <double>() { swapRates_[i].Value }, fixedDayCount, BusinessDayConvention.Following, // paymentConvention 100.0); // redemption swapBondYields_[i] = BondFunctions.yield(swapBond2, 100.0, // floating leg NPV including end payment new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, bondSettlementDate, // accuracy, maxIterations, guess 1.0e-10, 100, swapBondYields_[i].Value); swapBondDurations_[i] = BondFunctions.duration(swapBond2, swapBondYields_[i].Value, new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, Duration.Type.Modified, bondSettlementDate); if (swapBondDurations_[i] > duration_) { equivalentSwapIndex_ = i - 1; break; // exit the loop } } return; }
public FixedRateLeg withCouponRates(List <double> couponRates, DayCounter paymentDayCounter, Compounding comp) { return(withCouponRates(couponRates, paymentDayCounter, comp, Frequency.Annual)); }
//! default constructor /*! \warning term structures initialized by means of this * constructor must manage their own reference date * by overriding the referenceDate() method. */ //public LocalVolTermStructure() // : base(BusinessDayConvention.Following, null) { } public LocalVolTermStructure(BusinessDayConvention bdc = BusinessDayConvention.Following, DayCounter dc = null) : base(bdc, dc) { }
public SurvivalProbabilityStructure(DayCounter dayCounter = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null) : base(dayCounter, jumps, jumpDates) { }
public SwaptionVolatilityStructure(BusinessDayConvention bdc, DayCounter dc = null) : base(bdc, dc) { }
//! calculate the reference date based on the global evaluation date public VolatilityTermStructure(int settlementDays, Calendar cal, BusinessDayConvention bdc, DayCounter dc = null) : base(settlementDays, cal, dc) { bdc_ = bdc; }
//! initialize with a fixed reference date public SwaptionVolatilityStructure(Date referenceDate, Calendar calendar, BusinessDayConvention bdc, DayCounter dc = null) : base(referenceDate, calendar, bdc, dc) { }
//! clean price given a yield and settlement date /*! The default bond settlement is used if no date is given. */ public double cleanPrice(double yield, DayCounter dc, Compounding comp, Frequency freq, Date settlement = null) { return(BondFunctions.cleanPrice(this, yield, dc, comp, freq, settlement)); }
public InterpolatedHazardRateCurve(List <Date> dates, List <double> hazardRates, DayCounter dayCounter, Calendar cal = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator)) : base(dates[0], cal, dayCounter, jumps, jumpDates) { dates_ = dates; times_ = new List <double>(); data_ = hazardRates; if (interpolator == null) { interpolator_ = new Interpolator(); } else { interpolator_ = interpolator; } initialize(); }
public static List <CashFlow> yoyInflationLeg(List <double> notionals_, Schedule schedule_, BusinessDayConvention paymentAdjustment_, YoYInflationIndex index_, List <double> gearings_, List <double> spreads_, DayCounter paymentDayCounter_, List <double> caps_, List <double> floors_, Calendar paymentCalendar_, List <int> fixingDays_, Period observationLag_) { int n = schedule_.Count - 1; if (notionals_.empty()) { throw new ApplicationException("no notional given"); } if (notionals_.Count > n) { throw new ApplicationException("too many nominals (" + notionals_.Count + "), only " + n + " required"); } if (gearings_ != null && gearings_.Count > n) { throw new ApplicationException("too many gearings (" + gearings_.Count + "), only " + n + " required"); } if (spreads_ != null && spreads_.Count > n) { throw new ApplicationException("too many spreads (" + spreads_.Count + "), only " + n + " required"); } if (caps_ != null && caps_.Count > n) { throw new ApplicationException("too many caps (" + caps_.Count + "), only " + n + " required"); } if (floors_ != null && floors_.Count > n) { throw new ApplicationException("too many floors (" + floors_.Count + "), only " + n + " required"); } List <CashFlow> leg = new List <CashFlow>(n); Calendar calendar = paymentCalendar_; Date refStart, start, refEnd, end; //Date lastPaymentDate = calendar.adjust(schedule_.date(n), paymentAdjustment_); for (int i = 0; i < n; ++i) { refStart = start = schedule_.date(i); refEnd = end = schedule_.date(i + 1); Date paymentDate = calendar.adjust(end, paymentAdjustment_); if (i == 0 && !schedule_.isRegular(i + 1)) { BusinessDayConvention bdc = schedule_.businessDayConvention(); refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc); } if (i == n - 1 && !schedule_.isRegular(i + 1)) { BusinessDayConvention bdc = schedule_.businessDayConvention(); refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc); } if (Utils.Get(gearings_, i, 1.0) == 0.0) { // fixed coupon leg.Add(new FixedRateCoupon(Utils.Get(notionals_, i, 1.0), paymentDate, Utils.effectiveFixedRate(spreads_, caps_, floors_, i), paymentDayCounter_, start, end, refStart, refEnd)); } else { // yoy inflation coupon if (Utils.noOption(caps_, floors_, i)) { // just swaplet YoYInflationCoupon coup = new YoYInflationCoupon(paymentDate, Utils.Get(notionals_, i, 1.0), start, end, Utils.Get(fixingDays_, i, 0), index_, observationLag_, paymentDayCounter_, Utils.Get(gearings_, i, 1.0), Utils.Get(spreads_, i, 0.0), refStart, refEnd); // in this case you can set a pricer // straight away because it only provides computation - not data YoYInflationCouponPricer pricer = new YoYInflationCouponPricer(); coup.setPricer(pricer); leg.Add(coup); } else { // cap/floorlet leg.Add(new CappedFlooredYoYInflationCoupon( paymentDate, Utils.Get(notionals_, i, 1.0), start, end, Utils.Get(fixingDays_, i, 0), index_, observationLag_, paymentDayCounter_, Utils.Get(gearings_, i, 1.0), Utils.Get(spreads_, i, 0.0), Utils.toNullable(Utils.Get(caps_, i, Double.MinValue)), Utils.toNullable(Utils.Get(floors_, i, Double.MinValue)), refStart, refEnd)); } } } return(leg); }
public static List <CashFlow> FloatingLeg <InterestRateIndexType, FloatingCouponType, CappedFlooredCouponType>(List <double> nominals, Schedule schedule, InterestRateIndexType index, DayCounter paymentDayCounter, BusinessDayConvention paymentAdj, List <int> fixingDays, List <double> gearings, List <double> spreads, List <double> caps, List <double> floors, bool isInArrears, bool isZero) where InterestRateIndexType : InterestRateIndex, new() where FloatingCouponType : FloatingRateCoupon, new() where CappedFlooredCouponType : CappedFlooredCoupon, new() { int n = schedule.Count; if (nominals.Count == 0) { throw new ArgumentException("no notional given"); } if (nominals.Count > n) { throw new ArgumentException( "too many nominals (" + nominals.Count + "), only " + n + " required"); } if (gearings != null && gearings.Count > n) { throw new ArgumentException( "too many gearings (" + gearings.Count + "), only " + n + " required"); } if (spreads != null && spreads.Count > n) { throw new ArgumentException( "too many spreads (" + spreads.Count + "), only " + n + " required"); } if (caps != null && caps.Count > n) { throw new ArgumentException( "too many caps (" + caps.Count + "), only " + n + " required"); } if (floors != null && floors.Count > n) { throw new ArgumentException( "too many floors (" + floors.Count + "), only " + n + " required"); } if (isZero && isInArrears) { throw new ArgumentException("in-arrears and zero features are not compatible"); } List <CashFlow> leg = new List <CashFlow>(); // the following is not always correct Calendar calendar = schedule.calendar(); Date refStart, start, refEnd, end; Date lastPaymentDate = calendar.adjust(schedule[n - 1], paymentAdj); for (int i = 0; i < n - 1; ++i) { refStart = start = schedule[i]; refEnd = end = schedule[i + 1]; Date paymentDate = isZero ? lastPaymentDate : calendar.adjust(end, paymentAdj); if (i == 0 && !schedule.isRegular(i + 1)) { refStart = calendar.adjust(end - schedule.tenor(), schedule.businessDayConvention()); } if (i == n - 1 && !schedule.isRegular(i + 1)) { refEnd = calendar.adjust(start + schedule.tenor(), schedule.businessDayConvention()); } if (Utils.Get(gearings, i, 1) == 0) // fixed coupon { leg.Add(new FixedRateCoupon(Utils.Get(nominals, i), paymentDate, Utils.effectiveFixedRate(spreads, caps, floors, i), paymentDayCounter, start, end, refStart, refEnd)); } else { if (Utils.noOption(caps, floors, i)) { leg.Add(new FloatingCouponType().factory(Utils.Get(nominals, i), paymentDate, start, end, Utils.Get(fixingDays, i, index.fixingDays()), index, Utils.Get(gearings, i, 1), Utils.Get(spreads, i), refStart, refEnd, paymentDayCounter, isInArrears)); } else { leg.Add(new CappedFlooredCouponType().factory(Utils.Get(nominals, i), paymentDate, start, end, Utils.Get(fixingDays, i, index.fixingDays()), index, Utils.Get(gearings, i, 1), Utils.Get(spreads, i), Utils.toNullable(Utils.Get(caps, i, Double.MinValue)), Utils.toNullable(Utils.Get(floors, i, Double.MinValue)), refStart, refEnd, paymentDayCounter, isInArrears)); } } } return(leg); }
public CPISwap(Type type, double nominal, bool subtractInflationNominal, // float+spread leg double spread, DayCounter floatDayCount, Schedule floatSchedule, BusinessDayConvention floatPaymentRoll, int fixingDays, IborIndex floatIndex, // fixed x inflation leg double fixedRate, double baseCPI, DayCounter fixedDayCount, Schedule fixedSchedule, BusinessDayConvention fixedPaymentRoll, Period observationLag, ZeroInflationIndex fixedIndex, InterpolationType observationInterpolation = InterpolationType.AsIndex, double?inflationNominal = null) : base(2) { type_ = type; nominal_ = nominal; subtractInflationNominal_ = subtractInflationNominal; spread_ = spread; floatDayCount_ = floatDayCount; floatSchedule_ = floatSchedule; floatPaymentRoll_ = floatPaymentRoll; fixingDays_ = fixingDays; floatIndex_ = floatIndex; fixedRate_ = fixedRate; baseCPI_ = baseCPI; fixedDayCount_ = fixedDayCount; fixedSchedule_ = fixedSchedule; fixedPaymentRoll_ = fixedPaymentRoll; fixedIndex_ = fixedIndex; observationLag_ = observationLag; observationInterpolation_ = observationInterpolation; Utils.QL_REQUIRE(floatSchedule_.Count > 0, () => "empty float schedule"); Utils.QL_REQUIRE(fixedSchedule_.Count > 0, () => "empty fixed schedule"); // todo if roll!=unadjusted then need calendars ... inflationNominal_ = inflationNominal ?? nominal_; List <CashFlow> floatingLeg; if (floatSchedule_.Count > 1) { floatingLeg = new IborLeg(floatSchedule_, floatIndex_) .withFixingDays(fixingDays_) .withPaymentDayCounter(floatDayCount_) .withSpreads(spread_) .withNotionals(nominal_) .withPaymentAdjustment(floatPaymentRoll_); } else { floatingLeg = new List <CashFlow>(); } if (floatSchedule_.Count == 1 || !subtractInflationNominal_ || (subtractInflationNominal && Math.Abs(nominal_ - inflationNominal_) > 0.00001) ) { Date payNotional; if (floatSchedule_.Count == 1) { // no coupons payNotional = floatSchedule_[0]; payNotional = floatSchedule_.calendar().adjust(payNotional, floatPaymentRoll_); } else { // use the pay date of the last coupon payNotional = floatingLeg.Last().date(); } double floatAmount = subtractInflationNominal_ ? nominal_ - inflationNominal_ : nominal_; CashFlow nf = new SimpleCashFlow(floatAmount, payNotional); floatingLeg.Add(nf); } // a CPIleg know about zero legs and inclusion of base inflation notional List <CashFlow> cpiLeg = new CPILeg(fixedSchedule_, fixedIndex_, baseCPI_, observationLag_) .withFixedRates(fixedRate_) .withPaymentDayCounter(fixedDayCount_) .withObservationInterpolation(observationInterpolation_) .withSubtractInflationNominal(subtractInflationNominal_) .withNotionals(inflationNominal_) .withPaymentAdjustment(fixedPaymentRoll_); foreach (CashFlow cashFlow in cpiLeg) { cashFlow.registerWith(update); } if (floatingLeg.Count > 0) { foreach (CashFlow cashFlow in floatingLeg) { cashFlow.registerWith(update); } } legs_[0] = cpiLeg; legs_[1] = floatingLeg; if (type_ == Type.Payer) { payer_[0] = 1.0; payer_[1] = -1.0; } else { payer_[0] = -1.0; payer_[1] = 1.0; } }
public static List <CashFlow> FloatingDigitalLeg <InterestRateIndexType, FloatingCouponType, DigitalCouponType>(List <double> nominals, Schedule schedule, InterestRateIndexType index, DayCounter paymentDayCounter, BusinessDayConvention paymentAdj, List <int> fixingDays, List <double> gearings, List <double> spreads, bool isInArrears, List <double> callStrikes, Position.Type callPosition, bool isCallATMIncluded, List <double> callDigitalPayoffs, List <double> putStrikes, Position.Type putPosition, bool isPutATMIncluded, List <double> putDigitalPayoffs, DigitalReplication replication) where InterestRateIndexType : InterestRateIndex, new() where FloatingCouponType : FloatingRateCoupon, new() where DigitalCouponType : DigitalCoupon, new() { int n = schedule.Count; if (nominals.Count == 0) { throw new ArgumentException("no nominal given"); } if (nominals.Count > n) { throw new ArgumentException( "too many nominals (" + nominals.Count + "), only " + n + " required"); } if (gearings != null && gearings.Count > n) { throw new ArgumentException( "too many gearings (" + gearings.Count + "), only " + n + " required"); } if (spreads != null && spreads.Count > n) { throw new ArgumentException( "too many spreads (" + spreads.Count + "), only " + n + " required"); } if (callStrikes.Count > n) { throw new ArgumentException( "too many nominals (" + callStrikes.Count + "), only " + n + " required"); } if (putStrikes.Count > n) { throw new ArgumentException( "too many nominals (" + putStrikes.Count + "), only " + n + " required"); } List <CashFlow> leg = new List <CashFlow>(); // the following is not always correct Calendar calendar = schedule.calendar(); Date refStart, start, refEnd, end; Date paymentDate; for (int i = 0; i < n; ++i) { refStart = start = schedule.date(i); refEnd = end = schedule.date(i + 1); paymentDate = calendar.adjust(end, paymentAdj); if (i == 0 && !schedule.isRegular(i + 1)) { BusinessDayConvention bdc = schedule.businessDayConvention(); refStart = calendar.adjust(end - schedule.tenor(), bdc); } if (i == n - 1 && !schedule.isRegular(i + 1)) { BusinessDayConvention bdc = schedule.businessDayConvention(); refEnd = calendar.adjust(start + schedule.tenor(), bdc); } if (Utils.Get(gearings, i, 1.0) == 0.0) // fixed coupon { leg.Add(new FixedRateCoupon(Utils.Get(nominals, i, 1.0), paymentDate, Utils.Get(spreads, i, 1.0), paymentDayCounter, start, end, refStart, refEnd)); } else // floating digital coupon { FloatingCouponType underlying = new FloatingCouponType().factory( Utils.Get(nominals, i, 1.0), paymentDate, start, end, Utils.Get(fixingDays, i, index.fixingDays()), index, Utils.Get(gearings, i, 1.0), Utils.Get(spreads, i, 0.0), refStart, refEnd, paymentDayCounter, isInArrears) as FloatingCouponType; DigitalCouponType digitalCoupon = new DigitalCouponType().factory( underlying, Utils.toNullable(Utils.Get(callStrikes, i, Double.MinValue)), callPosition, isCallATMIncluded, Utils.toNullable(Utils.Get(callDigitalPayoffs, i, Double.MinValue)), Utils.toNullable(Utils.Get(putStrikes, i, Double.MinValue)), putPosition, isPutATMIncluded, Utils.toNullable(Utils.Get(putDigitalPayoffs, i, Double.MinValue)), replication) as DigitalCouponType; leg.Add(digitalCoupon); } } return(leg); }
//! calculate the reference date based on the global evaluation date public LocalVolTermStructure(int settlementDays, Calendar cal, BusinessDayConvention bdc = BusinessDayConvention.Following, DayCounter dc = null) : base(settlementDays, cal, bdc, dc) { }
/* Generally inflation indices are available with a lag of 1month * and then observed with a lag of 2-3 months depending whether * they use an interpolated fixing or not. Here, we make the * swap use the interpolation of the index to avoid incompatibilities. */ public ZeroCouponInflationSwap(Type type, double nominal, Date startDate, // start date of contract (only) Date maturity, // this is pre-adjustment! Calendar fixCalendar, BusinessDayConvention fixConvention, DayCounter dayCounter, double fixedRate, ZeroInflationIndex infIndex, Period observationLag, bool adjustInfObsDates = false, Calendar infCalendar = null, BusinessDayConvention?infConvention = null) : base(2) { type_ = type; nominal_ = nominal; startDate_ = startDate; maturityDate_ = maturity; fixCalendar_ = fixCalendar; fixConvention_ = fixConvention; fixedRate_ = fixedRate; infIndex_ = infIndex; observationLag_ = observationLag; adjustInfObsDates_ = adjustInfObsDates; infCalendar_ = infCalendar; dayCounter_ = dayCounter; // first check compatibility of index and swap definitions if (infIndex_.interpolated()) { Period pShift = new Period(infIndex_.frequency()); Utils.QL_REQUIRE(observationLag_ - pShift > infIndex_.availabilityLag(), () => "inconsistency between swap observation of index " + observationLag_ + " index availability " + infIndex_.availabilityLag() + " interpolated index period " + pShift + " and index availability " + infIndex_.availabilityLag() + " need (obsLag-index period) > availLag"); } else { Utils.QL_REQUIRE(infIndex_.availabilityLag() < observationLag_, () => "index tries to observe inflation fixings that do not yet exist: " + " availability lag " + infIndex_.availabilityLag() + " versus obs lag = " + observationLag_); } if (infCalendar_ == null) { infCalendar_ = fixCalendar_; } if (infConvention == null) { infConvention_ = fixConvention_; } else { infConvention_ = infConvention.Value; } if (adjustInfObsDates_) { baseDate_ = infCalendar_.adjust(startDate - observationLag_, infConvention_); obsDate_ = infCalendar_.adjust(maturity - observationLag_, infConvention_); } else { baseDate_ = startDate - observationLag_; obsDate_ = maturity - observationLag_; } Date infPayDate = infCalendar_.adjust(maturity, infConvention_); Date fixedPayDate = fixCalendar_.adjust(maturity, fixConvention_); // At this point the index may not be able to forecast // i.e. do not want to force the existence of an inflation // term structure before allowing users to create instruments. double T = Utils.inflationYearFraction(infIndex_.frequency(), infIndex_.interpolated(), dayCounter_, baseDate_, obsDate_); // N.B. the -1.0 is because swaps only exchange growth, not notionals as well double fixedAmount = nominal * (Math.Pow(1.0 + fixedRate, T) - 1.0); legs_[0].Add(new SimpleCashFlow(fixedAmount, fixedPayDate)); bool growthOnly = true; legs_[1].Add(new IndexedCashFlow(nominal, infIndex, baseDate_, obsDate_, infPayDate, growthOnly)); for (int j = 0; j < 2; ++j) { legs_[j].ForEach((i, x) => x.registerWith(update)); } switch (type_) { case Type.Payer: payer_[0] = +1.0; payer_[1] = -1.0; break; case Type.Receiver: payer_[0] = -1.0; payer_[1] = +1.0; break; default: Utils.QL_FAIL("Unknown zero-inflation-swap type"); break; } }
//! initialize with a fixed reference date public LocalVolTermStructure(Date referenceDate, Calendar cal = null, BusinessDayConvention bdc = BusinessDayConvention.Following, DayCounter dc = null) : base(referenceDate, cal, bdc, dc) { }
// required for Handle //public BlackVarianceCurve() { } //public BlackVarianceCurve(Date referenceDate, List<Date> dates, List<double> blackVolCurve, DayCounter dayCounter, // bool forceMonotoneVariance = true); public BlackVarianceCurve(Date referenceDate, List <Date> dates, List <double> blackVolCurve, DayCounter dayCounter, bool forceMonotoneVariance) : base(referenceDate) { dayCounter_ = dayCounter; maxDate_ = dates.Last(); if (!(dates.Count == blackVolCurve.Count)) { throw new Exception("mismatch between date vector and black vol vector"); } // cannot have dates[0]==referenceDate, since the // value of the vol at dates[0] would be lost // (variance at referenceDate must be zero) if (!(dates[0] > referenceDate)) { throw new Exception("cannot have dates[0] <= referenceDate"); } variances_ = new InitializedList <double>(dates.Count + 1); times_ = new InitializedList <double>(dates.Count + 1); variances_[0] = 0.0; times_[0] = 0.0; for (int j = 1; j <= blackVolCurve.Count; j++) { times_[j] = timeFromReference(dates[j - 1]); if (!(times_[j] > times_[j - 1])) { throw new Exception("dates must be sorted unique!"); } variances_[j] = times_[j] * blackVolCurve[j - 1] * blackVolCurve[j - 1]; if (!(variances_[j] >= variances_[j - 1] || !forceMonotoneVariance)) { throw new Exception("variance must be non-decreasing"); } } // default: linear interpolation setInterpolation <Linear>(); }