Function xmirr

Source
pub fn xmirr(
    flow_table: &[(Decimal, i32)],
    finance_rate: Decimal,
    reinvest_rate: Decimal,
) -> Decimal
Expand description

XMIRR - Modified Internal Rate of Return for Irregular Cash Flows

The XMIRR function calculates the modified internal rate of return for a schedule of cash flows that is not necessarily periodic.

§Arguments

  • flow_table - A slice of tuples representing the cash flows and dates for each period (cash_flow, date) where date represents the number of days from an arbitrary epoch. The first cash flow is assumed to be the initial investment date at time 0, the order of subsequent cash flows does not matter.
  • finance_rate - The cost of capital (interest rate) for financing
  • reinvest_rate - The reinvestment rate for positive cash flows

Most time libraries will provide a method for the number of days from an epoch. For example, in the chrono library you can use the num_days_from_ce method to get the number of days from the Common Era (CE) epoch, simply convert your date types to an integer representing the number of days from any epoch. Alternatively, you can calculate the time delta in days from an arbitrary epoch, such as the initial investment date.

Cash flows are discounted assuming a 365-day year.

§Returns

  • The modified internal rate of return (MIRR)

§Example

  • Cash flows of $-100, $-20, $20, $20, $20, finance rate of 0.1, reinvestment rate of 0.05
use rust_finprim::rate::xmirr;
use rust_decimal_macros::*;

let flow_table = vec![
  (dec!(-100), 0),
  (dec!(-20), 359),
  (dec!(20), 400),
  (dec!(20), 1000),
  (dec!(20), 2000),
];
let finance_rate = dec!(0.1);
let reinvest_rate = dec!(0.05);
xmirr(&flow_table, finance_rate, reinvest_rate);