public static BigDecimal plus(final Number addend1, final Number addend2) { return plus(toBigDecimal(addend1), addend2); }
public static BigDecimal plus(final BigDecimal addend1, final Number addend2) { return plus(addend1, toBigDecimal(addend2)); }
public static BigDecimal plus(final Number addend1, final BigDecimal addend2) { return plus(toBigDecimal(addend1), addend2); }
public static BigDecimal plus(final Number addend1, final Number addend2) { return plus(toBigDecimal(addend1), addend2); }
public static BigDecimal plus(final Number addend1, final BigDecimal addend2) { return plus(toBigDecimal(addend1), addend2); }
public static BigDecimal plus(final BigDecimal addend1, final Number addend2) { return plus(addend1, toBigDecimal(addend2)); }
private static BigDecimal sum(final OverallPortfolio portfolio) { return BigDecimalCalculator.plus(portfolio.getDue(), portfolio.getUnpaid()); }
private static BigDecimal sum(final OverallPortfolio portfolio) { return BigDecimalCalculator.plus(portfolio.getDue(), portfolio.getUnpaid()); }
public static BigDecimal actualInterestAfterFees(final Investment investment, final long totalInvested, final boolean includeSmpSaleFee) { final int termsInZonky = countTermsInZonky(investment); final BigDecimal fee = feePaid(investment, totalInvested, termsInZonky); final BigDecimal actualFee = includeSmpSaleFee ? plus(fee, investment.getSmpFee().orElse(BigDecimal.ZERO)) : fee; final BigDecimal interest = plus(investment.getPaidInterest(), investment.getPaidPenalty()); return minus(interest, actualFee); }
public static BigDecimal actualInterestAfterFees(final Investment investment, final long totalInvested, final boolean includeSmpSaleFee) { final int termsInZonky = countTermsInZonky(investment); final BigDecimal fee = feePaid(investment, totalInvested, termsInZonky); final BigDecimal actualFee = includeSmpSaleFee ? plus(fee, investment.getSmpFee().orElse(BigDecimal.ZERO)) : fee; final BigDecimal interest = plus(investment.getPaidInterest(), investment.getPaidPenalty()); return minus(interest, actualFee); }
/** * 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 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(); }
/** * 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(); }
@Test void addition() { final BigDecimal result = BigDecimalCalculator.plus(0, 1.0); assertThat(result).isEqualTo(BigDecimal.ONE); }
@Test void additionWithBigDecimalAsSecondArg() { final BigDecimal result = BigDecimalCalculator.plus(0, BigDecimal.ONE); assertThat(result).isEqualTo(BigDecimal.ONE); }