From eb5f0b6755ac233ae2ff30dc0329722ed7e46a75 Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Fri, 17 Jan 2020 22:04:31 +0700 Subject: [PATCH] Performance: added various stats --- forms.py | 23 ++++++++- templates/dashboard/performance.html | 44 +++++++++++++++++ views.py | 71 +++++++++++++++++++++++----- 3 files changed, 125 insertions(+), 13 deletions(-) diff --git a/forms.py b/forms.py index 42fdeb0..c689609 100644 --- a/forms.py +++ b/forms.py @@ -30,7 +30,7 @@ class TradeFilterForm(forms.Form): def __init__(self, *args, show_unbalanced_checkbox=False, **kwargs): super().__init__(*args, **kwargs) - now = datetime.date.today() + now = datetime.date.today() + datetime.timedelta(days=1) all_accounts, all_strategies = get_all_accounts_and_strategies() self.fields['accounts'] = forms.MultipleChoiceField(choices=zip(sorted(list(all_accounts)), sorted(list(all_accounts))), required=False) @@ -42,3 +42,24 @@ class TradeFilterForm(forms.Form): self.fields['unbalanced_only'] = forms.BooleanField(required=False) except KeyError: pass + +# Can't subclass it from TradeFilterForm, field 'timestamp' will not show. Go figure. +class PerformanceFilterForm(forms.Form): + def __init__(self, *args, show_unbalanced_checkbox=False, **kwargs): + super().__init__(*args, **kwargs) + + now = datetime.date.today() + datetime.timedelta(days=1) + + all_accounts, all_strategies = get_all_accounts_and_strategies() + self.fields['accounts'] = forms.MultipleChoiceField(choices=zip(sorted(list(all_accounts)), sorted(list(all_accounts))), required=False) + self.fields['strategies'] = forms.MultipleChoiceField(choices=zip(sorted(list(all_strategies)), sorted(list(all_strategies))), required=False) + self.fields['startdate'] = forms.DateField(initial=(now - datetime.timedelta(weeks=4))) + self.fields['enddate'] = forms.DateField(initial=now) + try: + if show_unbalanced_checkbox: + self.fields['unbalanced_only'] = forms.BooleanField(required=False) + except KeyError: + pass + + self.fields['timeframe'] = forms.ChoiceField(choices=[('daily', 'Daily'), ('weekly', 'Weekly'), ('monthly', 'Monthly')]) + diff --git a/templates/dashboard/performance.html b/templates/dashboard/performance.html index 2da5963..fa31e18 100644 --- a/templates/dashboard/performance.html +++ b/templates/dashboard/performance.html @@ -5,11 +5,27 @@ {% load humanize %} {% block content %} + +
+ +
+
+ {% csrf_token %} + {% bootstrap_form trades_filter_form %} + {% bootstrap_button button_type='submit' content='Submit' %} +
+
+
+ +
@@ -37,6 +53,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterTradePeriod
Mean {{ results.stats.mean }} {{ results.stats_period.mean }}
Std. dev. {{ results.stats.stddev }} {{ results.stats_period.stddev }}
Skew {{ results.stats.skew }} {{ results.stats_period.skew }}
Kurtosis {{ results.stats.kurtosis }} {{ results.stats_period.kurtosis }}
+