Skip to content

Commit

Permalink
add StrategySmaDualMl for example of multiple data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
msaltnet committed Dec 9, 2023
1 parent b8f1f93 commit 1cb1adb
Show file tree
Hide file tree
Showing 160 changed files with 72,874 additions and 6,515 deletions.
1 change: 1 addition & 0 deletions integration_tests/strategy_bnh/bnh_ITG_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# python -m unittest discover .\integration_tests\strategy_bnh *test.py -v
import json
import unittest
from smtm import Simulator
Expand Down
102 changes: 102 additions & 0 deletions integration_tests/strategy_dml/dml_ITG_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# python -m unittest discover .\integration_tests\strategy_dml *test.py -v
# MUST SET Config.simulation_data_provider_type = "dual" in smtm/config.py
# simulation_data_provider_type = "dual"

import json
import unittest
from smtm import Simulator
from unittest.mock import *

KEY_PERIOD = [
"220701.000000-220701.195900",
"220710.040000-220710.235900",
"220711.200000-220712.155900",
"220712.160000-220713.115900",
"220715.040000-220715.235900",
"220723.120000-220724.075900",
"220724.130000-220725.085900",
"220728.120000-220729.075900",
"220731.000000-220731.195900",
"220811.230000-220812.185900",
"220814.040000-220814.235900",
"220815.000000-220815.195900",
"220826.160000-220827.115900",
"220830.000000-220830.195900",
"221004.080000-221005.035900",
"221010.040000-221010.235900",
"221026.170000-221027.125900",
"221101.000000-221101.195900",
"221114.040000-221114.235900",
"221118.080000-221119.035900",
"230112.160000-230113.115900",
"230113.100000-230114.055900",
"230117.160000-230118.115900",
"230210.000000-230210.195900",
"230227.120000-230228.075900",
"230422.130000-230423.085900",
"230424.080000-230425.035900",
"230425.220000-230426.175900",
"230428.120000-230429.075900",
"230507.160000-230508.115900",
"230511.200000-230512.155900",
"230512.160000-230513.115900",
"230516.000000-230516.195900",
"230527.160000-230528.115900",
"230528.120000-230529.075900",
"230530.040000-230530.235900",
]


class SmlIntegrationTests(unittest.TestCase):
def test_ITG_run_single_simulation(self):
result_list = []
for period in KEY_PERIOD:
request_list = []
simulator = Simulator(
budget=1000000,
interval=0.0001,
strategy="DML",
from_dash_to=period,
currency="BTC",
)
simulator.run_single()

for request in simulator.operator.analyzer.request_list:
request_list.append(
{
"type": request["type"],
"price": request["price"],
"amount": request["amount"],
"date_time": request["date_time"],
}
)
result_list.append(request_list)

# If you want to update the expected result, uncomment the following code.
# with open("./dml_test_result.json", "w") as f:
# json.dump(result_list, f)

with open("./integration_tests/strategy_dml/dml_test_result.json", "r") as f:
expected = json.load(f)

