I think Mark Baker is right, try this:
function modDietz(DateTime $startDate, DateTime $endDate, $BMV, $EMV, $MIMO){
$CD = $startDate->diff($endDate);
$SumWiFi = 0;
$F = 0;
foreach ($MIMO as $date=>$Fi){
$date = new DateTime($date);
//Only take into account the MIMO if it falls between the start and end dates.
if ($date >= $startDate && $date <= $endDate){
$Di = $date->diff($startDate);
$Wi = ($CD->d - $Di->d) / $CD->d;
$SumWiFi += $Wi * $Fi;
$F += $Fi;
}
}
if ($BMV + $SumWiFi != 0) {
return ($EMV - $BMV - $F)/($BMV + $SumWiFi);
} else {
return 0;
}
}
$mimo = array(
'2013-04-19' => -600.0,
'2013-04-23' => 1000000.0,
'2013-04-29' => -13750,
);
$startDate = new DateTime('2013-03-31');
$endDate = new DateTime('2013-04-30');
$result = modDietz($startDate, $endDate, 4990430.0, 5991710.1, $mimo);
// 0.0029925034725645