From 2a6b896e37a02224c677a5aae4d6786a20c1d535 Mon Sep 17 00:00:00 2001 From: Xu Tiezhu Date: Tue, 13 Mar 2018 18:13:35 +0800 Subject: [PATCH] change float format in report template --- jaqs/trade/analyze/analyze.py | 51 ++++++++++--------- .../trade/analyze/static/report_template.html | 16 +++--- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/jaqs/trade/analyze/analyze.py b/jaqs/trade/analyze/analyze.py index b82e4d9..76fa722 100644 --- a/jaqs/trade/analyze/analyze.py +++ b/jaqs/trade/analyze/analyze.py @@ -608,45 +608,50 @@ def get_returns(self, compound_return=False, consider_commission=True): 100 * (df_returns.loc[:, 'active'].std() * np.sqrt(common.CALENDAR_CONST.TRADE_DAYS_PER_YEAR)) self.performance_metrics['Sharpe Ratio'] = (self.performance_metrics['Annual Return (%)'] / self.performance_metrics['Annual Volatility (%)']) - self.performance_metrics['Number of Trades'] = len(self.trades.index) - self.performance_metrics['Total PNL'] = df_pnl.loc[:,'total_pnl'].sum() - self.performance_metrics['Daily Win Rate(%)'] = "%.2f"%(win_rate*100) - self.performance_metrics['Daily Lost Rate(%)'] = "%.2f"%(lost_rate*100) - self.performance_metrics['Commission'] = df_pnl.loc[:,'commission'].sum() + self.performance_metrics['Number of Trades'] = len(self.trades.index) + self.performance_metrics['Total PNL'] = df_pnl.loc[:,'total_pnl'].sum() + self.performance_metrics['Daily Win Rate(%)'] = win_rate*100 + self.performance_metrics['Daily Lost Rate(%)'] = lost_rate*100 + self.performance_metrics['Commission'] = df_pnl.loc[:,'commission'].sum() self.risk_metrics['Beta'] = np.corrcoef(df_returns.loc[:, 'bench'], df_returns.loc[:, 'strat'])[0, 1] - self.risk_metrics['Maximum Drawdown (%)'] = max_dd * TO_PCT + self.risk_metrics['Maximum Drawdown (%)'] = max_dd * TO_PCT self.risk_metrics['Maximum Drawdown start'] = df_returns.index[max_dd_start] - self.risk_metrics['Maximum Drawdown end'] = df_returns.index[max_dd_end] + self.risk_metrics['Maximum Drawdown end'] = df_returns.index[max_dd_end] #self.performance_metrics_report = sorted([(k,v) for (k,v) in self.performance_metrics.items()]) self.performance_metrics_report = [] - self.performance_metrics_report.append(('Total PNL', self.performance_metrics['Total PNL'])) - self.performance_metrics_report.append(('Commission', self.performance_metrics['Commission'])) - self.performance_metrics_report.append(('Annual Return (%)', self.performance_metrics['Annual Return (%)'])) - self.performance_metrics_report.append(('Annual Volatility (%)', self.performance_metrics['Annual Volatility (%)'])) - self.performance_metrics_report.append(('Sharpe Ratio', self.performance_metrics['Sharpe Ratio'])) - self.performance_metrics_report.append(('Number of Trades', self.performance_metrics['Number of Trades'])) - self.performance_metrics_report.append(('Daily Win Rate(%)', self.performance_metrics['Daily Win Rate(%)'])) - self.performance_metrics_report.append(('Daily Lost Rate(%)', self.performance_metrics['Daily Lost Rate(%)'])) + self.performance_metrics_report.append(('Annual Return (%)', "{:,.2f}".format( self.performance_metrics['Annual Return (%)'])) ) + self.performance_metrics_report.append(('Annual Volatility (%)', "{:,.2f}".format( self.performance_metrics['Annual Volatility (%)'])) ) + self.performance_metrics_report.append(('Sharpe Ratio', "{:,.2f}".format( self.performance_metrics['Sharpe Ratio'])) ) + self.performance_metrics_report.append(('Total PNL', "{:,.2f}".format( self.performance_metrics['Total PNL'])) ) + self.performance_metrics_report.append(('Commission', "{:,.2f}".format( self.performance_metrics['Commission'])) ) + self.performance_metrics_report.append(('Number of Trades', self.performance_metrics['Number of Trades'])) + self.performance_metrics_report.append(('Daily Win Rate(%)', "{:,.2f}".format( self.performance_metrics['Daily Win Rate(%)'])) ) + self.performance_metrics_report.append(('Daily Lost Rate(%)', "{:,.2f}".format( self.performance_metrics['Daily Lost Rate(%)'])) ) self.dailypnl_metrics_report = [] self.dailypnl_metrics_report.append(('Daily PNL Max Time', max_pnl.index[0])) - self.dailypnl_metrics_report.append(('Daily PNL Max',max_pnl.values[0])) + self.dailypnl_metrics_report.append(('Daily PNL Max', "{:,.2f}".format(max_pnl.values[0]))) self.dailypnl_metrics_report.append(('Daily PNL Min Time', min_pnl.index[0])) - self.dailypnl_metrics_report.append(('Daily PNL Min',min_pnl.values[0])) - self.dailypnl_metrics_report.append(('Daily PNL Up 5%', up5pct)) - self.dailypnl_metrics_report.append(('Daily PNL Low 5%', low5pct)) + self.dailypnl_metrics_report.append(('Daily PNL Min', "{:,.2f}".format(min_pnl.values[0]))) + self.dailypnl_metrics_report.append(('Daily PNL Up 5%', "{:,.2f}".format(up5pct))) + self.dailypnl_metrics_report.append(('Daily PNL Low 5%', "{:,.2f}".format(low5pct))) self.dailypnl_tail5_metrics_report = [] for k,v in tail5_pnl.iteritems(): - self.dailypnl_tail5_metrics_report.append((k,v)) + self.dailypnl_tail5_metrics_report.append((k, "{:,.2f}".format(v))) - self.dailypnl_top5_metrics_report = [] + self.dailypnl_top5_metrics_report = [] for k,v in top5_pnl.iteritems(): - self.dailypnl_top5_metrics_report.append((k,v)) + self.dailypnl_top5_metrics_report.append((k,"{:,.2f}".format(v))) - self.risk_metrics_report = sorted([(k, v) for (k, v) in self.risk_metrics.items()]) + #self.risk_metrics_report = sorted([(k, v) for (k, v) in self.risk_metrics.items()]) + self.risk_metrics_report = [] + self.risk_metrics_report.append(("Beta", "{:,.3f}".format( self.risk_metrics["Beta"])) ) + self.risk_metrics_report.append(("Maximum Drawdown (%)", "{:,.2f}".format( self.risk_metrics["Maximum Drawdown (%)"])) ) + self.risk_metrics_report.append(("Maximum Drawdown start", self.risk_metrics["Maximum Drawdown start"])) + self.risk_metrics_report.append(("Maximum Drawdown end", self.risk_metrics["Maximum Drawdown end"])) # bt_strat_mv = pd.read_csv('bt_strat_mv.csv').set_index('trade_date') # df_returns = df_returns.join(bt_strat_mv, how='right') diff --git a/jaqs/trade/analyze/static/report_template.html b/jaqs/trade/analyze/static/report_template.html index fba7d40..2b4c759 100644 --- a/jaqs/trade/analyze/static/report_template.html +++ b/jaqs/trade/analyze/static/report_template.html @@ -99,7 +99,7 @@

