simplify tests and daily change calculations

This commit is contained in:
hackerESQ
2024-09-23 15:09:35 -05:00
parent d0fbf44fa0
commit 7d119a8c24
8 changed files with 77 additions and 65 deletions
+11 -9
View File
@@ -127,15 +127,17 @@ class Portfolio extends Model
$total_market_value = $performance->owned * $close;
$dividends_earned += $performance->owned * ($dividends->get($date)?->dividend_amount ?? 0);
$daily[$date] = [
'date' => $date,
'portfolio_id' => $this->id,
'total_market_value' => $total_market_value,
'total_cost_basis' => $performance->cost_basis,
'total_gain' => $total_market_value - $performance->cost_basis,
'realized_gains' => $performance->realized_gains,
'total_dividends_earned' => $dividends_earned
];
if (Carbon::parse($date)->isWeekday()) {
$daily[$date] = [
'date' => $date,
'portfolio_id' => $this->id,
'total_market_value' => $total_market_value,
'total_cost_basis' => $performance->cost_basis,
'total_gain' => $total_market_value - $performance->cost_basis,
'realized_gains' => $performance->realized_gains,
'total_dividends_earned' => $dividends_earned
];
}
});
foreach ($daily as $date => $performance) {