adds dividend re-investment feature

This commit is contained in:
hackerESQ
2024-10-18 20:46:22 -05:00
parent e4d45f391c
commit 51c33ebec0
14 changed files with 218 additions and 17 deletions
+16 -1
View File
@@ -26,11 +26,13 @@ class Holding extends Model
'realized_gain_dollars',
'dividends_earned',
'splits_synced_at',
'reinvest_dividends'
];
protected $casts = [
'splits_synced_at' => 'datetime',
'first_transaction_date' => 'datetime'
'first_transaction_date' => 'datetime',
'reinvest_dividends' => 'boolean'
];
protected $attributes = [
@@ -209,6 +211,19 @@ class Holding extends Model
$this->save();
}
public function qtyOwned(\Illuminate\Support\Carbon $date = null)
{
if ($date == null) $date = now();
$transactions = $this->transactions->where('date', '<=', $date);
$purchases = $transactions->where('transaction_type', 'BUY')->sum('quantity');
$sales = $transactions->where('transaction_type', 'SELL')->sum('quantity');
return $purchases - $sales;
}
public function dailyPerformance(
\Illuminate\Support\Carbon $start_date = null,
\Illuminate\Support\Carbon $end_date = null,