raymon1 / financial

Financial is a Rust crate that contains collection of finance calculations memicking some of Excel Financial Functions interface.
https://docs.rs/crate/financial
14 stars 5 forks source link

xirr not working cash flow that works in Google Sheets XIRR function #5

Open kevlu93 opened 2 years ago

kevlu93 commented 2 years ago

I'm working on a program that calculates the money-weighted return for a given investment, and for some this series of cash flows doesn't work with the crate.

let cf = [-6.1, -13.0, 6.6];
let dates = [
        chrono::DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2021,4,3).and_hms(0,0,0), Utc),
        chrono::DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2021,4,21).and_hms(0,0,0), Utc),
        chrono::DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2021,10,30).and_hms(0,0,0), Utc),];
println!("{}", financial::xirr(&cf, &dates, None).unwrap());

This will panic. If you provide a guess with a negative return, ie. -0.1, then the calculation will work. However, given that Google Sheet can find the XIRR without being provided a guess, there might be a deeper issue behind the calculation?

raymon1 commented 2 years ago

Thanks for reporting!

Would you like to debug it and open a PR? @kevlu93

kevlu93 commented 2 years ago

Sure when I free up time wise I can take a look at what's going on.