for result_idx, request_list in enumerate(result_list):
for request_idx, requst in enumerate(request_list):
target = expected[result_idx][request_idx]
try:
self.assertEqual(
requst["type"], target["type"], f"{result_idx}-{request_idx}"
)
self.assertEqual(
requst["price"], target["price"], f"{result_idx}-{request_idx}"
)
self.assertEqual(
requst["amount"], target["amount"], f"{result_idx}-{request_idx}"
)
self.assertEqual(
requst["date_time"],
target["date_time"],
f"{result_idx}-{request_idx}",
)
except AssertionError as e:
print(f"[FAIL] result_idx:{result_idx} - request_idx:{request_idx}")
raise e
1 change: 1 addition & 0 deletions integration_tests/strategy_dml/dml_test_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[], [], [], [], [{"type": "buy", "price": 27166000.0, "amount": 0.0367, "date_time": "2022-07-15T13:04:00"}, {"type": "sell", "price": 27090000.0, "amount": 0.0367, "date_time": "2022-07-15T13:40:00"}], [], [{"type": "buy", "price": 30053000.0, "amount": 0.0332, "date_time": "2022-07-25T02:16:00"}, {"type": "sell", "price": 29850000.0, "amount": 0.0332, "date_time": "2022-07-25T02:34:00"}], [{"type": "buy", "price": 30366000.0, "amount": 0.0329, "date_time": "2022-07-28T23:49:00"}, {"type": "sell", "price": 31225000.0, "amount": 0.0329, "date_time": "2022-07-29T03:33:00"}, {"type": "buy", "price": 31285000.0, "amount": 0.0328, "date_time": "2022-07-29T04:26:00"}, {"type": "sell", "price": 31228000.0, "amount": 0.0328, "date_time": "2022-07-29T04:39:00"}, {"type": "buy", "price": 31387000.0, "amount": 0.0326, "date_time": "2022-07-29T07:48:00"}], [], [{"type": "buy", "price": 31927000.0, "amount": 0.0313, "date_time": "2022-08-12T16:13:00"}, {"type": "sell", "price": 31880000.0, "amount": 0.0313, "date_time": "2022-08-12T16:22:00"}], [], [{"type": "buy", "price": 33191000.0, "amount": 0.0301, "date_time": "2022-08-15T14:03:00"}, {"type": "sell", "price": 33081000.0, "amount": 0.0301, "date_time": "2022-08-15T14:17:00"}], [], [{"type": "buy", "price": 27761000.0, "amount": 0.036, "date_time": "2022-08-30T11:57:00"}, {"type": "sell", "price": 27954000.0, "amount": 0.036, "date_time": "2022-08-30T14:49:00"}, {"type": "sell", "price": 27953000.0, "amount": 0.036, "date_time": "2022-08-30T14:50:00"}], [{"type": "buy", "price": 28630000.0, "amount": 0.0349, "date_time": "2022-10-04T18:51:00"}, {"type": "sell", "price": 28620000.0, "amount": 0.0349, "date_time": "2022-10-04T19:10:00"}, {"type": "sell", "price": 28586000.0, "amount": 0.0349, "date_time": "2022-10-04T19:11:00"}, {"type": "buy", "price": 28644000.0, "amount": 0.0348, "date_time": "2022-10-04T21:17:00"}, {"type": "sell", "price": 28577000.0, "amount": 0.0348, "date_time": "2022-10-04T21:24:00"}], [], [], [], [], [{"type": "buy", "price": 23272000.0, "amount": 0.0429, "date_time": "2022-11-18T11:41:00"}, {"type": "sell", "price": 23197000.0, "amount": 0.0429, "date_time": "2022-11-18T12:01:00"}], [{"type": "buy", "price": 22766000.0, "amount": 0.0439, "date_time": "2023-01-13T02:09:00"}, {"type": "sell", "price": 23569000.0, "amount": 0.0439, "date_time": "2023-01-13T06:37:00"}], [{"type": "buy", "price": 24246000.0, "amount": 0.0412, "date_time": "2023-01-14T02:22:00"}, {"type": "sell", "price": 24100000.0, "amount": 0.0412, "date_time": "2023-01-14T02:49:00"}], [{"type": "buy", "price": 26446000.0, "amount": 0.0377, "date_time": "2023-01-17T23:09:00"}, {"type": "sell", "price": 26276000.0, "amount": 0.0377, "date_time": "2023-01-17T23:34:00"}], [], [], [{"type": "buy", "price": 36500000.0, "amount": 0.0273, "date_time": "2023-04-22T23:47:00"}, {"type": "sell", "price": 36850000.0, "amount": 0.0273, "date_time": "2023-04-23T03:13:00"}], [], [{"type": "buy", "price": 36954000.0, "amount": 0.027, "date_time": "2023-04-26T05:00:00"}, {"type": "buy", "price": 37039000.0, "amount": 0.0269, "date_time": "2023-04-26T05:01:00"}, {"type": "sell", "price": 37770000.0, "amount": 0.0269, "date_time": "2023-04-26T08:20:00"}], [], [], [], [], [{"type": "buy", "price": 36507000.0, "amount": 0.0273, "date_time": "2023-05-16T16:07:00"}, {"type": "sell", "price": 36654000.0, "amount": 0.0273, "date_time": "2023-05-16T18:15:00"}], [], [{"type": "buy", "price": 36886000.0, "amount": 0.027, "date_time": "2023-05-29T05:33:00"}], []]
154 changes: 154 additions & 0 deletions integration_tests/strategy_dml/mass_config_dml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"title": "DML_REF_CHECK",
"description": "mass simulation test for reference period",
"budget": 5000000,
"strategy": "DML",
"interval": 1e-06,
"currency": "BTC",
"period_list": [
{
"start": "2022-07-01T00:00:00",
"end": "2022-07-01T19:59:00"
},
{
"start": "2022-07-10T04:00:00",
"end": "2022-07-10T23:59:00"
},
{
"start": "2022-07-11T20:00:00",
"end": "2022-07-12T15:59:00"
},
{
"start": "2022-07-12T16:00:00",
"end": "2022-07-13T11:59:00"
},
{
"start": "2022-07-15T04:00:00",
"end": "2022-07-15T23:59:00"
},
{
"start": "2022-07-23T12:00:00",
"end": "2022-07-24T07:59:00"
},
{
"start": "2022-07-24T13:00:00",
"end": "2022-07-25T08:59:00"
},
{
"start": "2022-07-28T12:00:00",
"end": "2022-07-29T07:59:00"
},
{
"start": "2022-07-31T00:00:00",
"end": "2022-07-31T19:59:00"
},
{
"start": "2022-08-11T23:00:00",
"end": "2022-08-12T18:59:00"
},
{
"start": "2022-08-14T04:00:00",
"end": "2022-08-14T23:59:00"
},
{
"start": "2022-08-15T00:00:00",
"end": "2022-08-15T19:59:00"
},
{
"start": "2022-08-26T16:00:00",
"end": "2022-08-27T11:59:00"
},
{
"start": "2022-08-30T00:00:00",
"end": "2022-08-30T19:59:00"
},
{
"start": "2022-10-04T08:00:00",
"end": "2022-10-05T03:59:00"
},
{
"start": "2022-10-10T04:00:00",
"end": "2022-10-10T23:59:00"
},
{
"start": "2022-10-26T17:00:00",
"end": "2022-10-27T12:59:00"
},
{
"start": "2022-11-01T00:00:00",
"end": "2022-11-01T19:59:00"
},
{
"start": "2022-11-14T04:00:00",
"end": "2022-11-14T23:59:00"
},
{
"start": "2022-11-18T08:00:00",
"end": "2022-11-19T03:59:00"
},
{
"start": "2023-01-12T16:00:00",
"end": "2023-01-13T11:59:00"
},
{
"start": "2023-01-13T10:00:00",
"end": "2023-01-14T05:59:00"
},
{
"start": "2023-01-17T16:00:00",
"end": "2023-01-18T11:59:00"
},
{
"start": "2023-02-10T00:00:00",
"end": "2023-02-10T19:59:00"
},
{
"start": "2023-02-27T12:00:00",
"end": "2023-02-28T07:59:00"
},
{
"start": "2023-04-22T13:00:00",
"end": "2023-04-23T08:59:00"
},
{
"start": "2023-04-24T08:00:00",
"end": "2023-04-25T03:59:00"
},
{
"start": "2023-04-25T22:00:00",
"end": "2023-04-26T17:59:00"
},
{
"start": "2023-04-28T12:00:00",
"end": "2023-04-29T07:59:00"
},
{
"start": "2023-05-07T16:00:00",
"end": "2023-05-08T11:59:00"
},
{
"start": "2023-05-11T20:00:00",
"end": "2023-05-12T15:59:00"
},
{
"start": "2023-05-12T16:00:00",
"end": "2023-05-13T11:59:00"
},
{
"start": "2023-05-16T00:00:00",
"end": "2023-05-16T19:59:00"
},
{
"start": "2023-05-27T16:00:00",
"end": "2023-05-28T11:59:00"
},
{
"start": "2023-05-28T12:00:00",
"end": "2023-05-29T07:59:00"
},
{
"start": "2023-05-30T04:00:00",
"end": "2023-05-30T23:59:00"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions integration_tests/strategy_dml/result/DML_REF_CHECK.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Title: DML_REF_CHECK
Description: mass simulation test for reference period
Strategy: SML-DUAL, Budget: 5000000, Currency: BTC
2022-07-01T00:00:00 ~ 2023-05-30T23:59:00 (36)
수익률 평균: 0.18
수익률 편차: 0.849
수익률 최대: 3.423, 20
수익률 최소: -0.774, 6
수익률 TOP 10 ===============================================
3.423, 20
2.394, 7
1.871, 27
1.318, 34
0.858, 25
0.591, 13
0.302, 32
0.0, 23
0.0, 24
0.0, 26
수익률 WORST 10 ===============================================
-0.774, 6
-0.742, 22
-0.701, 21
-0.586, 14
-0.431, 11
-0.422, 19
-0.379, 4
-0.247, 9
0.0, 35
0.0, 16
순간 최대 수익률 BEST 10 =====================================
4.713, 20
3.681, 7
2.813, 27
1.467, 34
1.398, 25
1.224, 13
0.755, 22
0.637, 32
0.222, 4
0.025, 11
순간 최저 수익률 WORST 10 =====================================
-0.774, 6
-0.742, 22
-0.701, 21
-0.586, 14
-0.431, 11
-0.422, 19
-0.379, 4
-0.247, 9
-0.193, 34
-0.182, 7
순번, 인덱스, 구간 수익률, 최대 수익률, 최저 수익률 ===
1, 20, 3.423, 4.713, -0.041
2, 7, 2.394, 3.681, -0.182
3, 27, 1.871, 2.813, 0.0
4, 34, 1.318, 1.467, -0.193
5, 25, 0.858, 1.398, -0.05
6, 13, 0.591, 1.224, -0.018
7, 32, 0.302, 0.637, -0.069
8, 23, 0.0, 0.0, 0.0
9, 24, 0.0, 0.0, 0.0
10, 26, 0.0, 0.0, 0.0
11, 0, 0.0, 0.0, 0.0
12, 28, 0.0, 0.0, 0.0
13, 1, 0.0, 0.0, 0.0
14, 30, 0.0, 0.0, 0.0
15, 31, 0.0, 0.0, 0.0
16, 33, 0.0, 0.0, 0.0
17, 29, 0.0, 0.0, 0.0
18, 18, 0.0, 0.0, 0.0
19, 17, 0.0, 0.0, 0.0
20, 12, 0.0, 0.0, 0.0
21, 2, 0.0, 0.0, 0.0
22, 3, 0.0, 0.0, 0.0
23, 5, 0.0, 0.0, 0.0
24, 8, 0.0, 0.0, 0.0
25, 10, 0.0, 0.0, 0.0
26, 15, 0.0, 0.0, 0.0
27, 16, 0.0, 0.0, 0.0
28, 35, 0.0, 0.0, 0.0
29, 9, -0.247, 0.0, -0.247
30, 4, -0.379, 0.222, -0.379
31, 19, -0.422, 0.0, -0.422
32, 11, -0.431, 0.025, -0.431
33, 14, -0.586, 0.0, -0.586
34, 21, -0.701, 0.0, -0.701
35, 22, -0.742, 0.755, -0.742
36, 6, -0.774, 0.0, -0.774
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1cb1adb

Please sign in to comment.