internal static FinanceCalcResult <double> Ppmt(double Rate, double Per, double NPer, double PV, double FV = 0, PmtDue Due = PmtDue.EndOfPeriod) { double Pmt; double dIPMT; // Checking for error conditions if ((Per <= 0.0) || (Per >= (NPer + 1))) { return(new FinanceCalcResult <double>(eErrorType.Num)); } var pmtResult = InternalMethods.PMT_Internal(Rate, NPer, PV, FV, Due); if (pmtResult.HasError) { return(new FinanceCalcResult <double>(pmtResult.ExcelErrorType)); } Pmt = pmtResult.Result; var iPmtResult = IPmtImpl.Ipmt(Rate, Per, NPer, PV, FV, Due); if (iPmtResult.HasError) { return(new FinanceCalcResult <double>(iPmtResult.ExcelErrorType)); } dIPMT = iPmtResult.Result; return(new FinanceCalcResult <double>(Pmt - dIPMT)); }
internal static FinanceCalcResult <double> Ipmt(double Rate, double Per, double NPer, double PV, double FV = 0, PmtDue Due = PmtDue.EndOfPeriod) { double Pmt; double dTFv; double dTemp; if (Due != PmtDue.EndOfPeriod) { dTemp = 2d; } else { dTemp = 1; } // Type = 0 or non-zero only. Offset to calculate FV if ((Per <= 0) || (Per >= NPer + 1)) { return(new FinanceCalcResult <double>(eErrorType.Value)); } if (Due != PmtDue.EndOfPeriod && (Per == 1.0)) { return(new FinanceCalcResult <double>(0d));; } // Calculate PMT (i.e. annuity) for given parms. Rqrd for FV var result = InternalMethods.PMT_Internal(Rate, NPer, PV, FV, Due); if (result.HasError) { return(new FinanceCalcResult <double>(eErrorType.Num)); } Pmt = result.Result; if (Due != PmtDue.EndOfPeriod) { PV = PV + Pmt; } dTFv = InternalMethods.FV_Internal(Rate, (Per - dTemp), Pmt, PV, PmtDue.EndOfPeriod); return(new FinanceCalcResult <double>(dTFv * Rate)); }
public static FinanceCalcResult <double> GetCumipmt(double rate, int nPer, double pv, int startPeriod, int endPeriod, PmtDue type) { if (startPeriod <= 0 || endPeriod < startPeriod || rate <= 0d || endPeriod > nPer || pv <= 0d) { return(new FinanceCalcResult <double>(eErrorType.Num)); } var result = InternalMethods.PMT_Internal(rate, nPer, pv, 0d, type); if (result.HasError) { return(new FinanceCalcResult <double>(result.ExcelErrorType)); } var pmtResult = result.Result; var retVal = 0d; if (startPeriod == 1) { if (type == PmtDue.EndOfPeriod) { retVal = -pv; } startPeriod++; } for (int i = startPeriod; i <= endPeriod; i++) { var res = FvImpl.Fv(rate, (i - 1 - (int)type), pmtResult, pv, type); if (res.HasError) { return(new FinanceCalcResult <double>(res.ExcelErrorType)); } retVal += type == PmtDue.BeginningOfPeriod ? res.Result - pmtResult : res.Result; } retVal *= rate; return(new FinanceCalcResult <double>(retVal)); }
public double GetPmt(double Rate, double NPer, double PV, double FV = 0, PmtDue Due = PmtDue.EndOfPeriod) { return(InternalMethods.PMT_Internal(Rate, NPer, PV, FV, Due).Result); }