backtestingfx 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- backtestingfx-0.1.0/.gitignore +6 -0
- backtestingfx-0.1.0/Cargo.lock +398 -0
- backtestingfx-0.1.0/Cargo.toml +13 -0
- backtestingfx-0.1.0/LICENSE +21 -0
- backtestingfx-0.1.0/PKG-INFO +170 -0
- backtestingfx-0.1.0/README.md +158 -0
- backtestingfx-0.1.0/backtestingfx/__init__.py +2 -0
- backtestingfx-0.1.0/backtestingfx/backtest.py +100 -0
- backtestingfx-0.1.0/examples/simple_strategy.rs +27 -0
- backtestingfx-0.1.0/pyproject.toml +19 -0
- backtestingfx-0.1.0/python/backtest.py +100 -0
- backtestingfx-0.1.0/python/simple_strategy.py +28 -0
- backtestingfx-0.1.0/src/broker.rs +234 -0
- backtestingfx-0.1.0/src/data.rs +31 -0
- backtestingfx-0.1.0/src/engine.rs +95 -0
- backtestingfx-0.1.0/src/lib.rs +18 -0
- backtestingfx-0.1.0/src/stats.rs +148 -0
- backtestingfx-0.1.0/src/strategy.rs +8 -0
- backtestingfx-0.1.0/src/types.rs +58 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "android_system_properties"
|
|
7
|
+
version = "0.1.5"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"libc",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "autocfg"
|
|
16
|
+
version = "1.5.1"
|
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
19
|
+
|
|
20
|
+
[[package]]
|
|
21
|
+
name = "backtestingfx"
|
|
22
|
+
version = "0.1.0"
|
|
23
|
+
dependencies = [
|
|
24
|
+
"chrono",
|
|
25
|
+
"pyo3",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[[package]]
|
|
29
|
+
name = "bumpalo"
|
|
30
|
+
version = "3.20.3"
|
|
31
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
32
|
+
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
|
33
|
+
|
|
34
|
+
[[package]]
|
|
35
|
+
name = "cc"
|
|
36
|
+
version = "1.2.64"
|
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
38
|
+
checksum = "dad887fd958be91b5098c0248def011f4523ab786cd411be668777e55063501f"
|
|
39
|
+
dependencies = [
|
|
40
|
+
"find-msvc-tools",
|
|
41
|
+
"shlex",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[[package]]
|
|
45
|
+
name = "cfg-if"
|
|
46
|
+
version = "1.0.4"
|
|
47
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
48
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
49
|
+
|
|
50
|
+
[[package]]
|
|
51
|
+
name = "chrono"
|
|
52
|
+
version = "0.4.45"
|
|
53
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
54
|
+
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
|
|
55
|
+
dependencies = [
|
|
56
|
+
"iana-time-zone",
|
|
57
|
+
"js-sys",
|
|
58
|
+
"num-traits",
|
|
59
|
+
"wasm-bindgen",
|
|
60
|
+
"windows-link",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[[package]]
|
|
64
|
+
name = "core-foundation-sys"
|
|
65
|
+
version = "0.8.7"
|
|
66
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
67
|
+
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
|
68
|
+
|
|
69
|
+
[[package]]
|
|
70
|
+
name = "find-msvc-tools"
|
|
71
|
+
version = "0.1.9"
|
|
72
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
73
|
+
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
|
74
|
+
|
|
75
|
+
[[package]]
|
|
76
|
+
name = "futures-core"
|
|
77
|
+
version = "0.3.32"
|
|
78
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
79
|
+
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
|
80
|
+
|
|
81
|
+
[[package]]
|
|
82
|
+
name = "futures-task"
|
|
83
|
+
version = "0.3.32"
|
|
84
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
85
|
+
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
|
86
|
+
|
|
87
|
+
[[package]]
|
|
88
|
+
name = "futures-util"
|
|
89
|
+
version = "0.3.32"
|
|
90
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
91
|
+
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
|
92
|
+
dependencies = [
|
|
93
|
+
"futures-core",
|
|
94
|
+
"futures-task",
|
|
95
|
+
"pin-project-lite",
|
|
96
|
+
"slab",
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
[[package]]
|
|
100
|
+
name = "heck"
|
|
101
|
+
version = "0.5.0"
|
|
102
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
103
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
104
|
+
|
|
105
|
+
[[package]]
|
|
106
|
+
name = "iana-time-zone"
|
|
107
|
+
version = "0.1.65"
|
|
108
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
109
|
+
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
|
|
110
|
+
dependencies = [
|
|
111
|
+
"android_system_properties",
|
|
112
|
+
"core-foundation-sys",
|
|
113
|
+
"iana-time-zone-haiku",
|
|
114
|
+
"js-sys",
|
|
115
|
+
"log",
|
|
116
|
+
"wasm-bindgen",
|
|
117
|
+
"windows-core",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
[[package]]
|
|
121
|
+
name = "iana-time-zone-haiku"
|
|
122
|
+
version = "0.1.2"
|
|
123
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
124
|
+
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
|
125
|
+
dependencies = [
|
|
126
|
+
"cc",
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
[[package]]
|
|
130
|
+
name = "js-sys"
|
|
131
|
+
version = "0.3.102"
|
|
132
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
133
|
+
checksum = "03d04c30968dffe80775bd4d7fb676131cd04a1fb46d2686dbffbaec2d9dfd31"
|
|
134
|
+
dependencies = [
|
|
135
|
+
"cfg-if",
|
|
136
|
+
"futures-util",
|
|
137
|
+
"wasm-bindgen",
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
[[package]]
|
|
141
|
+
name = "libc"
|
|
142
|
+
version = "0.2.186"
|
|
143
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
144
|
+
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
|
145
|
+
|
|
146
|
+
[[package]]
|
|
147
|
+
name = "log"
|
|
148
|
+
version = "0.4.32"
|
|
149
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
150
|
+
checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
|
|
151
|
+
|
|
152
|
+
[[package]]
|
|
153
|
+
name = "num-traits"
|
|
154
|
+
version = "0.2.19"
|
|
155
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
156
|
+
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
157
|
+
dependencies = [
|
|
158
|
+
"autocfg",
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
[[package]]
|
|
162
|
+
name = "once_cell"
|
|
163
|
+
version = "1.21.4"
|
|
164
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
165
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
166
|
+
|
|
167
|
+
[[package]]
|
|
168
|
+
name = "pin-project-lite"
|
|
169
|
+
version = "0.2.17"
|
|
170
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
171
|
+
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
|
172
|
+
|
|
173
|
+
[[package]]
|
|
174
|
+
name = "portable-atomic"
|
|
175
|
+
version = "1.13.1"
|
|
176
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
177
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
178
|
+
|
|
179
|
+
[[package]]
|
|
180
|
+
name = "proc-macro2"
|
|
181
|
+
version = "1.0.106"
|
|
182
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
183
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
184
|
+
dependencies = [
|
|
185
|
+
"unicode-ident",
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
[[package]]
|
|
189
|
+
name = "pyo3"
|
|
190
|
+
version = "0.28.3"
|
|
191
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
192
|
+
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
|
|
193
|
+
dependencies = [
|
|
194
|
+
"libc",
|
|
195
|
+
"once_cell",
|
|
196
|
+
"portable-atomic",
|
|
197
|
+
"pyo3-build-config",
|
|
198
|
+
"pyo3-ffi",
|
|
199
|
+
"pyo3-macros",
|
|
200
|
+
]
|
|
201
|
+
|
|
202
|
+
[[package]]
|
|
203
|
+
name = "pyo3-build-config"
|
|
204
|
+
version = "0.28.3"
|
|
205
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
206
|
+
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
|
|
207
|
+
dependencies = [
|
|
208
|
+
"target-lexicon",
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
[[package]]
|
|
212
|
+
name = "pyo3-ffi"
|
|
213
|
+
version = "0.28.3"
|
|
214
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
215
|
+
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
|
|
216
|
+
dependencies = [
|
|
217
|
+
"libc",
|
|
218
|
+
"pyo3-build-config",
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
[[package]]
|
|
222
|
+
name = "pyo3-macros"
|
|
223
|
+
version = "0.28.3"
|
|
224
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
225
|
+
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
|
|
226
|
+
dependencies = [
|
|
227
|
+
"proc-macro2",
|
|
228
|
+
"pyo3-macros-backend",
|
|
229
|
+
"quote",
|
|
230
|
+
"syn",
|
|
231
|
+
]
|
|
232
|
+
|
|
233
|
+
[[package]]
|
|
234
|
+
name = "pyo3-macros-backend"
|
|
235
|
+
version = "0.28.3"
|
|
236
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
237
|
+
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
|
|
238
|
+
dependencies = [
|
|
239
|
+
"heck",
|
|
240
|
+
"proc-macro2",
|
|
241
|
+
"pyo3-build-config",
|
|
242
|
+
"quote",
|
|
243
|
+
"syn",
|
|
244
|
+
]
|
|
245
|
+
|
|
246
|
+
[[package]]
|
|
247
|
+
name = "quote"
|
|
248
|
+
version = "1.0.45"
|
|
249
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
250
|
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
|
251
|
+
dependencies = [
|
|
252
|
+
"proc-macro2",
|
|
253
|
+
]
|
|
254
|
+
|
|
255
|
+
[[package]]
|
|
256
|
+
name = "rustversion"
|
|
257
|
+
version = "1.0.22"
|
|
258
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
260
|
+
|
|
261
|
+
[[package]]
|
|
262
|
+
name = "shlex"
|
|
263
|
+
version = "2.0.1"
|
|
264
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
265
|
+
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
|
266
|
+
|
|
267
|
+
[[package]]
|
|
268
|
+
name = "slab"
|
|
269
|
+
version = "0.4.12"
|
|
270
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
271
|
+
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
|
272
|
+
|
|
273
|
+
[[package]]
|
|
274
|
+
name = "syn"
|
|
275
|
+
version = "2.0.117"
|
|
276
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
277
|
+
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
|
278
|
+
dependencies = [
|
|
279
|
+
"proc-macro2",
|
|
280
|
+
"quote",
|
|
281
|
+
"unicode-ident",
|
|
282
|
+
]
|
|
283
|
+
|
|
284
|
+
[[package]]
|
|
285
|
+
name = "target-lexicon"
|
|
286
|
+
version = "0.13.5"
|
|
287
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
288
|
+
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
|
289
|
+
|
|
290
|
+
[[package]]
|
|
291
|
+
name = "unicode-ident"
|
|
292
|
+
version = "1.0.24"
|
|
293
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
294
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
295
|
+
|
|
296
|
+
[[package]]
|
|
297
|
+
name = "wasm-bindgen"
|
|
298
|
+
version = "0.2.125"
|
|
299
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
300
|
+
checksum = "8ddb3f79143bced6de84270411622a2699cee572fc0875aeaf1e7867cf9fca1a"
|
|
301
|
+
dependencies = [
|
|
302
|
+
"cfg-if",
|
|
303
|
+
"once_cell",
|
|
304
|
+
"rustversion",
|
|
305
|
+
"wasm-bindgen-macro",
|
|
306
|
+
"wasm-bindgen-shared",
|
|
307
|
+
]
|
|
308
|
+
|
|
309
|
+
[[package]]
|
|
310
|
+
name = "wasm-bindgen-macro"
|
|
311
|
+
version = "0.2.125"
|
|
312
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
313
|
+
checksum = "4e21a184b13fb19e157296e2c46056aec9092264fab83e4ba59e68c61b323c3d"
|
|
314
|
+
dependencies = [
|
|
315
|
+
"quote",
|
|
316
|
+
"wasm-bindgen-macro-support",
|
|
317
|
+
]
|
|
318
|
+
|
|
319
|
+
[[package]]
|
|
320
|
+
name = "wasm-bindgen-macro-support"
|
|
321
|
+
version = "0.2.125"
|
|
322
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
323
|
+
checksum = "fecefd9c35bd935a20fc3fc344b5f29138961e4f47fb03297d88f2587afb5ebd"
|
|
324
|
+
dependencies = [
|
|
325
|
+
"bumpalo",
|
|
326
|
+
"proc-macro2",
|
|
327
|
+
"quote",
|
|
328
|
+
"syn",
|
|
329
|
+
"wasm-bindgen-shared",
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
[[package]]
|
|
333
|
+
name = "wasm-bindgen-shared"
|
|
334
|
+
version = "0.2.125"
|
|
335
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
336
|
+
checksum = "23939e44bb9a5d7576fa2b563dc2e136628f1224e88a8deed09e04858b77871f"
|
|
337
|
+
dependencies = [
|
|
338
|
+
"unicode-ident",
|
|
339
|
+
]
|
|
340
|
+
|
|
341
|
+
[[package]]
|
|
342
|
+
name = "windows-core"
|
|
343
|
+
version = "0.62.2"
|
|
344
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
345
|
+
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
|
346
|
+
dependencies = [
|
|
347
|
+
"windows-implement",
|
|
348
|
+
"windows-interface",
|
|
349
|
+
"windows-link",
|
|
350
|
+
"windows-result",
|
|
351
|
+
"windows-strings",
|
|
352
|
+
]
|
|
353
|
+
|
|
354
|
+
[[package]]
|
|
355
|
+
name = "windows-implement"
|
|
356
|
+
version = "0.60.2"
|
|
357
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
358
|
+
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
|
359
|
+
dependencies = [
|
|
360
|
+
"proc-macro2",
|
|
361
|
+
"quote",
|
|
362
|
+
"syn",
|
|
363
|
+
]
|
|
364
|
+
|
|
365
|
+
[[package]]
|
|
366
|
+
name = "windows-interface"
|
|
367
|
+
version = "0.59.3"
|
|
368
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
369
|
+
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
|
370
|
+
dependencies = [
|
|
371
|
+
"proc-macro2",
|
|
372
|
+
"quote",
|
|
373
|
+
"syn",
|
|
374
|
+
]
|
|
375
|
+
|
|
376
|
+
[[package]]
|
|
377
|
+
name = "windows-link"
|
|
378
|
+
version = "0.2.1"
|
|
379
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
380
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
381
|
+
|
|
382
|
+
[[package]]
|
|
383
|
+
name = "windows-result"
|
|
384
|
+
version = "0.4.1"
|
|
385
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
386
|
+
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
|
387
|
+
dependencies = [
|
|
388
|
+
"windows-link",
|
|
389
|
+
]
|
|
390
|
+
|
|
391
|
+
[[package]]
|
|
392
|
+
name = "windows-strings"
|
|
393
|
+
version = "0.5.1"
|
|
394
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
395
|
+
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
|
396
|
+
dependencies = [
|
|
397
|
+
"windows-link",
|
|
398
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "backtestingfx"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
|
|
7
|
+
[lib]
|
|
8
|
+
name = "_backtestingfx"
|
|
9
|
+
crate-type = ["cdylib", "rlib"]
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
chrono = "0.4"
|
|
13
|
+
pyo3 = { version = "0.28", features = ["extension-module"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Khizar Imran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: backtestingfx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Requires-Dist: pandas
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Summary: FX backtesting library built in Rust
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
10
|
+
Project-URL: Repository, https://github.com/KhizarImran/backtestingfx
|
|
11
|
+
|
|
12
|
+
# backtestingfx
|
|
13
|
+
|
|
14
|
+
A Rust-powered FX backtesting library for Python. Write your strategy in Python, let Rust handle the heavy lifting.
|
|
15
|
+
|
|
16
|
+
Inspired by [backtesting.py](https://kernc.github.io/backtesting.py/) but built specifically for forex — lot sizes, pip-based PnL, stop loss, take profit, and realistic account currency conversion.
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
pip install backtestingfx
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import pandas as pd
|
|
26
|
+
from backtestingfx import Backtest, Strategy
|
|
27
|
+
|
|
28
|
+
class MyCrossStrategy(Strategy):
|
|
29
|
+
def next(self):
|
|
30
|
+
self.close_all()
|
|
31
|
+
self.buy(lot_size=0.1)
|
|
32
|
+
|
|
33
|
+
df = pd.read_csv("EURUSD_1H.csv")
|
|
34
|
+
|
|
35
|
+
bt = Backtest(df, MyCrossStrategy, cash=10000.0, spread=0.0001)
|
|
36
|
+
stats = bt.run()
|
|
37
|
+
|
|
38
|
+
print(stats)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
--- Backtest Results ---
|
|
43
|
+
Initial Cash: 10000.00
|
|
44
|
+
Final Cash: 9823.50
|
|
45
|
+
Total Return: -1.77%
|
|
46
|
+
Trades: 248
|
|
47
|
+
Win Rate: 52.4%
|
|
48
|
+
Avg PnL: -0.71380
|
|
49
|
+
Best Trade: 84.20000
|
|
50
|
+
Worst Trade: -61.30000
|
|
51
|
+
Profit Factor: 0.94
|
|
52
|
+
Max Drawdown: 3.21%
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
pip install backtestingfx
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Requires Python 3.9+.
|
|
62
|
+
|
|
63
|
+
## Writing a Strategy
|
|
64
|
+
|
|
65
|
+
Inherit from `Strategy` and implement `next()`. It is called once per bar.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from backtestingfx import Backtest, Strategy
|
|
69
|
+
|
|
70
|
+
class MyStrategy(Strategy):
|
|
71
|
+
def init(self):
|
|
72
|
+
# called once before the loop starts
|
|
73
|
+
# self._bars contains all Bar objects if you need to pre-compute
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
def next(self):
|
|
77
|
+
# self._bar — current bar (open, high, low, close, volume, timestamp)
|
|
78
|
+
# self._broker — the broker instance (advanced use)
|
|
79
|
+
|
|
80
|
+
if self._bar.close > 1.1000:
|
|
81
|
+
self.buy(lot_size=0.1, stop_loss=1.0950, take_profit=1.1100)
|
|
82
|
+
else:
|
|
83
|
+
self.close_all()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Strategy methods
|
|
87
|
+
|
|
88
|
+
| Method | Description |
|
|
89
|
+
|--------|-------------|
|
|
90
|
+
| `self.buy(lot_size, stop_loss=None, take_profit=None)` | Open a long position |
|
|
91
|
+
| `self.sell(lot_size, stop_loss=None, take_profit=None)` | Open a short position |
|
|
92
|
+
| `self.close_all()` | Close all open positions |
|
|
93
|
+
| `self.close_position(id)` | Close a specific position by ID |
|
|
94
|
+
|
|
95
|
+
### Bar fields
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
self._bar.open
|
|
99
|
+
self._bar.high
|
|
100
|
+
self._bar.low
|
|
101
|
+
self._bar.close
|
|
102
|
+
self._bar.volume
|
|
103
|
+
self._bar.timestamp # unix timestamp (int)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Backtest Parameters
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
Backtest(
|
|
110
|
+
df, # pandas DataFrame with OHLCV columns
|
|
111
|
+
StrategyClass,
|
|
112
|
+
cash=10000.0, # starting account balance in USD
|
|
113
|
+
commission=0.0, # commission per lot (e.g. 7.0 = $7/lot)
|
|
114
|
+
spread=0.0, # spread in price units (e.g. 0.0001 = 1 pip)
|
|
115
|
+
contract_size=100000.0, # standard FX lot size, don't change this
|
|
116
|
+
quote_to_account=1.0, # conversion rate from quote currency to USD
|
|
117
|
+
)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Trading non-USD pairs
|
|
121
|
+
|
|
122
|
+
By default `quote_to_account=1.0` which is correct for USD-quoted pairs (EURUSD, GBPUSD).
|
|
123
|
+
|
|
124
|
+
For other pairs, pass the rate that converts the quote currency to USD:
|
|
125
|
+
|
|
126
|
+
| Pair | quote_to_account |
|
|
127
|
+
|------|-----------------|
|
|
128
|
+
| EURUSD, GBPUSD | `1.0` (default) |
|
|
129
|
+
| EURGBP | GBPUSD rate (e.g. `1.27`) |
|
|
130
|
+
| USDCAD, GBPCAD | CADUSD rate (e.g. `0.74`) |
|
|
131
|
+
| USDJPY | JPYUSD rate (e.g. `0.0067`) |
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
bt = Backtest(df, MyStrategy, cash=10000.0, spread=0.00015, quote_to_account=1.27)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Stats
|
|
138
|
+
|
|
139
|
+
| Field | Description |
|
|
140
|
+
|-------|-------------|
|
|
141
|
+
| `initial_cash` | Starting balance |
|
|
142
|
+
| `final_cash` | Ending balance |
|
|
143
|
+
| `total_return_pct` | Total return as a percentage |
|
|
144
|
+
| `num_trades` | Number of completed trades |
|
|
145
|
+
| `num_wins` | Number of winning trades |
|
|
146
|
+
| `win_rate_pct` | Win rate as a percentage |
|
|
147
|
+
| `avg_pnl` | Average PnL per trade in USD |
|
|
148
|
+
| `best_trade` | Best single trade PnL in USD |
|
|
149
|
+
| `worst_trade` | Worst single trade PnL in USD |
|
|
150
|
+
| `profit_factor` | Gross profit / gross loss |
|
|
151
|
+
| `max_drawdown_pct` | Maximum drawdown as a percentage |
|
|
152
|
+
|
|
153
|
+
## Data Format
|
|
154
|
+
|
|
155
|
+
Pass a pandas DataFrame with these columns:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
open, high, low, close, volume
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The index should be a `DatetimeIndex`, or include a `timestamp` column. Volume is optional (defaults to 0).
|
|
162
|
+
|
|
163
|
+
## Why Rust?
|
|
164
|
+
|
|
165
|
+
The backtesting engine is written in Rust and compiled as a native Python extension via [PyO3](https://pyo3.rs). This means the event loop, broker simulation, and stats computation run at native speed while your strategy stays in plain Python.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
MIT — see [LICENSE](LICENSE)
|
|
170
|
+
|