Example #1
0
        public static double PV(this CashFlowSchedule schedule, Currency reportingCCy, IFundingModel model, string forecastCurve, DayCountBasis basisFloat, DateTime?filterDate)
        {
            var totalPv = 0.0;

            for (var i = 0; i < schedule.Flows.Count; i++)
            {
                var flow = schedule.Flows[i];

                if (filterDate.HasValue && flow.SettleDate < filterDate.Value)
                {
                    continue;
                }

                double fv, pv;
                var    df        = model.GetDf(reportingCCy, model.BuildDate, flow.SettleDate);
                var    fwdFxRate = model.GetFxRate(flow.SettleDate, flow.Currency, reportingCCy);

                switch (flow.FlowType)
                {
                case FlowType.FixedRate:
                {
                    var rateLin = flow.FixedRateOrMargin;
                    var yf      = flow.YearFraction;
                    fv       = rateLin * yf * flow.Notional;
                    fv      *= fwdFxRate;
                    pv       = fv * df;
                    totalPv += pv;
                    break;
                }

                case FlowType.FloatRate:
                {
                    var s       = flow.AccrualPeriodStart;
                    var e       = flow.AccrualPeriodEnd;
                    var rateLin = model.GetCurve(forecastCurve).GetForwardRate(s, e, RateType.Linear, basisFloat);
                    rateLin += flow.FixedRateOrMargin;
                    var yf = flow.YearFraction;
                    fv       = rateLin * yf * flow.Notional;
                    fv      *= fwdFxRate;
                    pv       = fv * df;
                    totalPv += pv;
                    break;
                }

                case FlowType.FixedAmount:
                {
                    fv       = flow.Notional;
                    fv      *= fwdFxRate;
                    pv       = fv * df;
                    totalPv += pv;
                    break;
                }
                }
            }

            return(totalPv);
        }
Example #2
0
 public double Pv(IFundingModel model, bool updateState) => PayDate == DateTime.MinValue || PayDate <= model.BuildDate ? Notional : model.GetDf(Currency, model.BuildDate, PayDate) * Notional;