akquant-lwc 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.
@@ -0,0 +1,16 @@
1
+ # Byte-compiled / build artifacts
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+
10
+ # Test / tooling caches
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .mypy_cache/
14
+
15
+ # Local test artifacts
16
+ tmp_test/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AKQuant developers
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,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: akquant-lwc
3
+ Version: 0.1.0
4
+ Summary: TradingView Lightweight Charts backtest report & trade review plugin for AKQuant (plotly-free)
5
+ Project-URL: Homepage, https://github.com/neoblackxt/akquant-lwc
6
+ Project-URL: Repository, https://github.com/neoblackxt/akquant-lwc
7
+ Project-URL: Issues, https://github.com/neoblackxt/akquant-lwc/issues
8
+ Author-email: Neo Black <neoblackxt@outlook.com>
9
+ License: MIT License
10
+ License-File: LICENSE
11
+ Keywords: akquant,backtest,lightweight-charts,quant,report,tradingview
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: pandas>=2.0.0
19
+ Provides-Extra: dev
20
+ Requires-Dist: akquant>=0.3.16; extra == 'dev'
21
+ Requires-Dist: hatchling>=1.0.0; extra == 'dev'
22
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
23
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # akquant-lwc
27
+
28
+ 基于 **TradingView Lightweight Charts** 的 [AKQuant](https://github.com/akfamily/akquant) 回测报告与交易复盘插件(plotly 替代方案)。
29
+
30
+ 图表库已 vendored 进包内,生成的报告为**单文件 HTML,离线可开**;复盘标的支持**网页内热切换**。
31
+
32
+ ![报告总览](https://raw.githubusercontent.com/neoblackxt/akquant-lwc/main/docs/assets/report-overview.png)
33
+
34
+ ## 为什么不用 plotly
35
+
36
+ 原版 plotly 报告在交易复盘(K线买卖点)场景下的痛点:
37
+
38
+ - 买卖点标记与 K 线图案区分度不够,难以快速定位开平仓;
39
+ - 鼠标左键拖拽平移、滚轮缩放交互不友好;
40
+ - 缩放平移时 y 轴不自动贴合可视区数据,图像经常在垂直方向上偏出合理区域;
41
+ - plotly.js ~3.5MB 且走 CDN,离线/弱网环境报告无法打开。
42
+
43
+ Lightweight Charts 是 TradingView 开源的金融图表库:拖拽平移、以鼠标为中心的滚轮缩放、可视区 y 轴自动缩放均为原生行为,体积仅 ~160KB。
44
+
45
+ ## 安装
46
+
47
+ ```bash
48
+ pip install akquant-lwc
49
+ ```
50
+
51
+ 或从源码安装:
52
+
53
+ ```bash
54
+ pip install git+https://github.com/neoblackxt/akquant-lwc.git
55
+ ```
56
+
57
+ ## 快速开始
58
+
59
+ ```python
60
+ import akquant_lwc # 导入即自动给 BacktestResult 注入 report_lwc / serve_review
61
+ from akquant import run_backtest
62
+
63
+ result = run_backtest(...)
64
+
65
+ # 1) 静态单文件报告(含交易复盘,页面内可热切换标的)
66
+ result.report_lwc(
67
+ market_data={"600000": df1, "600004": df2}, # {symbol: DataFrame}
68
+ filename="akquant_lwc_report.html",
69
+ show=True,
70
+ )
71
+
72
+ # 2) 交互式复盘服务:页面输入任意代码,服务端按需加载
73
+ result.serve_review(
74
+ market_data={"600000": df1},
75
+ data_provider=lambda code: load_df(code), # 可选,解析未预载的代码
76
+ port=8765,
77
+ )
78
+ ```
79
+
80
+ 也可以不依赖注入,直接调用模块级函数(对任何带 `trades_df` /
81
+ `equity_curve` / `metrics` / `trade_metrics` 属性的结果对象都可用):
82
+
83
+ ```python
84
+ from akquant_lwc import plot_report, serve_review
85
+
86
+ plot_report(result, market_data={"600000": df1}, filename="report.html")
87
+ serve_review(result, market_data={"600000": df1})
88
+ ```
89
+
90
+ ## 功能
91
+
92
+ **报告区块(全面对齐原版 plotly 报告)**
93
+
94
+ - 报告概要(回测区间、初始/期末资金、持续天数)
95
+ - 绩效指标卡(收益/回撤/夏普/索提诺/卡玛/波动率/胜率/盈亏比/SQN 等)
96
+ - 净值曲线 + 回撤曲线(时间轴联动)
97
+ - 滚动指标(滚动夏普/波动率)、日收益分布、年度收益、月度收益热力图
98
+ - 基准对比(累计收益/超额收益曲线,年化超额、跟踪误差、信息比率、Beta、Alpha)
99
+ - 交易分析:盈亏分布、盈亏 vs 持仓时长散点(悬停显示完整交易卡片,
100
+ **点击散点直接联动下方 K 线复盘图切换标的**)
101
+ - 风控拒单分析(策略级占比、原因占比、按日趋势、强平审计)
102
+ - 明细表:交易/委托/成交/持仓/风险敞口/归因/容量分析
103
+ - 自定义指标预览区块(`include_indicators=True`)
104
+
105
+ **交易复盘(K线买卖点)**
106
+
107
+ - 代码输入框 + 自动补全,回车即热切换复盘标的,无需重新生成报告
108
+ - B/S 箭头标记开平仓(A股红涨绿跌配色),悬停显示开平仓时间/价格/收益率/净利润
109
+ - 交易明细表点击行自动缩放到该笔交易区间
110
+ - 服务模式支持 `data_provider` 回调,页面可解析任意新代码
111
+
112
+ ![买卖点复盘](https://raw.githubusercontent.com/neoblackxt/akquant-lwc/main/docs/assets/trade-review-markers.png)
113
+
114
+ ![悬停交易详情](https://raw.githubusercontent.com/neoblackxt/akquant-lwc/main/docs/assets/trade-tooltip.png)
115
+
116
+ ## API
117
+
118
+ ### `plot_report(result, market_data=None, title=..., filename=..., symbols=None, plot_symbol=None, show=False, benchmark=None, compact_currency=True, include_indicators=False, curve_freq="D") -> str`
119
+
120
+ 生成静态单文件报告,返回文件绝对路径。
121
+
122
+ - `market_data`: `{symbol: DataFrame}` 字典、单只 DataFrame,或带 symbol 列的长表(OHLCV 列容忍中英文命名)
123
+ - `symbols`: 仅内嵌指定标的子集
124
+ - `benchmark`: 基准收益率序列(`pd.Series`)
125
+
126
+ ### `serve_review(result, market_data=None, data_provider=None, host="127.0.0.1", port=8765, title=..., open_browser=True)`
127
+
128
+ 启动交互式复盘服务(阻塞,Ctrl+C 停止)。
129
+
130
+ - `data_provider`: `(code) -> DataFrame` 回调,解析 `market_data` 中不存在的代码
131
+
132
+ ### `BacktestResult.report_lwc(...) / .serve_review(...)`
133
+
134
+ 导入 `akquant_lwc` 后自动注入,参数同上。未安装 akquant 时注入自动跳过,模块级函数不受影响。
135
+
136
+ ## 开发
137
+
138
+ ```bash
139
+ pip install -e ".[dev]"
140
+ pytest tests/
141
+ ruff check src/
142
+ ```
143
+
144
+ ## License
145
+
146
+ MIT。内嵌的 [Lightweight Charts](https://github.com/tradingview/lightweight-charts)
147
+ 遵循 Apache License 2.0。
@@ -0,0 +1,122 @@
1
+ # akquant-lwc
2
+
3
+ 基于 **TradingView Lightweight Charts** 的 [AKQuant](https://github.com/akfamily/akquant) 回测报告与交易复盘插件(plotly 替代方案)。
4
+
5
+ 图表库已 vendored 进包内,生成的报告为**单文件 HTML,离线可开**;复盘标的支持**网页内热切换**。
6
+
7
+ ![报告总览](https://raw.githubusercontent.com/neoblackxt/akquant-lwc/main/docs/assets/report-overview.png)
8
+
9
+ ## 为什么不用 plotly
10
+
11
+ 原版 plotly 报告在交易复盘(K线买卖点)场景下的痛点:
12
+
13
+ - 买卖点标记与 K 线图案区分度不够,难以快速定位开平仓;
14
+ - 鼠标左键拖拽平移、滚轮缩放交互不友好;
15
+ - 缩放平移时 y 轴不自动贴合可视区数据,图像经常在垂直方向上偏出合理区域;
16
+ - plotly.js ~3.5MB 且走 CDN,离线/弱网环境报告无法打开。
17
+
18
+ Lightweight Charts 是 TradingView 开源的金融图表库:拖拽平移、以鼠标为中心的滚轮缩放、可视区 y 轴自动缩放均为原生行为,体积仅 ~160KB。
19
+
20
+ ## 安装
21
+
22
+ ```bash
23
+ pip install akquant-lwc
24
+ ```
25
+
26
+ 或从源码安装:
27
+
28
+ ```bash
29
+ pip install git+https://github.com/neoblackxt/akquant-lwc.git
30
+ ```
31
+
32
+ ## 快速开始
33
+
34
+ ```python
35
+ import akquant_lwc # 导入即自动给 BacktestResult 注入 report_lwc / serve_review
36
+ from akquant import run_backtest
37
+
38
+ result = run_backtest(...)
39
+
40
+ # 1) 静态单文件报告(含交易复盘,页面内可热切换标的)
41
+ result.report_lwc(
42
+ market_data={"600000": df1, "600004": df2}, # {symbol: DataFrame}
43
+ filename="akquant_lwc_report.html",
44
+ show=True,
45
+ )
46
+
47
+ # 2) 交互式复盘服务:页面输入任意代码,服务端按需加载
48
+ result.serve_review(
49
+ market_data={"600000": df1},
50
+ data_provider=lambda code: load_df(code), # 可选,解析未预载的代码
51
+ port=8765,
52
+ )
53
+ ```
54
+
55
+ 也可以不依赖注入,直接调用模块级函数(对任何带 `trades_df` /
56
+ `equity_curve` / `metrics` / `trade_metrics` 属性的结果对象都可用):
57
+
58
+ ```python
59
+ from akquant_lwc import plot_report, serve_review
60
+
61
+ plot_report(result, market_data={"600000": df1}, filename="report.html")
62
+ serve_review(result, market_data={"600000": df1})
63
+ ```
64
+
65
+ ## 功能
66
+
67
+ **报告区块(全面对齐原版 plotly 报告)**
68
+
69
+ - 报告概要(回测区间、初始/期末资金、持续天数)
70
+ - 绩效指标卡(收益/回撤/夏普/索提诺/卡玛/波动率/胜率/盈亏比/SQN 等)
71
+ - 净值曲线 + 回撤曲线(时间轴联动)
72
+ - 滚动指标(滚动夏普/波动率)、日收益分布、年度收益、月度收益热力图
73
+ - 基准对比(累计收益/超额收益曲线,年化超额、跟踪误差、信息比率、Beta、Alpha)
74
+ - 交易分析:盈亏分布、盈亏 vs 持仓时长散点(悬停显示完整交易卡片,
75
+ **点击散点直接联动下方 K 线复盘图切换标的**)
76
+ - 风控拒单分析(策略级占比、原因占比、按日趋势、强平审计)
77
+ - 明细表:交易/委托/成交/持仓/风险敞口/归因/容量分析
78
+ - 自定义指标预览区块(`include_indicators=True`)
79
+
80
+ **交易复盘(K线买卖点)**
81
+
82
+ - 代码输入框 + 自动补全,回车即热切换复盘标的,无需重新生成报告
83
+ - B/S 箭头标记开平仓(A股红涨绿跌配色),悬停显示开平仓时间/价格/收益率/净利润
84
+ - 交易明细表点击行自动缩放到该笔交易区间
85
+ - 服务模式支持 `data_provider` 回调,页面可解析任意新代码
86
+
87
+ ![买卖点复盘](https://raw.githubusercontent.com/neoblackxt/akquant-lwc/main/docs/assets/trade-review-markers.png)
88
+
89
+ ![悬停交易详情](https://raw.githubusercontent.com/neoblackxt/akquant-lwc/main/docs/assets/trade-tooltip.png)
90
+
91
+ ## API
92
+
93
+ ### `plot_report(result, market_data=None, title=..., filename=..., symbols=None, plot_symbol=None, show=False, benchmark=None, compact_currency=True, include_indicators=False, curve_freq="D") -> str`
94
+
95
+ 生成静态单文件报告,返回文件绝对路径。
96
+
97
+ - `market_data`: `{symbol: DataFrame}` 字典、单只 DataFrame,或带 symbol 列的长表(OHLCV 列容忍中英文命名)
98
+ - `symbols`: 仅内嵌指定标的子集
99
+ - `benchmark`: 基准收益率序列(`pd.Series`)
100
+
101
+ ### `serve_review(result, market_data=None, data_provider=None, host="127.0.0.1", port=8765, title=..., open_browser=True)`
102
+
103
+ 启动交互式复盘服务(阻塞,Ctrl+C 停止)。
104
+
105
+ - `data_provider`: `(code) -> DataFrame` 回调,解析 `market_data` 中不存在的代码
106
+
107
+ ### `BacktestResult.report_lwc(...) / .serve_review(...)`
108
+
109
+ 导入 `akquant_lwc` 后自动注入,参数同上。未安装 akquant 时注入自动跳过,模块级函数不受影响。
110
+
111
+ ## 开发
112
+
113
+ ```bash
114
+ pip install -e ".[dev]"
115
+ pytest tests/
116
+ ruff check src/
117
+ ```
118
+
119
+ ## License
120
+
121
+ MIT。内嵌的 [Lightweight Charts](https://github.com/tradingview/lightweight-charts)
122
+ 遵循 Apache License 2.0。
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "akquant-lwc"
7
+ version = "0.1.0"
8
+ description = "TradingView Lightweight Charts backtest report & trade review plugin for AKQuant (plotly-free)"
9
+ readme = "README.md"
10
+ license = { text = "MIT License" }
11
+ authors = [{ name = "Neo Black", email = "neoblackxt@outlook.com" }]
12
+ keywords = [
13
+ "akquant",
14
+ "lightweight-charts",
15
+ "tradingview",
16
+ "backtest",
17
+ "report",
18
+ "quant",
19
+ ]
20
+ classifiers = [
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "License :: OSI Approved :: MIT License",
26
+ ]
27
+ requires-python = ">=3.10"
28
+ dependencies = ["pandas>=2.0.0"]
29
+
30
+ [project.optional-dependencies]
31
+ dev = ["pytest>=7.0.0", "akquant>=0.3.16", "ruff>=0.1.0", "hatchling>=1.0.0"]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/neoblackxt/akquant-lwc"
35
+ Repository = "https://github.com/neoblackxt/akquant-lwc"
36
+ Issues = "https://github.com/neoblackxt/akquant-lwc/issues"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/akquant_lwc"]
40
+
41
+ [tool.hatch.build.targets.sdist]
42
+ include = ["src/akquant_lwc", "README.md", "LICENSE"]
43
+
44
+ [tool.ruff]
45
+ line-length = 88
46
+ target-version = "py310"
47
+
48
+ [tool.ruff.lint]
49
+ select = ["E", "F", "I", "D"]
50
+ ignore = ["D100", "D104"]
51
+
52
+ [tool.ruff.lint.pydocstyle]
53
+ convention = "pep257"
54
+
55
+ [tool.ruff.lint.per-file-ignores]
56
+ # HTML/JS live inside string constants; long lines are unavoidable there.
57
+ "src/akquant_lwc/_template.py" = ["E501"]
58
+ "src/akquant_lwc/_app_js.py" = ["E501"]
@@ -0,0 +1,39 @@
1
+ """akquant-lwc: TradingView Lightweight Charts reporting plugin for AKQuant.
2
+
3
+ A drop-in, plotly-free replacement of AKQuant's built-in HTML backtest
4
+ report, powered by TradingView Lightweight Charts (vendored, works offline).
5
+
6
+ Usage with AKQuant::
7
+
8
+ import akquant_lwc # patches BacktestResult on import
9
+
10
+ result = run_backtest(...)
11
+ result.report_lwc(market_data={"600000": df}, show=True)
12
+ result.serve_review(market_data={"600000": df}, port=8765)
13
+
14
+ The module-level functions accept any duck-typed result object (anything
15
+ exposing ``trades_df`` / ``equity_curve`` / ``metrics`` / ``trade_metrics``),
16
+ so the plugin also works without the patch or with akquant not installed::
17
+
18
+ from akquant_lwc import plot_report, serve_review
19
+
20
+ plot_report(result, market_data={"600000": df}, filename="report.html")
21
+ serve_review(result, market_data={"600000": df})
22
+ """
23
+
24
+ from ._patch import patch_result_methods
25
+ from .report import build_app_data, plot_report, render_html
26
+ from .server import serve_review
27
+
28
+ __version__ = "0.1.0"
29
+
30
+ __all__ = [
31
+ "build_app_data",
32
+ "patch_result_methods",
33
+ "plot_report",
34
+ "render_html",
35
+ "serve_review",
36
+ ]
37
+
38
+ # Auto-patch BacktestResult on import (idempotent, skipped without akquant).
39
+ patch_result_methods()