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 GetFv(double Rate, double NPer, double Pmt, double PV = 0, PmtDue Due = PmtDue.EndOfPeriod) { return(InternalMethods.FV_Internal(Rate, NPer, Pmt, PV, Due)); }
internal static FinanceCalcResult <double> Fv(double Rate, double NPer, double Pmt, double PV = 0, PmtDue Due = PmtDue.EndOfPeriod) { return(new FinanceCalcResult <double>(InternalMethods.FV_Internal(Rate, NPer, Pmt, PV, Due))); }
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); }