public static BigDecimal times(final Number multiplicand, final BigDecimal multiplier) { return times(toBigDecimal(multiplicand), multiplier); }
public static BigDecimal times(final BigDecimal multiplicand, final Number multiplier) { return times(multiplicand, toBigDecimal(multiplier)); }
public static BigDecimal times(final BigDecimal multiplicand, final Number multiplier) { return times(multiplicand, toBigDecimal(multiplier)); }
public static BigDecimal times(final Number multiplicand, final Number multiplier) { return times(toBigDecimal(multiplicand), multiplier); }
public static BigDecimal times(final Number multiplicand, final Number multiplier) { return times(toBigDecimal(multiplicand), multiplier); }
public static BigDecimal times(final Number multiplicand, final BigDecimal multiplier) { return times(toBigDecimal(multiplicand), multiplier); }
static BigDecimal feePaid(final BigDecimal originalValue, final BigDecimal interestRate, final int originalTerm, final BigDecimal annualFee, final int totalMonths) { final BigDecimal monthlyRate = divide(interestRate, 12); final BigDecimal monthlyFee = divide(annualFee, 12); final BigDecimal pmt = FinancialUtil.pmt(monthlyRate, originalTerm, originalValue); final BigDecimal result = IntStream.range(0, totalMonths) .mapToObj(term -> FinancialUtil.fv(monthlyRate, term + 1, pmt, originalValue).negate()) .map(fv -> times(fv, monthlyFee)) .reduce(BigDecimal.ZERO, BigDecimalCalculator::plus); LOGGER.debug("Fee paid from {} CZK at {} rate for {} months with {} annual fee over {} months is {} CZK.", originalValue, interestRate, originalTerm, annualFee, totalMonths, result.doubleValue()); return toScale(result); }
static BigDecimal feePaid(final BigDecimal originalValue, final BigDecimal interestRate, final int originalTerm, final BigDecimal annualFee, final int totalMonths) { final BigDecimal monthlyRate = divide(interestRate, 12); final BigDecimal monthlyFee = divide(annualFee, 12); final BigDecimal pmt = FinancialUtil.pmt(monthlyRate, originalTerm, originalValue); final BigDecimal result = IntStream.range(0, totalMonths) .mapToObj(term -> FinancialUtil.fv(monthlyRate, term + 1, pmt, originalValue).negate()) .map(fv -> times(fv, monthlyFee)) .reduce(BigDecimal.ZERO, BigDecimalCalculator::plus); LOGGER.debug("Fee paid from {} CZK at {} rate for {} months with {} annual fee over {} months is {} CZK.", originalValue, interestRate, originalTerm, annualFee, totalMonths, result.doubleValue()); return toScale(result); }
/** * Emulates Excel/Calc's IPMT(interest_rate, period, number_payments, PV, FV, 0) function, which calculates the * portion of the payment at a given period that is the interest on previous balance. * @param r - periodic interest rate represented as a decimal. * @param per - period (payment number) to check value at. * @param nper - number of total payments / periods. * @param pv - present value -- borrowed or invested principal. * @param fv - future value of loan or annuity. * @return Representing interest portion of payment. * @see #pmt(BigDecimal, int, BigDecimal, BigDecimal) * @see #fv(BigDecimal, int, BigDecimal, BigDecimal) */ public static BigDecimal ipmt(final BigDecimal r, final int per, final int nper, final BigDecimal pv, final BigDecimal fv) { // Prior period (i.e., per-1) balance times periodic interest rate. // i.e., ipmt = fv(r, per-1, c, pv, type) * r // where c = pmt(r, nper, pv, fv, type) return times(fv(r, per - 1, pmt(r, nper, pv, fv), pv), r); }
/** * Emulates Excel/Calc's IPMT(interest_rate, period, number_payments, PV, FV, 0) function, which calculates the * portion of the payment at a given period that is the interest on previous balance. * @param r - periodic interest rate represented as a decimal. * @param per - period (payment number) to check value at. * @param nper - number of total payments / periods. * @param pv - present value -- borrowed or invested principal. * @param fv - future value of loan or annuity. * @return Representing interest portion of payment. * @see #pmt(BigDecimal, int, BigDecimal, BigDecimal) * @see #fv(BigDecimal, int, BigDecimal, BigDecimal) */ public static BigDecimal ipmt(final BigDecimal r, final int per, final int nper, final BigDecimal pv, final BigDecimal fv) { // Prior period (i.e., per-1) balance times periodic interest rate. // i.e., ipmt = fv(r, per-1, c, pv, type) * r // where c = pmt(r, nper, pv, fv, type) return times(fv(r, per - 1, pmt(r, nper, pv, fv), pv), r); }
public static BigDecimal estimateFeeRate(final Investment investment, final long totalInvested) { final BigDecimal baseFee = baseFee(investment); final BigDecimal feeDiscount = feeDiscount(totalInvested); return minus(baseFee, times(baseFee, feeDiscount)); }
/** * Emulates Excel/Calc's PMT(interest_rate, number_payments, PV, FV, 0) function, which calculates the mortgage or * annuity payment / yield per period. * @param r - periodic interest rate represented as a decimal. * @param nper - number of total payments / periods. * @param pv - present value -- borrowed or invested principal. * @param fv - future value of loan or annuity. * @return Representing periodic payment amount. */ public static BigDecimal pmt(final BigDecimal r, final int nper, final BigDecimal pv, final BigDecimal fv) { // pmt = r / ((1 + r)^N - 1) * -(pv * (1 + r)^N + fv) final BigDecimal tmp = plus(1, r).pow(nper); return times( divide(r, minus(tmp, 1)), plus(times(pv, tmp), fv).negate() ); }
/** * Emulates Excel/Calc's FV(interest_rate, number_payments, payment, PV, 0) function, which calculates future value * or principal at period N. * @param r - periodic interest rate represented as a decimal. * @param nper - number of total payments / periods. * @param c - periodic payment amount. * @param pv - present value -- borrowed or invested principal. * @return Representing future principal value. */ public static BigDecimal fv(final BigDecimal r, final int nper, final BigDecimal c, final BigDecimal pv) { // account for payments at beginning of period versus end. // since we are going in reverse, we multiply by 1 plus interest rate. final BigDecimal tmp = plus(1, r).pow(nper); return plus( times( divide( minus(tmp, 1), r), c), times(pv, tmp) ).negate(); }
public static BigDecimal estimateFeeRate(final Investment investment, final long totalInvested) { final BigDecimal baseFee = baseFee(investment); final BigDecimal feeDiscount = feeDiscount(totalInvested); return minus(baseFee, times(baseFee, feeDiscount)); }
/** * Emulates Excel/Calc's FV(interest_rate, number_payments, payment, PV, 0) function, which calculates future value * or principal at period N. * @param r - periodic interest rate represented as a decimal. * @param nper - number of total payments / periods. * @param c - periodic payment amount. * @param pv - present value -- borrowed or invested principal. * @return Representing future principal value. */ public static BigDecimal fv(final BigDecimal r, final int nper, final BigDecimal c, final BigDecimal pv) { // account for payments at beginning of period versus end. // since we are going in reverse, we multiply by 1 plus interest rate. final BigDecimal tmp = plus(1, r).pow(nper); return plus( times( divide( minus(tmp, 1), r), c), times(pv, tmp) ).negate(); }
/** * Emulates Excel/Calc's PMT(interest_rate, number_payments, PV, FV, 0) function, which calculates the mortgage or * annuity payment / yield per period. * @param r - periodic interest rate represented as a decimal. * @param nper - number of total payments / periods. * @param pv - present value -- borrowed or invested principal. * @param fv - future value of loan or annuity. * @return Representing periodic payment amount. */ public static BigDecimal pmt(final BigDecimal r, final int nper, final BigDecimal pv, final BigDecimal fv) { // pmt = r / ((1 + r)^N - 1) * -(pv * (1 + r)^N + fv) final BigDecimal tmp = plus(1, r).pow(nper); return times( divide(r, minus(tmp, 1)), plus(times(pv, tmp), fv).negate() ); }
@Test void multiplicationWithBigDecimalAsSecondArg() { final BigDecimal result = BigDecimalCalculator.times(2, BigDecimal.valueOf(3)); assertThat(result).isEqualTo(new BigDecimal("6")); }
@Test void multiplication() { final BigDecimal result = BigDecimalCalculator.times(2, 3); assertThat(result).isEqualTo(new BigDecimal("6")); }