Skip to content

Commit c322218

Browse files
committed
Add backtest date range
1 parent 3e9e3fc commit c322218

File tree

72 files changed

+8488
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+8488
-506
lines changed

examples/backtest_experiment/configuration.json

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -14,133 +14,5 @@
1414
"slow":50,
1515
"trend":100,
1616
"stop_loss_percentage":7
17-
},
18-
{
19-
"name":"11-50-100",
20-
"description":"11-50-100",
21-
"fast":11,
22-
"slow":50,
23-
"trend":100,
24-
"stop_loss_percentage":7
25-
},
26-
{
27-
"name":"9-75-150",
28-
"description":"9-75-150",
29-
"fast":9,
30-
"slow":75,
31-
"trend":150,
32-
"stop_loss_percentage":7
33-
},
34-
{
35-
"name":"10-75-150",
36-
"description":"10-75-150",
37-
"fast":10,
38-
"slow":75,
39-
"trend":150,
40-
"stop_loss_percentage":7
41-
},
42-
{
43-
"name":"11-75-150",
44-
"description":"11-75-150",
45-
"fast":11,
46-
"slow":75,
47-
"trend":150,
48-
"stop_loss_percentage":7
49-
},
50-
{
51-
"name":"20-75-150",
52-
"description":"20-75-150",
53-
"fast":20,
54-
"slow":75,
55-
"trend":150,
56-
"stop_loss_percentage":7
57-
},
58-
{
59-
"name":"21-75-150",
60-
"description":"21-75-150",
61-
"fast":21,
62-
"slow":75,
63-
"trend":150,
64-
"stop_loss_percentage":7
65-
},
66-
{
67-
"name":"22-75-150",
68-
"description":"22-75-150",
69-
"fast":22,
70-
"slow":75,
71-
"trend":150,
72-
"stop_loss_percentage":7
73-
},
74-
{
75-
"name":"23-75-150",
76-
"description":"23-75-150",
77-
"fast":23,
78-
"slow":75,
79-
"trend":150,
80-
"stop_loss_percentage":7
81-
},
82-
{
83-
"name":"24-75-150",
84-
"description":"24-75-150",
85-
"fast":24,
86-
"slow":75,
87-
"trend":150,
88-
"stop_loss_percentage":7
89-
},
90-
{
91-
"name":"25-75-150",
92-
"description":"25-75-150",
93-
"fast":25,
94-
"slow":75,
95-
"trend":150,
96-
"stop_loss_percentage":7
97-
},
98-
{
99-
"name":"20-75-200",
100-
"description":"20-75-200",
101-
"fast":20,
102-
"slow":75,
103-
"trend":200,
104-
"stop_loss_percentage":7
105-
},
106-
{
107-
"name":"21-75-200",
108-
"description":"24-75-200",
109-
"fast":24,
110-
"slow":75,
111-
"trend":200,
112-
"stop_loss_percentage":7
113-
},
114-
{
115-
"name":"22-75-200",
116-
"description":"24-75-200",
117-
"fast":24,
118-
"slow":75,
119-
"trend":200,
120-
"stop_loss_percentage":7
121-
},
122-
{
123-
"name":"23-75-200",
124-
"description":"24-75-200",
125-
"fast":24,
126-
"slow":75,
127-
"trend":200,
128-
"stop_loss_percentage":7
129-
},
130-
{
131-
"name":"24-75-200",
132-
"description":"24-75-200",
133-
"fast":24,
134-
"slow":75,
135-
"trend":200,
136-
"stop_loss_percentage":7
137-
},
138-
{
139-
"name":"25-75-150",
140-
"description":"25-75-200",
141-
"fast":25,
142-
"slow":75,
143-
"trend":200,
144-
"stop_loss_percentage":7
14517
}
14618
]
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
[
2+
{
3+
"name":"9-50-100",
4+
"description":"9-50-100",
5+
"fast":9,
6+
"slow":50,
7+
"trend":100,
8+
"stop_loss_percentage":7
9+
},
10+
{
11+
"name":"10-50-100",
12+
"description":"10-50-100",
13+
"fast":10,
14+
"slow":50,
15+
"trend":100,
16+
"stop_loss_percentage":7
17+
},
18+
{
19+
"name":"11-50-100",
20+
"description":"11-50-100",
21+
"fast":11,
22+
"slow":50,
23+
"trend":100,
24+
"stop_loss_percentage":7
25+
},
26+
{
27+
"name":"9-75-150",
28+
"description":"9-75-150",
29+
"fast":9,
30+
"slow":75,
31+
"trend":150,
32+
"stop_loss_percentage":7
33+
},
34+
{
35+
"name":"10-75-150",
36+
"description":"10-75-150",
37+
"fast":10,
38+
"slow":75,
39+
"trend":150,
40+
"stop_loss_percentage":7
41+
},
42+
{
43+
"name":"11-75-150",
44+
"description":"11-75-150",
45+
"fast":11,
46+
"slow":75,
47+
"trend":150,
48+
"stop_loss_percentage":7
49+
},
50+
{
51+
"name":"20-75-150",
52+
"description":"20-75-150",
53+
"fast":20,
54+
"slow":75,
55+
"trend":150,
56+
"stop_loss_percentage":7
57+
},
58+
{
59+
"name":"21-75-150",
60+
"description":"21-75-150",
61+
"fast":21,
62+
"slow":75,
63+
"trend":150,
64+
"stop_loss_percentage":7
65+
},
66+
{
67+
"name":"22-75-150",
68+
"description":"22-75-150",
69+
"fast":22,
70+
"slow":75,
71+
"trend":150,
72+
"stop_loss_percentage":7
73+
},
74+
{
75+
"name":"23-75-150",
76+
"description":"23-75-150",
77+
"fast":23,
78+
"slow":75,
79+
"trend":150,
80+
"stop_loss_percentage":7
81+
},
82+
{
83+
"name":"24-75-150",
84+
"description":"24-75-150",
85+
"fast":24,
86+
"slow":75,
87+
"trend":150,
88+
"stop_loss_percentage":7
89+
},
90+
{
91+
"name":"25-75-150",
92+
"description":"25-75-150",
93+
"fast":25,
94+
"slow":75,
95+
"trend":150,
96+
"stop_loss_percentage":7
97+
},
98+
{
99+
"name":"20-75-200",
100+
"description":"20-75-200",
101+
"fast":20,
102+
"slow":75,
103+
"trend":200,
104+
"stop_loss_percentage":7
105+
},
106+
{
107+
"name":"21-75-200",
108+
"description":"24-75-200",
109+
"fast":24,
110+
"slow":75,
111+
"trend":200,
112+
"stop_loss_percentage":7
113+
},
114+
{
115+
"name":"22-75-200",
116+
"description":"24-75-200",
117+
"fast":24,
118+
"slow":75,
119+
"trend":200,
120+
"stop_loss_percentage":7
121+
},
122+
{
123+
"name":"23-75-200",
124+
"description":"24-75-200",
125+
"fast":24,
126+
"slow":75,
127+
"trend":200,
128+
"stop_loss_percentage":7
129+
},
130+
{
131+
"name":"24-75-200",
132+
"description":"24-75-200",
133+
"fast":24,
134+
"slow":75,
135+
"trend":200,
136+
"stop_loss_percentage":7
137+
},
138+
{
139+
"name":"25-75-150",
140+
"description":"25-75-200",
141+
"fast":25,
142+
"slow":75,
143+
"trend":200,
144+
"stop_loss_percentage":7
145+
}
146+
]

