Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 protected bool Equals(FinancingId other)
 {
     return(string.Equals(id, other.id) && Equals(currency, other.currency));
 }
Esempio n. 6
0
 public PaymentInfo(Currency currency, DateTime date)
     : this(currency, date, FinancingId.RiskFree(currency))
 {
 }
Esempio n. 7
0
 public PaymentInfo(Currency currency, DateTime date, FinancingId financing)
 {
     Financing = financing;
     Date      = date;
     Currency  = currency;
 }
Esempio n. 8
0
 public DiscountCurve RiskFreeDiscountCurve(Currency currency)
 {
     return(DiscountCurve(FinancingId.RiskFree(currency)));
 }
Esempio n. 9
0
 public DiscountCurve AssetFinancingCurve(DiscountCurve cashFinancingCurve)
 {
     return(DiscountCurve.Product(RepoCurve, cashFinancingCurve, FinancingId.AssetCollat(Asset)));
 }
Esempio n. 10
0
 public DiscountCurveFromRate(FinancingId financing, ITimeMeasure time, RrFunction zcRate)
     : base(time.RefDate, financing)
 {
     this.time = time;
     this.zcRate = zcRate;
 }
Esempio n. 11
0
 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);
 }
Esempio n. 12
0
 public static DiscountCurve Product(DiscountCurve discount1, DiscountCurve discount2, FinancingId financing)
 {
     return new ProductDiscount(discount1, discount2, financing);
 }
Esempio n. 13
0
 protected DiscountCurve(DateTime refDate, FinancingId financing)
 {
     this.refDate = refDate;
     Financing = financing;
 }