The code returns NA while the exact same data returns a valid value in Excel as shown here (MS Excel: How to use the XIRR Function (WS)) . Any guidance would be appreciated
If I wanted to implement a moving window, so for the first step, the entire CF vector is provided as input and for the second iteration , values starting from i = 2 and so on , how would I modify the code I have?
I don't think that's possible. Because you need to have a sign change in the cash flow values and there isn't a sign change after you've dropped the first value.
For example,
library(tvm)
# Provide input data
CF <- c(-7500, 3000, 5000, 1200, 4000)
d <- as.Date(c("2016-01-01", "2016-02-01", "2016-04-15", "2016-08-01", "2017-03-26"))
xirr(CF[2:5], d[2:5])
#> Error in uniroot(xnpv, interval = interval, cf = cf, d = d, extendInt = "yes", : no sign change found in 1000 iterations
@mhenderson,
Can you help me correct the following in such a way that the function returns "NA" when there is an error , else returns a value ? Based on your input , I understand that the function needs to be re-written and I tried it below. Currently it returns just "NA"
In the above code, by changing the inputs , I am ensuring that the code should return a value starting at i = 4 , because at i = 4, I would expect to see a value since there is a sign change I expect to have a value. Similarly at i =5.