examples/backtest_experiment/run_backtest.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import json
2-
from datetime import datetime, timedelta
2+
from datetime import datetime
33

44
from algorithms import create_algorithm
55
from app import app
66
from investing_algorithm_framework import PortfolioConfiguration, \
7-
pretty_print_backtest_reports_evaluation, BacktestReportsEvaluation
7+
pretty_print_backtest_reports_evaluation, BacktestReportsEvaluation, \
8+
BacktestDateRange
89

910
if __name__ == "__main__":
10-
end_date = datetime(2023, 12, 2)
11-
start_date = end_date - timedelta(days=100)
11+
down_turn_date_range = BacktestDateRange(
12+
start_date=datetime(2021, 12, 21),
13+
end_date=datetime(2022, 6, 20),
14+
name="down_turn"
15+
)
16+
up_turn_date_range = BacktestDateRange(
17+
start_date=datetime(2022, 12, 20),
18+
end_date=datetime(2023, 6, 1),
19+
name="up_turn"
20+
)
21+
sideways_date_range = BacktestDateRange(
22+
start_date=datetime(2022, 6, 10),
23+
end_date=datetime(2023, 1, 10),
24+
name="sideways"
25+
)
26+
1227
json = json.load(open("configuration.json"))
1328
algorithms = []
1429

@@ -27,12 +42,9 @@
2742
reports = app.run_backtests(
2843
algorithms=algorithms,
2944
date_ranges=[
30-
(datetime(2023, 7, 2),
31-
datetime(2023, 7, 2) + timedelta(days=200)),
32-
(datetime(2022, 7, 2),
33-
datetime(2022, 7, 2) + timedelta(days=200)),
34-
(datetime(2024, 1, 1),
35-
datetime(2024, 1, 1) + timedelta(days=100)),
45+
down_turn_date_range,
46+
up_turn_date_range,
47+
sideways_date_range
3648
],
3749
pending_order_check_interval="2h",
3850
)

investing_algorithm_framework/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
Trade, OHLCVMarketDataSource, OrderBookMarketDataSource, SYMBOLS, \
1010
TickerMarketDataSource, MarketService, BacktestReportsEvaluation, \
1111
pretty_print_backtest_reports_evaluation, load_backtest_reports, \
12-
RESERVED_BALANCES, APP_MODE, AppMode, DATETIME_FORMAT
12+
RESERVED_BALANCES, APP_MODE, AppMode, DATETIME_FORMAT,\
13+
load_backtest_report, BacktestDateRange
1314
from investing_algorithm_framework.infrastructure import \
1415
CCXTOrderBookMarketDataSource, CCXTOHLCVMarketDataSource, \
1516
CCXTTickerMarketDataSource, CSVOHLCVMarketDataSource, \
@@ -61,4 +62,6 @@
6162
"APP_MODE",
6263
"AppMode",
6364
"DATETIME_FORMAT",
65+
"load_backtest_report",
66+
"BacktestDateRange",
6467
]

0 commit comments

Comments
 (0)