public static DiscountCurve LinearRateInterpol(FinancingId financing, DateTime[] pillars, double[] zcs, ITimeMeasure time) { if (pillars.Length != zcs.Length) throw new Exception("LinearRateDiscountProvider : Incompatible size"); var dates = time[pillars]; var zcRates = new double[pillars.Length]; if (DoubleUtils.EqualZero(dates[0])) { if (!DoubleUtils.MachineEquality(1.0, zcs[0])) throw new Exception("LinearRateInterpol : Discount for refDate must equal to 1.0 "); zcRates[0] = 0.0; } else { zcRates[0] = -Math.Log(zcs[0]) / dates[0]; } for (int i = 1; i < zcs.Length; i++) { zcRates[i] = -Math.Log(zcs[i]) / dates[i]; } return new DiscountCurveFromRate(financing, time, RrFunctions.LinearInterpolation(dates, zcRates)); }
public static bool TryParse(string curveId, out FinancingId result) { result = null; var splitted = curveId.Split('.'); if (splitted.Length != 2) { throw new Exception(string.Format("Not a valid FinancingCurveId : {0}", curveId)); } Currency currency; if (!Currency.TryParse(splitted[0], out currency)) { return(false); } switch (splitted[1].Trim().ToLowerInvariant()) { case "riskfree": result = RiskFree(currency); return(true); } return(false); }
public ProductDiscount(DiscountCurve discount1, DiscountCurve discount2, FinancingId financing) : base(discount1.RefDate, financing) { if (discount1.RefDate != discount2.RefDate) throw new Exception("ProductDiscount : incompatible ref date !"); this.discount1 = discount1; this.discount2 = discount2; }
public DiscountCurve DiscountCurve(FinancingId financingId) { DiscountCurve curve; if (!discountCurves.TryGetValue(financingId, out curve)) { throw new Exception(string.Format("Missing discount curve : {0}", financingId)); } return(curve); }
protected bool Equals(FinancingId other) { return(string.Equals(id, other.id) && Equals(currency, other.currency)); }
public PaymentInfo(Currency currency, DateTime date) : this(currency, date, FinancingId.RiskFree(currency)) { }
public PaymentInfo(Currency currency, DateTime date, FinancingId financing) { Financing = financing; Date = date; Currency = currency; }
public DiscountCurve RiskFreeDiscountCurve(Currency currency) { return(DiscountCurve(FinancingId.RiskFree(currency))); }
public DiscountCurve AssetFinancingCurve(DiscountCurve cashFinancingCurve) { return(DiscountCurve.Product(RepoCurve, cashFinancingCurve, FinancingId.AssetCollat(Asset))); }
public DiscountCurveFromRate(FinancingId financing, ITimeMeasure time, RrFunction zcRate) : base(time.RefDate, financing) { this.time = time; this.zcRate = zcRate; }
public static DiscountCurve Flat(FinancingId financing, DateTime refDate, double zcRate) { var time = TimeMeasure.Act365(refDate); var zc1Y = Math.Exp(-zcRate * time[refDate + Duration.Year]); return LinearRateInterpol(financing, new[] { refDate + Duration.Year }, new[] { zc1Y }, time); }
public static DiscountCurve Product(DiscountCurve discount1, DiscountCurve discount2, FinancingId financing) { return new ProductDiscount(discount1, discount2, financing); }
protected DiscountCurve(DateTime refDate, FinancingId financing) { this.refDate = refDate; Financing = financing; }