发明者本地回测平台python版[博]

原创博客地址:发明者本地回测平台python版[博]

网页版策略开发问题
1,没有自动提示
2,tab自动4个空格,问题是编译器无法识别4个空格,只能再把自动填充4空格改成tab
另一方面,官方提供安装指引过于简陋,连基本的python版本都没有说明。
官方python编译器版本为3.6.9

 

1
2
import platform # 版本信息 
Log(platform.python_version())

本文基于ubuntu18

建立conda环境

 

1
2
conda create -n fmz python=3.7
conda activate fmz

安装pip

 

1
2
3
sudo apt-get install python3-pip
python -m pip install --upgrade pip  
pip install https://github.com/fmzquant/backtest_python/archive/master.zip

运行demo程序

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
vim test01.py
以下内容粘贴进去

# !/usr/local/bin/python
# -*- coding: UTF-8 -*-

'''backtest
start: 2018-02-19 00:00:00
end: 2018-03-22 12:00:00
period: 15m
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD","balance":10000,"stocks":3}]
'''

from fmz import *
import math
import talib

task = VCtx(__doc__) # initialize backtest engine from __doc__

# ------------------------------ 策略部分开始 --------------------------
print (exchange.GetAccount())     # 调用一些接口,打印其返回值。
print (exchange.GetTicker())

def adjustFloat(v):             # 策略中自定义的函数
    v = math.floor(v * 1000)
    return v / 1000

def onTick():
    Log("onTick")
    # 具体的策略代码


def main():
    InitAccount = GetAccount()
    while True:
        onTick()
        Sleep(1000)

# ------------------------------ 策略部分结束 --------------------------

try:
    main()                     # 回测结束时会 raise EOFError() 抛出异常,来停止回测的循环。所以要对这个异常处理,在检测到抛出的异常后调用 task.Join() 打印回测结果。
except:
    print (task.Join())

执行回测

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
python test01.py

回测结果
{
	'Balance': 10000.0,
	'FrozenBalance': 0.0,
	'Stocks': 3.0,
	'FrozenStocks': 0.0
} {
	'Time': 1518969600000,
	'High': 10632.001,
	'Low': 10631.999,
	'Sell': 10632.001,
	'Buy': 10631.999,
	'Last': 10632.0,
	'Volume': 0.0,
	'OpenInterest': 0.0
}

b 字符串,转为json后
{
	"Chart": {
		"Cfg": "",
		"Datas": []
	},
	"Elapsed": 534000000,
	"Finished": true,
	"Indicators": {},
	"LoadBytes": 522026,
	"LoadElapsed": 490000000,
	"LogsCount": 0,
	"Profit": 0.0,
	"ProfitLogs": [],
	"Progress": 100.0,
	"RuntimeLogs": [],
	"Snapshorts": [
		[1518883200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": null,
			"TradeStatus": {}
		}]],
		[1518969600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": null,
			"TradeStatus": {}
		}]],
		[1519056000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 11168.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519142400000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 11508.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519228800000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10558.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519315200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9995.12
				}
			},
			"TradeStatus": {}
		}]],
		[1519401600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10300.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519488000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9730.1
				}
			},
			"TradeStatus": {}
		}]],
		[1519574400000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9399.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519660800000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10259.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519747200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10578.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519833600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10506.0
				}
			},
			"TradeStatus": {}
		}]],
		[1519920000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10715.9
				}
			},
			"TradeStatus": {}
		}]],
		[1520006400000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10840.0
				}
			},
			"TradeStatus": {}
		}]],
		[1520092800000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 11470.0
				}
			},
			"TradeStatus": {}
		}]],
		[1520179200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 11141.0
				}
			},
			"TradeStatus": {}
		}]],
		[1520265600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 11508.0
				}
			},
			"TradeStatus": {}
		}]],
		[1520352000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10972.7
				}
			},
			"TradeStatus": {}
		}]],
		[1520438400000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 10661.0
				}
			},
			"TradeStatus": {}
		}]],
		[1520524800000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9944.1
				}
			},
			"TradeStatus": {}
		}]],
		[1520611200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9944.1
				}
			},
			"TradeStatus": {}
		}]],
		[1520697600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9363.9
				}
			},
			"TradeStatus": {}
		}]],
		[1520784000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9200.0
				}
			},
			"TradeStatus": {}
		}]],
		[1520870400000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9594.1
				}
			},
			"TradeStatus": {}
		}]],
		[1520956800000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9089.5
				}
			},
			"TradeStatus": {}
		}]],
		[1521043200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 8719.6
				}
			},
			"TradeStatus": {}
		}]],
		[1521129600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 8092.9
				}
			},
			"TradeStatus": {}
		}]],
		[1521216000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 8551.3
				}
			},
			"TradeStatus": {}
		}]],
		[1521302400000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 7888.1
				}
			},
			"TradeStatus": {}
		}]],
		[1521388800000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 7378.5
				}
			},
			"TradeStatus": {}
		}]],
		[1521475200000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 8559.0
				}
			},
			"TradeStatus": {}
		}]],
		[1521561600000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 8517.0
				}
			},
			"TradeStatus": {}
		}]],
		[1521648000000, [{
			"Balance": 10000.0,
			"BaseCurrency": "BTC",
			"Commission": 0.0,
			"FrozenBalance": 0.0,
			"FrozenStocks": 0.0,
			"Id": "Bitfinex",
			"QuoteCurrency": "USD",
			"Stocks": 3.0,
			"Symbols": {
				"BTC_USD_Bitfinex": {
					"Last": 9024.6
				}
			},
			"TradeStatus": {}
		}]]
	],
	"Status": "",
	"Task": {
		"Args": null,
		"Exchanges": [{
			"Balance": 10000,
			"BaseCurrency": "BTC",
			"BasePeriod": 300000,
			"BasePrecision": 4,
			"DepthAmount": 20,
			"DepthDeep": 5,
			"FaultTolerant": 0,
			"FeeDenominator": 5,
			"FeeMaker": 200,
			"FeeMin": 0,
			"FeeTaker": 200,
			"Id": "Bitfinex",
			"Label": "Bitfinex",
			"PriceTick": 0.001,
			"QuoteCurrency": "USD",
			"QuotePrecision": 4,
			"SlipPoint": 0,
			"Stocks": 3
		}],
		"Options": {
			"DataServer": "q.fmz.com",
			"MaxChartLogs": 800,
			"MaxProfitLogs": 800,
			"MaxRuntimeLogs": 800,
			"NetDelay": 200,
			"Period": 900000,
			"RetFlags": 445,
			"SnapshortPeriod": 86400000,
			"TimeBegin": 1518969600,
			"TimeEnd": 1521691200,
			"UpdatePeriod": 5000
		}
	},
	"TaskStatus": 1,
	"Time": 1521691200000
}

发明者本地回测平台python版[博]_第1张图片

这个回测结果,谁晓得啥意思,我是没看懂,没有各字段说明文档,有些能猜到,还有些就不晓得了。
而且作为回测,最基本的净值图也没有,这让人情何以堪啊。完全无法晓得策略表现。

放弃

综上所述,放弃使用fmz本地回测功能。但是fmz的线上编码难以调试,最佳方案是用其他工具进行idea-策略开发,然后迁移到fmz上回测+实盘。

参考:https://www.fmz.com/bbs-topic/4183
https://github.com/fmzquant/backtest_python/blob/master/README.md  

 

你可能感兴趣的:(量化_数字货币)