类 Xirr
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.
-
嵌套类概要
嵌套类 -
构造器概要
构造器构造器说明Xirr(Transaction... tx)Construct an Xirr instance for the given transactions.Xirr(Collection<Transaction> txs)Construct an Xirr instance for the given transactions. -
方法概要
修饰符和类型方法说明static Xirr.Builderbuilder()Convenience method for getting an instance of aXirr.Builder.doublederivative(double rate)The derivative of the present value under the given rate.doublepresentValue(double rate)Calculates the present value of the investment if it had been subject to the given rate of return.doublexirr()Calculates the irregular rate of return of the transactions for this instance of Xirr.
-
构造器详细资料
-
Xirr
Construct an Xirr instance for the given transactions.- 参数:
tx- the transactions- 抛出:
IllegalArgumentException- if there are fewer than 2 transactionsIllegalArgumentException- if all the transactions are on the same dateIllegalArgumentException- if all the transactions negative (deposits)IllegalArgumentException- if all the transactions non-negative (withdrawals)
-
Xirr
Construct an Xirr instance for the given transactions.- 参数:
txs- the transactions- 抛出:
IllegalArgumentException- if there are fewer than 2 transactionsIllegalArgumentException- if all the transactions are on the same dateIllegalArgumentException- if all the transactions negative (deposits)IllegalArgumentException- if all the transactions non-negative (withdrawals)
-
-
方法详细资料
-
builder
Convenience method for getting an instance of aXirr.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 methodNonconvergenceException- if the Newton-Raphson method fails to converge in the
-