1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| $credits = [];
$credits[1] = [
'duree_mois' => 360,
'nominal' => 100000,
'taux_annuel' => 3/100,
'franchise_mois' => 0,
'franchise_taux' => 0
];
$credits[2] = [
'duree_mois' => 120,
'nominal' => 60000,
'taux_annuel' => 0,
'franchise_mois' => 180,
'franchise_taux' => 0
];
$credits[3] = [
'duree_mois' => 180,
'nominal' => 80000,
'taux_annuel' => 1.5/100,
'franchise_mois' => 0,
'franchise_taux' => 0
];
// calcul : taux mensuel et mensualité
foreach ($credits as &$c) {
$c['taux_mensuel'] = $c['taux_annuel'] / 12;
if ($c['taux_annuel'] > 0) {
$c['mensualité'] = $c['nominal'] * $c['taux_mensuel'] / (1 - pow(1 + $c['taux_mensuel'], -$c['duree_mois']));
} else {
$c['mensualité'] = $c['nominal'] / $c['duree_mois'];
}
}
// lissage : je considère que le $credit[1] correspond au crédit principal
$numerateur = [$credits[1]['nominal'] * $credits[1]['taux_mensuel']];
$denominateur = [pow(1 + $credits[1]['mensualité'], -$credits[1]['franchise_mois']-1)];
$duree = $credits[1]['duree_mois'];
$fixe = 1 + $credits[1]['taux_mensuel'];
foreach ($credits as $k => $c) {
if ($k > 1) {
$numerateur[] = 0 - ($c['mensualité'] * (1 - pow($fixe, -$c['franchise_mois'])));
$numerateur[] = $c['mensualité'] * (1 - pow($fixe, -$c['franchise_mois']) * pow($fixe, -$c['duree_mois']));
$denominateur[] = pow($fixe, -$c['franchise_mois']-1);
$denominateur[] = pow($fixe, -$c['duree_mois']);
$duree -= ($c['franchise_mois'] + 1 + $c['duree_mois']);
}
}
$denominateur[] = pow($fixe, -$duree);
$mensualite_lisse = array_sum($numerateur) / (1 - array_product($denominateur)); |
Partager