Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joutvhu/xirr
To calculate the internal rate of return for a schedule of cash flows that is not necessarily periodic.
https://github.com/joutvhu/xirr
excel xirr xirr-calculation
Last synced: 16 days ago
JSON representation
To calculate the internal rate of return for a schedule of cash flows that is not necessarily periodic.
- Host: GitHub
- URL: https://github.com/joutvhu/xirr
- Owner: joutvhu
- License: mit
- Created: 2023-03-31T10:03:48.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-19T10:38:51.000Z (about 1 year ago)
- Last Synced: 2024-11-08T21:38:18.963Z (2 months ago)
- Topics: excel, xirr, xirr-calculation
- Language: Java
- Homepage:
- Size: 101 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Xirr
To calculate the internal rate of return for a schedule of cash flows that is not necessarily periodic.
## Installation
- If you are using Gradle just add the following dependency to your `build.gradle`.
```groovy
implementation "com.github.joutvhu:xirr:1.0.5"
```- Or add the following dependency to your `pom.xml` if you are using Maven.
```xml
com.github.joutvhu
xirr
1.0.5```
## Using
To use the xirr function you need to create a Xirr object.
You can use the `Xirr.instance()` method to create a Xirr object.
Xirr cycles through the calculation until the result is accurate within 0.000001 percent.
If Xirr can't find a result that works after 100 tries, you'll get a `XirrException`.You can also change the accuracy and tries using the `Xirr.of(double accurate, double tries)` method.
```java
// Xirr.instance() -> precision = 0.000001, tries = 100;
Xirr xirr = Xirr.instance();// Xirr.of(double precision, double tries);
Xirr xirr1 = Xirr.of(0.000001, 1000);
```The Syntax of the `xirr` function:
- `Xirr.xirr(Transaction[] transactions)`
- `Xirr.xirr(Transaction[] transactions, double guess)`
- `Xirr.xirr(double[] values, long[] days)`
- `Xirr.xirr(double[] values, long[] days, double guess)`
The arguments of the `xirr` function:
- `values` __required__. A series of cash flows that corresponds to a schedule of payments in dates. The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. The series of values must contain at least one positive and one negative value.
- `days` __required__. A schedule of payment dates that corresponds to the cash flow payments. Dates may occur in any order.
- `transactions` __required__. A series of pairs of `value` and `day`.
- `guess` __optional__. A number that you guess is close to the result of Xirr. If omitted, guess is assumed to be 0.1 (10 percent).```java
// rate ~ 0.35899244 ~ 35.90%
double rate = Xirr.instance().xirr(
new Transaction(-10000,"2008-01-01"),
new Transaction(2750,"2008-03-01"),
new Transaction(4250,"2008-11-30"),
new Transaction(3250,"2009-02-15"),
new Transaction(2750,"2009-04-01")
);
```