PyAlgoEngine 0.5.3__tar.gz → 0.5.4__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.
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/LICENSE +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/PKG-INFO +27 -20
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/PyAlgoEngine.egg-info/PKG-INFO +27 -20
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/PyAlgoEngine.egg-info/SOURCES.txt +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/PyAlgoEngine.egg-info/dependency_links.txt +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/PyAlgoEngine.egg-info/requires.txt +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/PyAlgoEngine.egg-info/top_level.txt +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/README.md +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/__init__.py +1 -1
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/backtest/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/backtest/doc_server.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/backtest/tester.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/backtest/web_app.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/bokeh_server.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/demo/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/apps/demo/test.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/backtest/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/backtest/__main__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/backtest/metrics.py +29 -29
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/backtest/replay.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/backtest/sim_match.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/console_utils.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/finance_decimal.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/market_utils.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/technical_analysis.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/telemetrics.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/base/trade_utils.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/engine/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/engine/algo_engine.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/engine/event_engine.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/engine/market_engine.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/engine/trade_engine.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/monitor/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/monitor/advanced_data_interface.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/profile/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/profile/cn.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/strategy/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/strategy/strategy_engine.py +1 -1
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/utils/__init__.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/utils/commit_regularizer.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/algo_engine/utils/data_utils.py +0 -0
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/setup.cfg +4 -4
- {PyAlgoEngine-0.5.3 → pyalgoengine-0.5.4}/setup.py +0 -0
|
File without changes
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: PyAlgoEngine
|
|
3
|
-
Version: 0.5.
|
|
4
|
-
Summary: Basic algo engine
|
|
5
|
-
Home-page: https://github.com/BolunHan/PyAlgoEngine
|
|
6
|
-
Author: Bolun.Han
|
|
7
|
-
Author-email: Bolun.Han@outlook.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: Operating System :: OS Independent
|
|
14
|
-
Requires-Python: >=3.1
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyAlgoEngine
|
|
3
|
+
Version: 0.5.4
|
|
4
|
+
Summary: Basic algo engine
|
|
5
|
+
Home-page: https://github.com/BolunHan/PyAlgoEngine
|
|
6
|
+
Author: Bolun.Han
|
|
7
|
+
Author-email: Bolun.Han@outlook.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.1
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: exchange_calendars
|
|
20
|
+
Requires-Dist: PyEventEngine
|
|
21
|
+
Provides-Extra: webapps
|
|
22
|
+
Requires-Dist: flask; extra == "webapps"
|
|
23
|
+
Requires-Dist: waitress; extra == "webapps"
|
|
24
|
+
Requires-Dist: bokeh; extra == "webapps"
|
|
25
|
+
|
|
26
|
+
# PyAlgoEngine
|
|
27
|
+
python algo trading engine
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: PyAlgoEngine
|
|
3
|
-
Version: 0.5.
|
|
4
|
-
Summary: Basic algo engine
|
|
5
|
-
Home-page: https://github.com/BolunHan/PyAlgoEngine
|
|
6
|
-
Author: Bolun.Han
|
|
7
|
-
Author-email: Bolun.Han@outlook.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: Operating System :: OS Independent
|
|
14
|
-
Requires-Python: >=3.1
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyAlgoEngine
|
|
3
|
+
Version: 0.5.4
|
|
4
|
+
Summary: Basic algo engine
|
|
5
|
+
Home-page: https://github.com/BolunHan/PyAlgoEngine
|
|
6
|
+
Author: Bolun.Han
|
|
7
|
+
Author-email: Bolun.Han@outlook.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.1
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: exchange_calendars
|
|
20
|
+
Requires-Dist: PyEventEngine
|
|
21
|
+
Provides-Extra: webapps
|
|
22
|
+
Requires-Dist: flask; extra == "webapps"
|
|
23
|
+
Requires-Dist: waitress; extra == "webapps"
|
|
24
|
+
Requires-Dist: bokeh; extra == "webapps"
|
|
25
|
+
|
|
26
|
+
# PyAlgoEngine
|
|
27
|
+
python algo trading engine
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -13,16 +13,16 @@ class TradeMetrics(object):
|
|
|
13
13
|
self.total_pnl = 0.
|
|
14
14
|
self.total_cash_flow = 0.
|
|
15
15
|
|
|
16
|
-
self.
|
|
17
|
-
self.
|
|
18
|
-
self.
|
|
19
|
-
self.
|
|
16
|
+
self.current_pnl = 0.
|
|
17
|
+
self.current_cash_flow = 0.
|
|
18
|
+
self.current_trade_batch = {'cash_flow': 0., 'pnl': 0., 'turnover': 0., 'trades': []}
|
|
19
|
+
self.market_price = None
|
|
20
20
|
|
|
21
21
|
def update(self, market_price: float):
|
|
22
|
-
self.
|
|
22
|
+
self.market_price = market_price
|
|
23
23
|
self.total_pnl = self.exposure * market_price + self.total_cash_flow
|
|
24
|
-
self.
|
|
25
|
-
self.
|
|
24
|
+
self.current_pnl = self.exposure * market_price + self.current_cash_flow
|
|
25
|
+
self.current_trade_batch['pnl'] = self.exposure * market_price + self.current_trade_batch['cash_flow']
|
|
26
26
|
|
|
27
27
|
def add_trades(self, side: int, price: float, timestamp: float, volume: float = None, trade_id: int | str = None):
|
|
28
28
|
assert side in {1, -1}, f"trade side must in {1, -1}, got {side}."
|
|
@@ -50,9 +50,9 @@ class TradeMetrics(object):
|
|
|
50
50
|
self.exposure += volume * side
|
|
51
51
|
self.total_cash_flow -= volume * side * price
|
|
52
52
|
self.total_pnl = self.exposure * price + self.total_cash_flow
|
|
53
|
-
self.
|
|
54
|
-
self.
|
|
55
|
-
self.
|
|
53
|
+
self.current_cash_flow -= volume * side * price
|
|
54
|
+
self.current_pnl = self.exposure * price + self.current_cash_flow
|
|
55
|
+
self.market_price = price
|
|
56
56
|
|
|
57
57
|
self.trades[trade_id] = trade_log = dict(
|
|
58
58
|
side=side,
|
|
@@ -60,22 +60,22 @@ class TradeMetrics(object):
|
|
|
60
60
|
timestamp=timestamp,
|
|
61
61
|
price=price,
|
|
62
62
|
exposure=self.exposure,
|
|
63
|
-
cash_flow=self.
|
|
64
|
-
pnl=self.
|
|
63
|
+
cash_flow=self.current_cash_flow,
|
|
64
|
+
pnl=self.current_pnl
|
|
65
65
|
)
|
|
66
66
|
|
|
67
|
-
if 'init_side' not in self.
|
|
68
|
-
self.
|
|
67
|
+
if 'init_side' not in self.current_trade_batch:
|
|
68
|
+
self.current_trade_batch['init_side'] = side
|
|
69
69
|
|
|
70
|
-
self.
|
|
71
|
-
self.
|
|
72
|
-
self.
|
|
73
|
-
self.
|
|
70
|
+
self.current_trade_batch['cash_flow'] -= volume * side * price
|
|
71
|
+
self.current_trade_batch['pnl'] = self.exposure * price + self.current_trade_batch['cash_flow']
|
|
72
|
+
self.current_trade_batch['turnover'] += abs(volume) * price
|
|
73
|
+
self.current_trade_batch['trades'].append(trade_log)
|
|
74
74
|
|
|
75
75
|
if not self.exposure:
|
|
76
|
-
self.trade_batch.append(self.
|
|
77
|
-
self.
|
|
78
|
-
self.
|
|
76
|
+
self.trade_batch.append(self.current_trade_batch)
|
|
77
|
+
self.current_trade_batch = {'cash_flow': 0., 'pnl': 0., 'turnover': 0., 'trades': []}
|
|
78
|
+
self.current_pnl = self.current_cash_flow = 0.
|
|
79
79
|
|
|
80
80
|
def add_trades_batch(self, trade_logs: pd.DataFrame):
|
|
81
81
|
for timestamp, row in trade_logs.iterrows(): # type: float, dict
|
|
@@ -92,10 +92,10 @@ class TradeMetrics(object):
|
|
|
92
92
|
self.total_pnl = 0.
|
|
93
93
|
self.total_cash_flow = 0.
|
|
94
94
|
|
|
95
|
-
self.
|
|
96
|
-
self.
|
|
97
|
-
self.
|
|
98
|
-
self.
|
|
95
|
+
self.current_pnl = 0.
|
|
96
|
+
self.current_cash_flow = 0.
|
|
97
|
+
self.current_trade_batch = {'cash_flow': 0., 'pnl': 0., 'turnover': 0., 'trades': []}
|
|
98
|
+
self.market_price = None
|
|
99
99
|
|
|
100
100
|
@property
|
|
101
101
|
def summary(self):
|
|
@@ -121,11 +121,11 @@ class TradeMetrics(object):
|
|
|
121
121
|
info_dict['turnover'] += trade_batch['turnover']
|
|
122
122
|
|
|
123
123
|
info_dict['win_rate'] = info_dict['win_count'] / info_dict['trade_count'] if info_dict['trade_count'] else 0.
|
|
124
|
-
info_dict['average_gain'] = info_dict['total_gain'] / info_dict['win_count'] / self.
|
|
125
|
-
info_dict['average_loss'] = info_dict['total_loss'] / info_dict['lose_count'] / self.
|
|
124
|
+
info_dict['average_gain'] = info_dict['total_gain'] / info_dict['win_count'] / self.market_price if info_dict['win_count'] else 0.
|
|
125
|
+
info_dict['average_loss'] = info_dict['total_loss'] / info_dict['lose_count'] / self.market_price if info_dict['lose_count'] else 0.
|
|
126
126
|
info_dict['gain_loss_ratio'] = -info_dict['average_gain'] / info_dict['average_loss'] if info_dict['average_loss'] else 1.
|
|
127
|
-
info_dict['long_avg_pnl'] = np.average([_['pnl'] for _ in long_trades]) / self.
|
|
128
|
-
info_dict['short_avg_pnl'] = np.average([_['pnl'] for _ in short_trades]) / self.
|
|
127
|
+
info_dict['long_avg_pnl'] = np.average([_['pnl'] for _ in long_trades]) / self.market_price if (long_trades := [_ for _ in self.trade_batch if _['init_side'] == 1]) else np.nan
|
|
128
|
+
info_dict['short_avg_pnl'] = np.average([_['pnl'] for _ in short_trades]) / self.market_price if (short_trades := [_ for _ in self.trade_batch if _['init_side'] == -1]) else np.nan
|
|
129
129
|
info_dict['ttl_pnl.no_leverage'] = np.sum([trade_batch['pnl'] for trade_batch in self.trade_batch])
|
|
130
130
|
info_dict['net_pnl.optimistic'] = info_dict['ttl_pnl.no_leverage'] - (0.00034 + 0.000023) / 2 * info_dict['turnover']
|
|
131
131
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[egg_info]
|
|
2
|
-
tag_build =
|
|
3
|
-
tag_date = 0
|
|
4
|
-
|
|
1
|
+
[egg_info]
|
|
2
|
+
tag_build =
|
|
3
|
+
tag_date = 0
|
|
4
|
+
|
|
File without changes
|