Package com.cedarsoft.business

Examples of com.cedarsoft.business.MutableMoney


    //Create a runner that represents the begin of the actual month
    //For the first month this may be another day of month than 1
    LocalDate actualMonthBegin = begin;

    //Now iterate over all months
    MutableMoney rentSummer = new MutableMoney();
    while ( actualMonthBegin.isBefore( end ) ) {
      LocalDate actualMonthEnd = actualMonthBegin.plusMonths( 1 );
      //Check if this month is complete --> else only add the rest
      if ( actualMonthEnd.isAfter( end ) ) {
        actualMonthEnd = end;
      }

      double monthYears = getTimeSystem().calculateYears( actualMonthBegin, actualMonthEnd );
      double monthDays = getTimeSystem().calculateDays( actualMonthBegin, actualMonthEnd );
      double monthRate = getInterestRateProvider().getRate( actualMonthBegin );

      //add the rent for the rent
      Money baseForMonth = rentSummer.immutable();

      Money compoundInterest;
      if ( getBackingCalculationSystem().isCompoundSystem() && baseForMonth.getValue() != 0 ) {
        compoundInterest = getBackingCalculationSystem().calculateInterest( baseForMonth, monthYears, monthDays, monthRate );
        rentSummer.plus( compoundInterest );
      } else {
        compoundInterest = Money.ZERO;
      }

      //add the rent for the amount
      Money interest = getBackingCalculationSystem().calculateInterest( amount, monthYears, monthDays, monthRate );
      rentSummer.plus( interest );

      //Build the information object (if expected)
      interestDetails.add( new InterestDetails( actualMonthBegin, actualMonthEnd, monthRate, baseForMonth, interest.plus( compoundInterest ), monthDays ) );

      //Next month --> now we really need the first day of the month
View Full Code Here


   *
   * @return the amount of payments
   */
  @NotNull
  public Money getPaymentsAmount() {
    MutableMoney amount = new MutableMoney();
    for ( Payment payment : payments ) {
      amount.plus( payment.getAmount() );
    }
    return amount.getMoney();
  }
View Full Code Here

  public PangV calculate() {
    if ( payments.size() < 2 ) {
      return PangV.NULL;
    }

    MutableMoney sum = new MutableMoney();
    for ( Payment payment : payments ) {
      sum.plus( payment.getAmount() );
    }

    boolean sumPositive = sum.getEstimatedValue() > 0;

    //test it using bisection

    double actualGuess;
    if ( sumPositive ) {
      actualGuess = -INITIAL_RATE_GUESS;
    } else {
      actualGuess = INITIAL_RATE_GUESS;
    }

    int counter = 0;

    Money actualValue = Money.BIG;
    while ( actualValue.abs().isGreaterThan( TARGET_DELTA ) ) {
      double change = INITIAL_RATE_GUESS / Math.pow( 2, counter );

      if ( change < MIN_CHANGE ) {
        return new PangV( actualGuess, actualValue, counter, sum.immutable() );
      }

      //modify guess
      if ( !sumPositive ^ actualValue.isGreaterThan( Money.ZERO ) ) {
        actualGuess += change;
      } else {
        actualGuess -= change;
      }

      actualValue = calculateCashValue( actualGuess );
      counter++;
    }

    return new PangV( actualGuess, actualValue, counter, sum.immutable() );
  }
View Full Code Here

   * @param rate the rate
   * @return the cash value for all payments
   */
  @NotNull
  public Money calculateCashValue( double rate ) {
    MutableMoney cashValue = new MutableMoney();
    for ( Payment payment : payments ) {
      cashValue.plus( calulateCashValue( baseDate, payment, rate ) );
    }
    return cashValue.immutable();
  }
View Full Code Here

    this.until = until;
    this.valueDate = valueDate;
    this.interestDetails = new ArrayList<InterestDetails>( interestDetails );

    //Sum up
    MutableMoney interestSummer = new MutableMoney();
    for ( InterestDetails interestDetail : interestDetails ) {
      interestSummer.plus( interestDetail.getInterest() );
    }
    this.interest = interestSummer.immutable();
  }
View Full Code Here

    }
    if ( interestRate == 0 ) {
      throw new IllegalStateException( "Interest rate not set" );
    }

    MutableMoney sum = new MutableMoney();

    for ( Payment payment : payments ) {
      double years = timeSystem.calculateYears( payment.getDate(), until );
      double days = timeSystem.calculateDays( payment.getDate(), until );
      sum.plus( calculationSystem.calculateInterest( payment.getAmount(), years, days, interestRate ) );
    }

    return sum.immutable();
  }
View Full Code Here

    }
    if ( interestRate == 0 ) {
      throw new IllegalStateException( "Interest rate not set" );
    }

    MutableMoney sum = new MutableMoney();

    for ( Payment payment : payments ) {
      double years = timeSystem.calculateYears( payment.getDate(), until );
      double days = timeSystem.calculateDays( payment.getDate(), until );
      sum.plus( calculationSystem.calculateInterest( payment.getAmount(), years, days, interestRate ) );
    }

    return sum.immutable();
  }
View Full Code Here

   *
   * @return the amount of payments
   */
  @NotNull
  public Money getPaymentsAmount() {
    MutableMoney amount = new MutableMoney();
    for ( Payment payment : payments ) {
      amount.plus( payment.getAmount() );
    }
    return amount.getMoney();
  }
View Full Code Here

  public PangV calculate() {
    if ( payments.size() < 2 ) {
      return PangV.NULL;
    }

    MutableMoney sum = new MutableMoney();
    for ( Payment payment : payments ) {
      sum.plus( payment.getAmount() );
    }

    boolean sumPositive = sum.getEstimatedValue() > 0;

    //test it using bisection

    double actualGuess;
    if ( sumPositive ) {
      actualGuess = -INITIAL_RATE_GUESS;
    } else {
      actualGuess = INITIAL_RATE_GUESS;
    }

    int counter = 0;

    Money actualValue = Money.BIG;
    while ( actualValue.abs().isGreaterThan( TARGET_DELTA ) ) {
      double change = INITIAL_RATE_GUESS / Math.pow( 2, counter );

      if ( change < MIN_CHANGE ) {
        return new PangV( actualGuess, actualValue, counter, sum.immutable() );
      }

      //modify guess
      if ( !sumPositive ^ actualValue.isGreaterThan( Money.ZERO ) ) {
        actualGuess += change;
      } else {
        actualGuess -= change;
      }

      actualValue = calculateCashValue( actualGuess );
      counter++;
    }

    return new PangV( actualGuess, actualValue, counter, sum.immutable() );
  }
View Full Code Here

   * @param rate the rate
   * @return the cash value for all payments
   */
  @NotNull
  public Money calculateCashValue( double rate ) {
    MutableMoney cashValue = new MutableMoney();
    for ( Payment payment : payments ) {
      cashValue.plus( calulateCashValue( baseDate, payment, rate ) );
    }
    return cashValue.immutable();
  }
View Full Code Here

TOP

Related Classes of com.cedarsoft.business.MutableMoney

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.