public static BigDecimal minus(final Number minuend, final BigDecimal subtrahend) { return minus(toBigDecimal(minuend), subtrahend); }
public static BigDecimal minus(final Number minuend, final Number subtrahend) { return minus(toBigDecimal(minuend), subtrahend); }
public static BigDecimal minus(final Number minuend, final BigDecimal subtrahend) { return minus(toBigDecimal(minuend), subtrahend); }
public static BigDecimal minus(final BigDecimal minuend, final Number subtrahend) { return minus(minuend, toBigDecimal(subtrahend)); }
public static BigDecimal minus(final Number minuend, final Number subtrahend) { return minus(toBigDecimal(minuend), subtrahend); }
public static BigDecimal minus(final BigDecimal minuend, final Number subtrahend) { return minus(minuend, toBigDecimal(subtrahend)); }
public static BigDecimal expectedInterestRateAfterFees(final Investment investment, final long totalInvested) { final BigDecimal interestRate = investment.getInterestRate(); final BigDecimal feeRate = estimateFeeRate(investment, totalInvested); return minus(interestRate, feeRate); } }
public static BigDecimal expectedInterestRateAfterFees(final Investment investment, final long totalInvested) { final BigDecimal interestRate = investment.getInterestRate(); final BigDecimal feeRate = estimateFeeRate(investment, totalInvested); return minus(interestRate, feeRate); } }
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)); }
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 PPMT(interest_rate, period, number_payments, PV, FV, 0) function, which calculates the * portion of the payment at a given period that will apply to principal. * @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 principal portion of payment. * @see #pmt(BigDecimal, int, BigDecimal, BigDecimal) * @see #ipmt(BigDecimal, int, int, BigDecimal, BigDecimal) */ public static BigDecimal ppmt(final BigDecimal r, final int per, final int nper, final BigDecimal pv, final BigDecimal fv) { // Calculated payment per period minus interest portion of that period. // i.e., ppmt = c - i // where c = pmt(r, nper, pv, fv, type) // and i = ipmt(r, per, nper, pv, fv, type) return minus( pmt(r, nper, pv, fv), ipmt(r, per, nper, pv, fv) ); }
public static BigDecimal expectedInterestAfterFees(final Investment investment, final long totalInvested) { final int terms = investment.getRemainingMonths(); final BigDecimal expectedFee = feePaid(investment, totalInvested, terms); final BigDecimal expectedIncome = expectedInterest(investment); return minus(expectedIncome, expectedFee); }
public static BigDecimal expectedInterestAfterFees(final Investment investment, final long totalInvested) { final int terms = investment.getRemainingMonths(); final BigDecimal expectedFee = feePaid(investment, totalInvested, terms); final BigDecimal expectedIncome = expectedInterest(investment); return minus(expectedIncome, expectedFee); }
@Test void subtraction() { final BigDecimal result = BigDecimalCalculator.minus(0.0, 1); assertThat(result).isEqualTo(BigDecimal.ONE.negate()); }
@Test void subtractionWithBigDecimalAsSecondArg() { final BigDecimal result = BigDecimalCalculator.minus(0.0, BigDecimal.ONE); assertThat(result).isEqualTo(BigDecimal.ONE.negate()); }
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(); }