类 Xirr

java.lang.Object
cn.nkpro.elcube.utils.xirr.Xirr

public class Xirr extends Object
Calculates the irregular rate of return on a series of transactions. The irregular rate of return is the constant rate for which, if the transactions had been applied to an investment with that rate, the same resulting returns would be realized.

When creating the list of Transaction instances to feed Xirr, be sure to include one transaction representing the present value of the account now, as if you had cashed out the investment.

Example usage: double rate = new Xirr( new Transaction(-1000, "2016-01-15"), new Transaction(-2500, "2016-02-08"), new Transaction(-1000, "2016-04-17"), new Transaction( 5050, "2016-08-24") ).xirr();

Example using the builder to gain more control: double rate = Xirr.builder() .withNewtonRaphsonBuilder( NewtonRaphson.builder() .withIterations(1000) .withTolerance(0.0001)) .withGuess(.20) .withTransactions( new Transaction(-1000, "2016-01-15"), new Transaction(-2500, "2016-02-08"), new Transaction(-1000, "2016-04-17"), new Transaction( 5050, "2016-08-24") ).xirr();

This class is not thread-safe and is designed for each instance to be used once.

  • 嵌套类概要

    嵌套类
    修饰符和类型
    说明
    static class 
    Builder for Xirr instances.
  • 构造器概要

    构造器
    构造器
    说明
    Xirr​(Transaction... tx)
    Construct an Xirr instance for the given transactions.
    Construct an Xirr instance for the given transactions.
  • 方法概要

    修饰符和类型
    方法
    说明
    Convenience method for getting an instance of a Xirr.Builder.
    double
    derivative​(double rate)
    The derivative of the present value under the given rate.
    double
    presentValue​(double rate)
    Calculates the present value of the investment if it had been subject to the given rate of return.
    double
    Calculates the irregular rate of return of the transactions for this instance of Xirr.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

  • 方法详细资料

    • builder

      public static Xirr.Builder builder()
      Convenience method for getting an instance of a Xirr.Builder.
      返回:
      new Builder
    • presentValue

      public double presentValue(double rate)
      Calculates the present value of the investment if it had been subject to the given rate of return.
      参数:
      rate - the rate of return
      返回:
      the present value of the investment if it had been subject to the given rate of return
    • derivative

      public double derivative(double rate)
      The derivative of the present value under the given rate.
      参数:
      rate - the rate of return
      返回:
      derivative of the present value under the given rate
    • xirr

      public double xirr()
      Calculates the irregular rate of return of the transactions for this instance of Xirr.
      返回:
      the irregular rate of return of the transactions
      抛出:
      ZeroValuedDerivativeException - if the derivative is 0 while executing the Newton-Raphson method
      NonconvergenceException - if the Newton-Raphson method fails to converge in the