Strategy Performance Metrics

{% for key, value in performance_metrics_report %} {{key}} - {{value | round_if_float(1) }} + {{value | round_if_float(1) }} {% endfor %} @@ -116,7 +116,7 @@

Strategy Risk Metrics

{% for key, value in risk_metrics_report %} {{key}} - {{value | round_if_float(3) }} + {{value | round_if_float(3) }} {% endfor %} @@ -133,13 +133,14 @@

Daily PnL Metrics

{% for key, value in dailypnl_metrics_report %} {{key}} - {{value | round_if_float(3) }} + {{value | round_if_float(3) }} {% endfor %} +

Tail 5 Daily PnL

- + @@ -149,13 +150,14 @@

Daily PnL Metrics

{% for key, value in dailypnl_tail5_metrics_report %} - + {% endfor %}

Tail 5 Daily Pnl


This data is stored in Analyzer.dailypnl_tail5_metrics
This data is stored in Analyzer.dailypnl_tail5_metrics
Term
{{key}}{{value | round_if_float(3) }}{{value | round_if_float(3) }}
+

Top 5 Daily PnL

- + @@ -165,7 +167,7 @@

Daily PnL Metrics

{% for key, value in dailypnl_top5_metrics_report %} - + {% endfor %}

Top 5 Daily Pnl


This data is stored in Analyzer.dailypnl_top5_metrics
This data is stored in Analyzer.dailypnl_top5_metrics
Term
{{key}}{{value | round_if_float(3) }}{{value | round_if_float(3) }}