@@ -51,17 +51,19 @@ def is_positive(number) -> bool:
51
51
return number > 0
52
52
53
53
54
- def pretty_print_profit_evaluation (reports , precision = 4 ):
54
+ def pretty_print_profit_evaluation (
55
+ reports , price_precision = 2 , percentage_precision = 4
56
+ ):
55
57
profit_table = {}
56
58
profit_table ["Algorithm name" ] = [
57
59
report .name for report in reports
58
60
]
59
61
profit_table ["Profit" ] = [
60
- f"{ float (report .total_net_gain ):.{precision }f} { report .trading_symbol } "
62
+ f"{ float (report .total_net_gain ):.{price_precision }f} { report .trading_symbol } "
61
63
for report in reports
62
64
]
63
65
profit_table ["Profit percentage" ] = [
64
- f"{ float (report .total_net_gain_percentage ):.{precision }f} %" for report in reports
66
+ f"{ float (report .total_net_gain_percentage ):.{percentage_precision }f} %" for report in reports
65
67
]
66
68
profit_table ["Percentage positive trades" ] = [
67
69
f"{ float (report .percentage_positive_trades ):.{0 }f} %"
@@ -72,21 +74,25 @@ def pretty_print_profit_evaluation(reports, precision=4):
72
74
for report in reports
73
75
]
74
76
profit_table ["Total value" ] = [
75
- f"{ float (report .total_value ):.{precision }f} " for report in reports
77
+ f"{ float (report .total_value ):.{price_precision }f} " for report in reports
76
78
]
77
79
print (tabulate (profit_table , headers = "keys" , tablefmt = "rounded_grid" ))
78
80
79
81
80
- def pretty_print_growth_evaluation (reports , precision = 4 ):
82
+ def pretty_print_growth_evaluation (
83
+ reports ,
84
+ price_precision = 2 ,
85
+ percentage_precision = 4
86
+ ):
81
87
growth_table = {}
82
88
growth_table ["Algorithm name" ] = [
83
89
report .name for report in reports
84
90
]
85
91
growth_table ["Growth" ] = [
86
- f"{ float (report .growth ):.{precision }f} { report .trading_symbol } " for report in reports
92
+ f"{ float (report .growth ):.{price_precision }f} { report .trading_symbol } " for report in reports
87
93
]
88
94
growth_table ["Growth percentage" ] = [
89
- f"{ float (report .growth_rate ):.{precision }f} %" for report in reports
95
+ f"{ float (report .growth_rate ):.{percentage_precision }f} %" for report in reports
90
96
]
91
97
growth_table ["Percentage positive trades" ] = [
92
98
f"{ float (report .percentage_positive_trades ):.{0 }f} %"
@@ -97,7 +103,7 @@ def pretty_print_growth_evaluation(reports, precision=4):
97
103
for report in reports
98
104
]
99
105
growth_table ["Total value" ] = [
100
- f"{ float (report .total_value ):.{precision }f} " for report in reports
106
+ f"{ float (report .total_value ):.{price_precision }f} " for report in reports
101
107
]
102
108
print (
103
109
tabulate (growth_table , headers = "keys" , tablefmt = "rounded_grid" )
@@ -683,8 +689,8 @@ def pretty_print_backtest_reports_evaluation(
683
689
:%%%#+- .=*#%%% { COLOR_GREEN } Backtest reports evaluation{ COLOR_RESET }
684
690
*%%%%%%%+------=*%%%%%%%- { COLOR_GREEN } ---------------------------{ COLOR_RESET }
685
691
*%%%%%%%%%%%%%%%%%%%%%%%- { COLOR_YELLOW } Number of reports:{ COLOR_RESET } { COLOR_GREEN } { number_of_backtest_reports } backtest reports{ COLOR_RESET }
686
- .%%%%%%%%%%%%%%%%%%%%%%# { COLOR_YELLOW } Largest overall profit:{ COLOR_RESET } { COLOR_GREEN } { COLOR_RESET } { COLOR_GREEN } (Algorithm { most_profitable .name } ) { float (most_profitable .total_net_gain ):.{precision }f} { most_profitable .trading_symbol } { float (most_profitable .total_net_gain_percentage ):.{precision }f} % ({ most_profitable .backtest_date_range .name } { most_profitable .backtest_date_range .start_date } - { most_profitable .backtest_date_range .end_date } ){ COLOR_RESET }
687
- #%%%####%%%%%%%%**#%%%+ { COLOR_YELLOW } Largest overall growth:{ COLOR_RESET } { COLOR_GREEN } (Algorithm { most_profitable .name } ) { float (most_growth .growth ):.{precision }f} { most_growth .trading_symbol } { float (most_growth .growth_rate ):.{precision }f} % ({ most_growth .backtest_date_range .name } { most_growth .backtest_date_range .start_date } - { most_growth .backtest_date_range .end_date } ){ COLOR_RESET }
692
+ .%%%%%%%%%%%%%%%%%%%%%%# { COLOR_YELLOW } Largest overall profit:{ COLOR_RESET } { COLOR_GREEN } { COLOR_RESET } { COLOR_GREEN } (Algorithm { most_profitable .name } ) { float (most_profitable .total_net_gain ):.{price_precision }f} { most_profitable .trading_symbol } { float (most_profitable .total_net_gain_percentage ):.{percentage_precision }f} % ({ most_profitable .backtest_date_range .name } { most_profitable .backtest_date_range .start_date } - { most_profitable .backtest_date_range .end_date } ){ COLOR_RESET }
693
+ #%%%####%%%%%%%%**#%%%+ { COLOR_YELLOW } Largest overall growth:{ COLOR_RESET } { COLOR_GREEN } (Algorithm { most_profitable .name } ) { float (most_growth .growth ):.{price_precision }f} { most_growth .trading_symbol } { float (most_growth .growth_rate ):.{percentage_precision }f} % ({ most_growth .backtest_date_range .name } { most_growth .backtest_date_range .start_date } - { most_growth .backtest_date_range .end_date } ){ COLOR_RESET }
688
694
.:-+*%%%%- { COLOR_PURPLE } -+..#{ COLOR_RESET } %%%+.{ COLOR_PURPLE } +- +{ COLOR_RESET } %%%#*=-:
689
695
.:-=*%%%%. { COLOR_PURPLE } +={ COLOR_RESET } .%%# { COLOR_PURPLE } -+.-{ COLOR_RESET } %%%%=-:..
690
696
.:=+#%%%%%*###%%%%#*+#%%%%%%*+-:
@@ -711,14 +717,18 @@ def pretty_print_backtest_reports_evaluation(
711
717
pretty_print_date_ranges (backtest_reports_evaluation .get_date_ranges ())
712
718
print ("" )
713
719
714
- pretty_print_price_efficiency (reports , precision = precision )
720
+ pretty_print_price_efficiency (reports , precision = price_precision )
715
721
print (f"{ COLOR_YELLOW } All profits ordered{ COLOR_RESET } " )
716
722
pretty_print_profit_evaluation (
717
- backtest_reports_evaluation .get_profit_order (backtest_date_range ), precision
723
+ backtest_reports_evaluation .get_profit_order (backtest_date_range ),
724
+ price_precision = price_precision ,
725
+ percentage_precision = percentage_precision
718
726
)
719
727
print (f"{ COLOR_YELLOW } All growths ordered{ COLOR_RESET } " )
720
728
pretty_print_growth_evaluation (
721
- backtest_reports_evaluation .get_growth_order (backtest_date_range ), precision
729
+ backtest_reports_evaluation .get_growth_order (backtest_date_range ),
730
+ percentage_precision = percentage_precision ,
731
+ price_precision = price_precision
722
732
)
723
733
724
734
@@ -755,7 +765,10 @@ def pretty_print_backtest(
755
765
show_triggered_stop_losses_only: bool - show only the triggered stop losses
756
766
show_take_profits: bool - show the take profits
757
767
show_triggered_take_profits_only: bool - show only the triggered take profits
758
- precision: int - the precision of the floats
768
+ amount_precesion: int - the amount precision
769
+ price_precision: int - the price precision
770
+ time_precision: int - the time precision
771
+ percentage_precision: int - the percentage precision
759
772
760
773
Returns:
761
774
None
@@ -785,7 +798,6 @@ def pretty_print_backtest(
785
798
"""
786
799
787
800
print (ascii_art )
788
- # pretty_print_price_efficiency([backtest_report], precision=precision)
789
801
790
802
if show_positions :
791
803
print (f"{ COLOR_YELLOW } Positions overview{ COLOR_RESET } " )
0 commit comments