@@ -17,7 +17,9 @@ def run_strategy(self, algorithm, market_data):
17
17
18
18
19
19
class Test (TestBase ):
20
-
20
+ """
21
+ Collection of tests for backtest report operations
22
+ """
21
23
def setUp (self ) -> None :
22
24
self .resource_dir = os .path .abspath (
23
25
os .path .join (
@@ -36,6 +38,9 @@ def setUp(self) -> None:
36
38
)
37
39
38
40
def test_report_csv_creation (self ):
41
+ """
42
+ Test if the backtest report is created as a CSV file
43
+ """
39
44
app = create_app (
40
45
config = {"test" : "test" , RESOURCE_DIRECTORY : self .resource_dir }
41
46
)
@@ -65,11 +70,55 @@ def test_report_csv_creation(self):
65
70
)
66
71
67
72
def test_report_csv_creation_without_strategy_identifier (self ):
73
+ """
74
+ Test if the backtest report is created as a CSV file
75
+ when the strategy does not have an identifier
76
+ """
77
+ app = create_app (
78
+ config = {"test" : "test" , RESOURCE_DIRECTORY : self .resource_dir }
79
+ )
80
+ strategy = TestStrategy ()
81
+ strategy .strategy_id = None
82
+ app .add_strategy (strategy )
83
+ app .add_portfolio_configuration (
84
+ PortfolioConfiguration (
85
+ market = "bitvavo" ,
86
+ trading_symbol = "EUR" ,
87
+ initial_balance = 1000
88
+ )
89
+ )
90
+ report = app .backtest (
91
+ start_date = datetime .utcnow () - timedelta (days = 1 ),
92
+ end_date = datetime .utcnow (),
93
+ )
94
+
95
+ # Check if the backtest report exists
96
+ self .assertTrue (
97
+ os .path .isfile (
98
+ os .path .join (
99
+ self .resource_dir ,
100
+ "backtest_reports" ,
101
+ f"report"
102
+ f"_{ report .created_at .strftime (DATETIME_FORMAT )} .csv"
103
+ )
104
+ )
105
+ )
106
+
107
+ def test_report_csv_creation_with_multiple_strategies (self ):
108
+ """
109
+ Test if the backtest report is created as a CSV file
110
+ when there are multiple strategies
111
+ """
68
112
app = create_app (
69
113
config = {"test" : "test" , RESOURCE_DIRECTORY : self .resource_dir }
70
114
)
71
115
strategy = TestStrategy ()
72
116
strategy .strategy_id = None
117
+
118
+ @app .strategy ()
119
+ def run_strategy (algorithm , market_data ):
120
+ pass
121
+
73
122
app .add_strategy (strategy )
74
123
app .add_portfolio_configuration (
75
124
PortfolioConfiguration (
@@ -78,6 +127,8 @@ def test_report_csv_creation_without_strategy_identifier(self):
78
127
initial_balance = 1000
79
128
)
80
129
)
130
+
131
+ self .assertEqual (2 , len (app .strategies ))
81
132
report = app .backtest (
82
133
start_date = datetime .utcnow () - timedelta (days = 1 ),
83
134
end_date = datetime .utcnow (),
@@ -94,3 +145,43 @@ def test_report_csv_creation_without_strategy_identifier(self):
94
145
)
95
146
)
96
147
)
148
+
149
+ def test_report_csv_creation_with_multiple_strategies_with_id (self ):
150
+ """
151
+ Test if the backtest report is created as a CSV file
152
+ when there are multiple strategies with identifiers
153
+ """
154
+ app = create_app (
155
+ config = {"test" : "test" , RESOURCE_DIRECTORY : self .resource_dir }
156
+ )
157
+
158
+ @app .strategy ()
159
+ def run_strategy (algorithm , market_data ):
160
+ pass
161
+
162
+ app .add_strategy (TestStrategy )
163
+ app .add_portfolio_configuration (
164
+ PortfolioConfiguration (
165
+ market = "bitvavo" ,
166
+ trading_symbol = "EUR" ,
167
+ initial_balance = 1000
168
+ )
169
+ )
170
+
171
+ self .assertEqual (2 , len (app .strategies ))
172
+ report = app .backtest (
173
+ start_date = datetime .utcnow () - timedelta (days = 1 ),
174
+ end_date = datetime .utcnow (),
175
+ )
176
+
177
+ # Check if the backtest report exists
178
+ self .assertTrue (
179
+ os .path .isfile (
180
+ os .path .join (
181
+ self .resource_dir ,
182
+ "backtest_reports" ,
183
+ f"report_{ report .identifier } "
184
+ f"_{ report .created_at .strftime (DATETIME_FORMAT )} .csv"
185
+ )
186
+ )
187
+ )
0 commit comments