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; }
/*! \warning Relinking the term structure underlying the index will not have effect on the returned swap. */ OvernightIndexedSwap underlyingSwap(Date fixingDate) { double fixedRate = 0.0; return new MakeOIS(tenor_, overnightIndex_, fixedRate) .withEffectiveDate(valueDate(fixingDate)) .withFixedLegDayCount(dayCounter_); }
//public ZeroCouponBond(int settlementDays, Calendar calendar, double faceAmount, Date maturityDate, // BusinessDayConvention paymentConvention = Following, // double redemption = 100.0, // Date issueDate = Date()); public ZeroCouponBond(int settlementDays, Calendar calendar, double faceAmount, Date maturityDate, BusinessDayConvention paymentConvention, double redemption, Date issueDate) : base(settlementDays, calendar, issueDate) { maturityDate_ = maturityDate; Date redemptionDate = calendar_.adjust(maturityDate, paymentConvention); setSingleRedemption(faceAmount, redemption, redemptionDate); }
// coupon does not adjust the payment date which must already be a business day public Coupon(double nominal, Date paymentDate, Date accrualStartDate, Date accrualEndDate, Date refPeriodStart = null, Date refPeriodEnd = null, double? amount = null) { nominal_ = nominal; amount_ = amount; paymentDate_ = paymentDate; accrualStartDate_ = accrualStartDate; accrualEndDate_ = accrualEndDate; refPeriodStart_ = refPeriodStart ?? accrualStartDate_; refPeriodEnd_ = refPeriodEnd ?? accrualEndDate_; }
public Principal(double amount, double nominal, Date paymentDate, Date accrualStartDate, Date accrualEndDate, DayCounter dayCounter, Date refPeriodStart, Date refPeriodEnd) { amount_ = amount; nominal_ = nominal; paymentDate_ = paymentDate; accrualStartDate_ = accrualStartDate; accrualEndDate_ = accrualEndDate; dayCounter_ = dayCounter; refPeriodStart_ = refPeriodStart ?? accrualStartDate_; refPeriodEnd_ = refPeriodEnd ?? accrualEndDate_; }
public double yoyRate(Date d, Period instObsLag, bool forceLinearInterpolation, bool extrapolate) { Period useLag = instObsLag; if (instObsLag == new Period(-1, TimeUnit.Days)) { useLag = observationLag(); } double yoyRate; if (forceLinearInterpolation) { KeyValuePair<Date, Date> dd = Utils.inflationPeriod(d - useLag, frequency()); Date ddValue = dd.Value + new Period(1, TimeUnit.Days); double dp = ddValue - dd.Key; double dt = (d - useLag) - dd.Key; // if we are interpolating we only check the exact point // this prevents falling off the end at curve maturity base.checkRange(d, extrapolate); double t1 = timeFromReference(dd.Key); double t2 = timeFromReference(dd.Value); yoyRate = yoyRateImpl(t1) + (yoyRateImpl(t2) - yoyRateImpl(t1)) * (dt / dp); } else { if (indexIsInterpolated()) { base.checkRange(d - useLag, extrapolate); double t = timeFromReference(d - useLag); yoyRate = yoyRateImpl(t); } else { KeyValuePair<Date, Date> dd = Utils.inflationPeriod(d - useLag, frequency()); base.checkRange(dd.Key, extrapolate); double t = timeFromReference(dd.Key); yoyRate = yoyRateImpl(t); } } if (hasSeasonality()) { yoyRate = seasonality().correctYoYRate(d - useLag, yoyRate, this); } return yoyRate; }
//! accrued days at the given date public int accruedDays(Date d) { if (d <= accrualStartDate_ || d > paymentDate_) return 0; else return dayCounter().dayCount(accrualStartDate_, Date.Min(d, accrualEndDate_)); }
public abstract double accruedAmount(Date d);
public YoYInflationCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, YoYInflationIndex yoyIndex, Period observationLag, DayCounter dayCounter) : this(paymentDate, nominal, startDate, endDate, fixingDays, yoyIndex, observationLag, dayCounter, 1.0, 0.0, null, null) { }
protected override double forecastFixing(Date fixingDate) { return underlyingSwap(fixingDate).fairRate(); }
// \warning Relinking the term structure underlying the index will not have effect on the returned swap. // recheck public VanillaSwap underlyingSwap(Date fixingDate) { double fixedRate = 0.0; if (exogenousDiscount_) { return new MakeVanillaSwap(tenor_, iborIndex_, fixedRate) .withEffectiveDate(valueDate(fixingDate)) .withFixedLegCalendar(fixingCalendar()) .withFixedLegDayCount(dayCounter_) .withFixedLegTenor(fixedLegTenor_) .withFixedLegConvention(fixedLegConvention_) .withFixedLegTerminationDateConvention(fixedLegConvention_) .withDiscountingTermStructure(discount_) .value(); } return new MakeVanillaSwap(tenor_, iborIndex_, fixedRate) .withEffectiveDate(valueDate(fixingDate)) .withFixedLegCalendar(fixingCalendar()) .withFixedLegDayCount(dayCounter_) .withFixedLegTenor(fixedLegTenor_) .withFixedLegConvention(fixedLegConvention_) .withFixedLegTerminationDateConvention(fixedLegConvention_) .value(); }
public override Date maturityDate(Date valueDate) { Date fixDate = fixingDate(valueDate); return underlyingSwap(fixDate).maturityDate(); }
public YoYInflationTermStructure(Date referenceDate, Calendar calendar, DayCounter dayCounter, double baseYoYRate, Period lag, Frequency frequency, bool indexIsInterpolated, Handle<YieldTermStructure> yieldTS) : this(referenceDate, calendar, dayCounter, baseYoYRate, lag, frequency, indexIsInterpolated, yieldTS, new Seasonality()) { }
public CappedFlooredIborCoupon(double nominal, Date paymentDate, Date startDate, Date endDate, int fixingDays, IborIndex index, double gearing, double spread, double? cap, double? floor) : this(nominal, paymentDate, startDate, endDate, fixingDays, index, gearing, spread, cap, floor, null, null, null, false) { }
public static Greeks GetOptionOnFutureGreeks(double underlyingPrice,double strike,double riskFreeRate, DateTime expirationDate, DateTime calculationDate, string optionType, string exerciseType, double optionPrice=double.NaN,double impliedVol=0.15,string engineName="baw") { QLNet.Date ExpirationDateObj = new QLNet.Date(expirationDate.Day, expirationDate.Month, expirationDate.Year); QLNet.Date CalculationDateObj = new QLNet.Date(calculationDate.Day, calculationDate.Month, calculationDate.Year); QLNet.DayCounter DayCountObj = new QLNet.Actual365Fixed(); QLNet.Calendar CalendarObj = new QLNet.UnitedStates(); Greeks GreeksOutput = new Greeks(); QLNet.Option.Type OptionTypeObj; QLNet.Exercise ExerciseObj; double ImpliedVol; double OptionPrice; int CalDte = DayCountObj.dayCount(CalculationDateObj, ExpirationDateObj); GreeksOutput.CalDte = CalDte; if (!double.IsNaN(optionPrice)) { if (optionType.ToUpper() == "C") { if (optionPrice + strike - underlyingPrice <= 1.0e-12) { GreeksOutput.Delta = 1; return GreeksOutput; } } else if (optionType.ToUpper() == "P") { if (optionPrice - strike + underlyingPrice <= 1.0e-12) { GreeksOutput.Delta = -1; return GreeksOutput; } } } if (CalDte == 0) { if (optionType.ToUpper() == "C") { if (strike <= underlyingPrice) { GreeksOutput.Delta = 1; } else { GreeksOutput.Delta = 0; } } else if (optionType.ToUpper() == "P") { if (strike >= underlyingPrice) { GreeksOutput.Delta = -1; } else { GreeksOutput.Delta = 0; } } return GreeksOutput; } if (optionType.ToUpper() == "C") { OptionTypeObj = QLNet.Option.Type.Call; } else if (optionType.ToUpper() == "P") { OptionTypeObj = QLNet.Option.Type.Put; } else { return GreeksOutput; } if (exerciseType.ToUpper() == "E") { ExerciseObj = new QLNet.EuropeanExercise(ExpirationDateObj); } else if (exerciseType.ToUpper() == "A") { ExerciseObj = new QLNet.AmericanExercise(CalculationDateObj, ExpirationDateObj); } else { return GreeksOutput; } QLNet.Settings.setEvaluationDate(CalculationDateObj); QLNet.Handle<Quote> UnderlyingObj = new QLNet.Handle<Quote>(new QLNet.SimpleQuote(underlyingPrice)); QLNet.Handle<YieldTermStructure> FlatRateObj = new QLNet.Handle<YieldTermStructure>(new QLNet.FlatForward(CalculationDateObj, riskFreeRate, DayCountObj)); QLNet.Handle<BlackVolTermStructure> FlatVolTsObj = new QLNet.Handle<BlackVolTermStructure>(new QLNet.BlackConstantVol(CalculationDateObj, CalendarObj, impliedVol, DayCountObj)); QLNet.BlackProcess BlackProc = new QLNet.BlackProcess(UnderlyingObj, FlatRateObj, FlatVolTsObj); QLNet.PlainVanillaPayoff PayoffObj = new QLNet.PlainVanillaPayoff(OptionTypeObj, strike); QLNet.VanillaOption OptionObj = new QLNet.VanillaOption(PayoffObj, ExerciseObj); if (engineName == "baw") { OptionObj.setPricingEngine(new QLNet.BaroneAdesiWhaleyApproximationEngine(BlackProc)); } else if (engineName == "fda") { OptionObj.setPricingEngine(new QLNet.FDAmericanEngine(BlackProc, 100, 100)); } else { return GreeksOutput; } if (!double.IsNaN(optionPrice)) { try { ImpliedVol = OptionObj.impliedVolatility(targetValue:optionPrice, process:BlackProc,accuracy:1e-5); } catch { return GreeksOutput; } FlatVolTsObj = new QLNet.Handle<BlackVolTermStructure>(new QLNet.BlackConstantVol(CalculationDateObj, CalendarObj, ImpliedVol, DayCountObj)); BlackProc = new QLNet.BlackProcess(UnderlyingObj, FlatRateObj, FlatVolTsObj); if (engineName == "baw") { OptionObj.setPricingEngine(new QLNet.BaroneAdesiWhaleyApproximationEngine(BlackProc)); } else if (engineName == "fda") { OptionObj.setPricingEngine(new QLNet.FDAmericanEngine(BlackProc, 100, 100)); } OptionPrice = optionPrice; } else { OptionPrice = OptionObj.NPV(); ImpliedVol = impliedVol; } OptionObj = new QLNet.VanillaOption(PayoffObj, new QLNet.EuropeanExercise(ExpirationDateObj)); OptionObj.setPricingEngine(new QLNet.AnalyticEuropeanEngine(BlackProc)); GreeksOutput.Delta = OptionObj.delta(); GreeksOutput.Vega = OptionObj.vega(); GreeksOutput.Theta = OptionObj.thetaPerDay(); GreeksOutput.Gamma = OptionObj.gamma(); GreeksOutput.OptionPrice = OptionPrice; GreeksOutput.ImpliedVol = ImpliedVol; return GreeksOutput; }
public double yoyRate(Date d, Period instObsLag, bool forceLinearInterpolation) { return yoyRate(d, instObsLag, forceLinearInterpolation, false); }
public double yoyRate(Date d, Period instObsLag) { return yoyRate(d, instObsLag, false, false); }
//! year-on-year inflation rate, forceLinearInterpolation //! is relative to the frequency of the TS. //! Since inflation is highly linked to dates (lags, interpolation, months for seasonality etc) //! we do NOT provide a "time" version of the rate lookup. /*! \note this is not the year-on-year swap (YYIIS) rate. */ public double yoyRate(Date d) { return yoyRate(d, new Period(-1, TimeUnit.Days), false, false); }
public YoYInflationTermStructure(Date referenceDate, Calendar calendar, DayCounter dayCounter, double baseYoYRate, Period observationLag, Frequency frequency, bool indexIsInterpolated, Handle<YieldTermStructure> yTS, Seasonality seasonality) : base(referenceDate, baseYoYRate, observationLag, frequency, indexIsInterpolated, yTS, calendar, dayCounter, seasonality) { }
//! accrued period as fraction of year at the given date public double accruedPeriod(Date d) { if (d <= accrualStartDate_ || d > paymentDate_) return 0.0; else return dayCounter().yearFraction(accrualStartDate_, Date.Min(d, accrualEndDate_), refPeriodStart_, refPeriodEnd_); }
public DateTime serialNumberDateTime(int serialNum) { QLNet.Date d = new QLNet.Date(serialNum); return d; }
public CappedFlooredCmsCoupon(double nominal, Date paymentDate, Date startDate, Date endDate, int fixingDays, SwapIndex index) : this(nominal, paymentDate, startDate, endDate, fixingDays, index, 1.0, 0.0, null, null, null, null, null, false) { }
public CappedFlooredIborCoupon(double nominal, Date paymentDate, Date startDate, Date endDate, int fixingDays, IborIndex index) : this(nominal, paymentDate, startDate, endDate, fixingDays, index, 1.0, 0.0, null, null) { }
public Principal(double amount, double nominal, Date paymentDate, Date accrualStartDate, Date accrualEndDate, DayCounter dayCounter) : this(amount, nominal, paymentDate, accrualStartDate, accrualEndDate, dayCounter, null, null) { }
public CappedFlooredIborCoupon(double nominal, Date paymentDate, Date startDate, Date endDate, int fixingDays, IborIndex index, double gearing, double spread, double? cap, double? floor, Date refPeriodStart, Date refPeriodEnd, DayCounter dayCounter, bool isInArrears) : base(new IborCoupon(nominal, paymentDate, startDate, endDate, fixingDays, index, gearing, spread, refPeriodStart, refPeriodEnd, dayCounter, isInArrears), cap, floor) { }
public void testConsistency() { //("Testing dates..."); int minDate = Date.minDate().serialNumber() + 1, maxDate = Date.maxDate().serialNumber(); int dyold = new Date(minDate - 1).DayOfYear, dold = new Date(minDate - 1).Day, mold = new Date(minDate - 1).Month, yold = new Date(minDate - 1).Year, wdold = new Date(minDate - 1).weekday(); for (int i = minDate; i <= maxDate; i++) { Date t = new Date(i); int serial = t.serialNumber(); // check serial number consistency if (serial != i) Assert.Fail("inconsistent serial number:\n" + " original: " + i + "\n" + " date: " + t + "\n" + " serial number: " + serial); int dy = t.DayOfYear, d = t.Day, m = t.Month, y = t.Year, wd = t.weekday(); // check if skipping any date if (!((dy == dyold + 1) || (dy == 1 && dyold == 365 && !Date.IsLeapYear(yold)) || (dy == 1 && dyold == 366 && Date.IsLeapYear(yold)))) Assert.Fail("wrong day of year increment: \n" + " date: " + t + "\n" + " day of year: " + dy + "\n" + " previous: " + dyold); dyold = dy; if (!((d == dold + 1 && m == mold && y == yold) || (d == 1 && m == mold + 1 && y == yold) || (d == 1 && m == 1 && y == yold + 1))) Assert.Fail("wrong day,month,year increment: \n" + " date: " + t + "\n" + " day,month,year: " + d + "," + m + "," + y + "\n" + " previous: " + dold + "," + mold + "," + yold); dold = d; mold = m; yold = y; // check month definition if (m < 1 || m > 12) Assert.Fail("invalid month: \n" + " date: " + t + "\n" + " month: " + m); // check day definition if (d < 1) Assert.Fail("invalid day of month: \n" + " date: " + t + "\n" + " day: " + d); if (!((m == 1 && d <= 31) || (m == 2 && d <= 28) || (m == 2 && d == 29 && Date.IsLeapYear(y)) || (m == 3 && d <= 31) || (m == 4 && d <= 30) || (m == 5 && d <= 31) || (m == 6 && d <= 30) || (m == 7 && d <= 31) || (m == 8 && d <= 31) || (m == 9 && d <= 30) || (m == 10 && d <= 31) || (m == 11 && d <= 30) || (m == 12 && d <= 31))) Assert.Fail("invalid day of month: \n" + " date: " + t + "\n" + " day: " + d); // check weekday definition if (!((wd == wdold + 1) || (wd == 1 && wdold == 7))) Assert.Fail("invalid weekday: \n" + " date: " + t + "\n" + " weekday: " + wd + "\n" + " previous: " + wdold); wdold = wd; // create the same date with a different constructor Date s = new Date(d, m, y); // check serial number consistency serial = s.serialNumber(); if (serial != i) Assert.Fail("inconsistent serial number:\n" + " date: " + t + "\n" + " serial number: " + i + "\n" + " cloned date: " + s + "\n" + " serial number: " + serial); } }