I am trying to calculate an IRR with several dimensions in Matlab 2019a. My formula below works in theory (ignoring the "multiple rates of return" warning for now), but the problem is that for bigger matrices, i.e. noScenarios > 5 or so, the code gets very slow.
What are alternatives for this? I tried also fsolve but I think it's not faster, either.
Please note that as I'm no math crack, a simple key word like "Brent's method" does not suffice for me (e.g. as in What is the Most Efficient Way to Calculate the Internal Rate of Return IRR?). I would have to know a) how to implement it in Matlab, and b) if it is pretty idiot proof so that nothing can go wrong? Thank you!
clc clear close all noScenarios = 50; CF = ones(300,noScenarios,noScenarios,noScenarios); CF = [repmat(-300, 1,noScenarios,noScenarios,noScenarios); CF]; for scenarios1 = 1:noScenarios for scenarios2 = 1:noScenarios for scenarios3 = 1:noScenarios IRR3dimensional(scenarios1,scenarios2,scenarios3) = irr(CF(:,scenarios1,scenarios2,scenarios3)); end end end