diff options
Diffstat (limited to 'app/trading')
-rw-r--r-- | app/trading/models.py | 4 | ||||
-rw-r--r-- | app/trading/templates/trading/list.html | 13 | ||||
-rw-r--r-- | app/trading/views.py | 1 |
3 files changed, 18 insertions, 0 deletions
diff --git a/app/trading/models.py b/app/trading/models.py index 026c9cb..704f3bb 100644 --- a/app/trading/models.py +++ b/app/trading/models.py @@ -106,6 +106,10 @@ class LuxTradeStatsManager(models.Manager): end_date = datetime.date(timezone.now().year, month, last_day) return self.filter(close_date__range=(start_date, end_date)).aggregate(Sum('pl')) + def get_year_pl(self, year=timezone.now().year): + start_date = datetime.date(year, 1, 1) + end_date = datetime.date(year, 12, 31) + return self.filter(close_date__range=(start_date, end_date)).aggregate(Sum('pl')) class LuxTrade(models.Model): symbol = models.CharField(max_length=256) diff --git a/app/trading/templates/trading/list.html b/app/trading/templates/trading/list.html index f2f7e26..a36c15c 100644 --- a/app/trading/templates/trading/list.html +++ b/app/trading/templates/trading/list.html @@ -195,6 +195,19 @@ <td>{{month}} P/L:</td> <td>{{monthly_pl.pl__sum}}</td> </tr> + <tr> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td></td> + <td>YTD P/L:</td> + <td>{{year_pl.pl__sum}}</td> + </tr> </table> diff --git a/app/trading/views.py b/app/trading/views.py index 9922bd5..c9dbeec 100644 --- a/app/trading/views.py +++ b/app/trading/views.py @@ -17,6 +17,7 @@ class LuxTradeListView(PaginatedListView): context['options_trades'] = LuxOptionsTrade.objects.filter(status__in=[0,2]) context['options_trades_closed'] = LuxOptionsTrade.objects.filter(status=1) context['monthly_pl'] = LuxTrade.stats.get_month_pl() + context['year_pl'] = LuxTrade.stats.get_month_pl() context['month'] = datetime.now().strftime('%h') return context |