crypto-volume-profile 1.0.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.
- crypto_volume_profile-1.0.0/LICENSE +21 -0
- crypto_volume_profile-1.0.0/PKG-INFO +87 -0
- crypto_volume_profile-1.0.0/README.md +62 -0
- crypto_volume_profile-1.0.0/pyproject.toml +42 -0
- crypto_volume_profile-1.0.0/src/crypto_volume_profile/__init__.py +128 -0
- crypto_volume_profile-1.0.0/src/crypto_volume_profile/py.typed +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HoldWins (https://holdwins.com)
|
|
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,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crypto-volume-profile
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Zero-dependency Volume Profile (VPVR) and turnover-decayed cost-basis chip distribution calculator over OHLCV candles (POC, 70% Value Area VAH/VAL, profit ratio).
|
|
5
|
+
Keywords: volume-profile,vpvr,poc,value-area,chip-distribution,crypto,ohlcv,trading-indicators
|
|
6
|
+
Author: HoldWins
|
|
7
|
+
Author-email: HoldWins <ops@holdwins.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Project-URL: Homepage, https://holdwins.com/en/chip-distribution/
|
|
19
|
+
Project-URL: Live Volume Profile Chart (EN), https://holdwins.com/en/chip-distribution/
|
|
20
|
+
Project-URL: 币圈筹码分布在线图表 (中文), https://holdwins.com/chip-distribution/
|
|
21
|
+
Project-URL: Candlestick & Volume Guide, https://holdwins.com/guides/how-to-read-kline/
|
|
22
|
+
Project-URL: Documentation, https://dalangdalang934.github.io/crypto-volume-profile/
|
|
23
|
+
Project-URL: Repository, https://github.com/dalangdalang934/crypto-volume-profile
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# crypto-volume-profile
|
|
27
|
+
|
|
28
|
+
Zero-dependency **Python** & **JavaScript (ESM)** library to compute **Volume Profile (VPVR)**, **Point of Control (POC)**, **70% Value Area (`VAH` / `VAL`)**, and **turnover-decayed Cost-Basis Chip Distribution (筹码分布)** directly from standard OHLCV candlestick arrays.
|
|
29
|
+
|
|
30
|
+
- **Live Interactive Tool (English)**: [Crypto Volume Profile & Cost Distribution (`holdwins.com/en/chip-distribution/`)](https://holdwins.com/en/chip-distribution/)
|
|
31
|
+
- **在线筹码分布图表(中文)**: [币圈筹码分布 (`holdwins.com/chip-distribution/`)](https://holdwins.com/chip-distribution/)
|
|
32
|
+
- **Candlestick Practice**: [Kline Trainer (EN)](https://holdwins.com/en/kline/) · [K 线盘感训练器](https://holdwins.com/kline/)
|
|
33
|
+
- **Reading Guide**: [K 线图与成交密集区怎么看](https://holdwins.com/guides/how-to-read-kline/)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Python Installation & Quick Start
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install crypto-volume-profile
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from crypto_volume_profile import compute_distribution
|
|
45
|
+
|
|
46
|
+
res = compute_distribution(bars, mode="profile", bins=120)
|
|
47
|
+
print(res.poc, res.val, res.vah)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Model Overview
|
|
53
|
+
|
|
54
|
+
1. **Triangular Intrabar Spread**: Each bar's volume is distributed across `[low, high]` using a triangular density peaking at the typical price `(H + L + C) / 3`.
|
|
55
|
+
2. **Volume Profile Mode (`mode: 'profile'`)**: Accumulates raw volume across price bins without decay, then expands outward from the **POC** bin until 70% of total volume is enclosed (`VAL` to `VAH`).
|
|
56
|
+
3. **Chip Distribution Mode (`mode: 'chips'`)**: Applies per-bar turnover decay `min(0.95, V / (avgV × turnoverBars))` before adding new volume, modeling how older positions turn over as fresh volume trades at newer price levels, and computes `profitRatio` (fraction of estimated holdings below current close).
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import { computeDistribution } from './src/index.mjs';
|
|
62
|
+
|
|
63
|
+
const bars = [
|
|
64
|
+
{ o: 95000, h: 96200, l: 94500, c: 95800, v: 12400 },
|
|
65
|
+
{ o: 95800, h: 97400, l: 95500, c: 97100, v: 18900 },
|
|
66
|
+
{ o: 97100, h: 97800, l: 96300, c: 96800, v: 15100 },
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const chips = computeDistribution(bars, { mode: 'chips', bins: 60, turnoverBars: 30 });
|
|
70
|
+
console.log({
|
|
71
|
+
pocPrice: chips.pocPrice,
|
|
72
|
+
valPrice: chips.valPrice,
|
|
73
|
+
vahPrice: chips.vahPrice,
|
|
74
|
+
profitRatioPct: (chips.profitRatio * 100).toFixed(1) + '%',
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Related Open Tools by HoldWins
|
|
79
|
+
|
|
80
|
+
- [Crypto Chip Distribution & Cost-Basis Visualizer](https://holdwins.com/chip-distribution/)
|
|
81
|
+
- [Historical Kline Candlesticks Trainer](https://holdwins.com/en/kline/) · [中文版](https://holdwins.com/kline/)
|
|
82
|
+
- [Perpetual Futures OI & Funding Monitor](https://holdwins.com/en/market-intel/) · [合约异动监测](https://holdwins.com/market-intel/)
|
|
83
|
+
- [Perpetual Futures PnL & Liquidation Calculator](https://holdwins.com/en/futures-calculator/)
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT © [HoldWins](https://holdwins.com)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# crypto-volume-profile
|
|
2
|
+
|
|
3
|
+
Zero-dependency **Python** & **JavaScript (ESM)** library to compute **Volume Profile (VPVR)**, **Point of Control (POC)**, **70% Value Area (`VAH` / `VAL`)**, and **turnover-decayed Cost-Basis Chip Distribution (筹码分布)** directly from standard OHLCV candlestick arrays.
|
|
4
|
+
|
|
5
|
+
- **Live Interactive Tool (English)**: [Crypto Volume Profile & Cost Distribution (`holdwins.com/en/chip-distribution/`)](https://holdwins.com/en/chip-distribution/)
|
|
6
|
+
- **在线筹码分布图表(中文)**: [币圈筹码分布 (`holdwins.com/chip-distribution/`)](https://holdwins.com/chip-distribution/)
|
|
7
|
+
- **Candlestick Practice**: [Kline Trainer (EN)](https://holdwins.com/en/kline/) · [K 线盘感训练器](https://holdwins.com/kline/)
|
|
8
|
+
- **Reading Guide**: [K 线图与成交密集区怎么看](https://holdwins.com/guides/how-to-read-kline/)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Python Installation & Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install crypto-volume-profile
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from crypto_volume_profile import compute_distribution
|
|
20
|
+
|
|
21
|
+
res = compute_distribution(bars, mode="profile", bins=120)
|
|
22
|
+
print(res.poc, res.val, res.vah)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Model Overview
|
|
28
|
+
|
|
29
|
+
1. **Triangular Intrabar Spread**: Each bar's volume is distributed across `[low, high]` using a triangular density peaking at the typical price `(H + L + C) / 3`.
|
|
30
|
+
2. **Volume Profile Mode (`mode: 'profile'`)**: Accumulates raw volume across price bins without decay, then expands outward from the **POC** bin until 70% of total volume is enclosed (`VAL` to `VAH`).
|
|
31
|
+
3. **Chip Distribution Mode (`mode: 'chips'`)**: Applies per-bar turnover decay `min(0.95, V / (avgV × turnoverBars))` before adding new volume, modeling how older positions turn over as fresh volume trades at newer price levels, and computes `profitRatio` (fraction of estimated holdings below current close).
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { computeDistribution } from './src/index.mjs';
|
|
37
|
+
|
|
38
|
+
const bars = [
|
|
39
|
+
{ o: 95000, h: 96200, l: 94500, c: 95800, v: 12400 },
|
|
40
|
+
{ o: 95800, h: 97400, l: 95500, c: 97100, v: 18900 },
|
|
41
|
+
{ o: 97100, h: 97800, l: 96300, c: 96800, v: 15100 },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const chips = computeDistribution(bars, { mode: 'chips', bins: 60, turnoverBars: 30 });
|
|
45
|
+
console.log({
|
|
46
|
+
pocPrice: chips.pocPrice,
|
|
47
|
+
valPrice: chips.valPrice,
|
|
48
|
+
vahPrice: chips.vahPrice,
|
|
49
|
+
profitRatioPct: (chips.profitRatio * 100).toFixed(1) + '%',
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Related Open Tools by HoldWins
|
|
54
|
+
|
|
55
|
+
- [Crypto Chip Distribution & Cost-Basis Visualizer](https://holdwins.com/chip-distribution/)
|
|
56
|
+
- [Historical Kline Candlesticks Trainer](https://holdwins.com/en/kline/) · [中文版](https://holdwins.com/kline/)
|
|
57
|
+
- [Perpetual Futures OI & Funding Monitor](https://holdwins.com/en/market-intel/) · [合约异动监测](https://holdwins.com/market-intel/)
|
|
58
|
+
- [Perpetual Futures PnL & Liquidation Calculator](https://holdwins.com/en/futures-calculator/)
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT © [HoldWins](https://holdwins.com)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "crypto-volume-profile"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Zero-dependency Volume Profile (VPVR) and turnover-decayed cost-basis chip distribution calculator over OHLCV candles (POC, 70% Value Area VAH/VAL, profit ratio)."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "HoldWins", email = "ops@holdwins.com" }
|
|
11
|
+
]
|
|
12
|
+
keywords = [
|
|
13
|
+
"volume-profile",
|
|
14
|
+
"vpvr",
|
|
15
|
+
"poc",
|
|
16
|
+
"value-area",
|
|
17
|
+
"chip-distribution",
|
|
18
|
+
"crypto",
|
|
19
|
+
"ohlcv",
|
|
20
|
+
"trading-indicators"
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 5 - Production/Stable",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
28
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
29
|
+
"Typing :: Typed"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://holdwins.com/en/chip-distribution/"
|
|
34
|
+
"Live Volume Profile Chart (EN)" = "https://holdwins.com/en/chip-distribution/"
|
|
35
|
+
"币圈筹码分布在线图表 (中文)" = "https://holdwins.com/chip-distribution/"
|
|
36
|
+
"Candlestick & Volume Guide" = "https://holdwins.com/guides/how-to-read-kline/"
|
|
37
|
+
Documentation = "https://dalangdalang934.github.io/crypto-volume-profile/"
|
|
38
|
+
Repository = "https://github.com/dalangdalang934/crypto-volume-profile"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["uv_build>=0.9.0,<0.12.0"]
|
|
42
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Zero-dependency Volume Profile (VPVR) and Turnover-Decayed Cost-Basis Chip Distribution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, Mapping, Sequence
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class PriceGrid:
|
|
11
|
+
min_price: float
|
|
12
|
+
max_price: float
|
|
13
|
+
step: float
|
|
14
|
+
bins: int
|
|
15
|
+
|
|
16
|
+
def price_at(self, index: int) -> float:
|
|
17
|
+
return self.min_price + (index + 0.5) * self.step
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class VolumeProfileResult:
|
|
22
|
+
mode: str
|
|
23
|
+
poc: float
|
|
24
|
+
val: float
|
|
25
|
+
vah: float
|
|
26
|
+
average_cost: float
|
|
27
|
+
profit_ratio: float
|
|
28
|
+
bins: list[dict[str, float]]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def build_price_grid(bars: Sequence[Mapping[str, float]], bins: int = 120) -> PriceGrid | None:
|
|
32
|
+
if not bars or bins < 2:
|
|
33
|
+
return None
|
|
34
|
+
low = min(float(b["l"]) for b in bars)
|
|
35
|
+
high = max(float(b["h"]) for b in bars)
|
|
36
|
+
if high <= low:
|
|
37
|
+
high = low * 1.001 if low > 0 else 1.0
|
|
38
|
+
step = (high - low) / bins
|
|
39
|
+
return PriceGrid(min_price=low, max_price=high, step=step, bins=bins)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _triangle_weights(bar: Mapping[str, float], grid: PriceGrid) -> list[float]:
|
|
43
|
+
out = [0.0] * grid.bins
|
|
44
|
+
low, high, close = float(bar["l"]), float(bar["h"]), float(bar["c"])
|
|
45
|
+
peak = (high + low + close) / 3.0
|
|
46
|
+
first = max(0, min(grid.bins - 1, int((low - grid.min_price) // grid.step)))
|
|
47
|
+
last = max(0, min(grid.bins - 1, int((high - grid.min_price) // grid.step)))
|
|
48
|
+
if first == last:
|
|
49
|
+
out[first] = 1.0
|
|
50
|
+
return out
|
|
51
|
+
total = 0.0
|
|
52
|
+
for i in range(first, last + 1):
|
|
53
|
+
px = grid.price_at(i)
|
|
54
|
+
if px <= peak:
|
|
55
|
+
w = 1.0 if peak <= low else (px - low) / (peak - low)
|
|
56
|
+
else:
|
|
57
|
+
w = 1.0 if high <= peak else (high - px) / (high - peak)
|
|
58
|
+
out[i] = max(w, 0.02)
|
|
59
|
+
total += out[i]
|
|
60
|
+
for i in range(first, last + 1):
|
|
61
|
+
out[i] /= total
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def compute_distribution(
|
|
66
|
+
bars: Sequence[Mapping[str, Any]],
|
|
67
|
+
*,
|
|
68
|
+
mode: str = "chips",
|
|
69
|
+
bins: int = 120,
|
|
70
|
+
turnover_bars: int = 30,
|
|
71
|
+
value_area_ratio: float = 0.70,
|
|
72
|
+
) -> VolumeProfileResult | None:
|
|
73
|
+
grid = build_price_grid(bars, bins=bins)
|
|
74
|
+
if grid is None or not bars:
|
|
75
|
+
return None
|
|
76
|
+
avg_vol = sum(float(b["v"]) for b in bars) / len(bars) or 1.0
|
|
77
|
+
dist = [0.0] * bins
|
|
78
|
+
|
|
79
|
+
for bar in bars:
|
|
80
|
+
vol = float(bar["v"])
|
|
81
|
+
weights = _triangle_weights(bar, grid)
|
|
82
|
+
if mode == "chips":
|
|
83
|
+
decay = min(0.95, vol / (avg_vol * max(1, turnover_bars)))
|
|
84
|
+
keep = 1.0 - decay
|
|
85
|
+
for i in range(bins):
|
|
86
|
+
dist[i] = dist[i] * keep + vol * weights[i]
|
|
87
|
+
else:
|
|
88
|
+
for i in range(bins):
|
|
89
|
+
dist[i] += vol * weights[i]
|
|
90
|
+
|
|
91
|
+
total = sum(dist)
|
|
92
|
+
if total <= 0:
|
|
93
|
+
return None
|
|
94
|
+
poc_idx = max(range(bins), key=lambda i: dist[i])
|
|
95
|
+
low_idx = high_idx = poc_idx
|
|
96
|
+
covered = dist[poc_idx]
|
|
97
|
+
target = total * value_area_ratio
|
|
98
|
+
while covered < target and (low_idx > 0 or high_idx < bins - 1):
|
|
99
|
+
down = dist[low_idx - 1] if low_idx > 0 else -1.0
|
|
100
|
+
up = dist[high_idx + 1] if high_idx < bins - 1 else -1.0
|
|
101
|
+
if up >= down:
|
|
102
|
+
high_idx += 1
|
|
103
|
+
covered += dist[high_idx]
|
|
104
|
+
else:
|
|
105
|
+
low_idx -= 1
|
|
106
|
+
covered += dist[low_idx]
|
|
107
|
+
|
|
108
|
+
last_close = float(bars[-1]["c"])
|
|
109
|
+
profit_vol = 0.0
|
|
110
|
+
weighted_px = 0.0
|
|
111
|
+
for i in range(bins):
|
|
112
|
+
px = grid.price_at(i)
|
|
113
|
+
weighted_px += px * dist[i]
|
|
114
|
+
if px <= last_close:
|
|
115
|
+
profit_vol += dist[i]
|
|
116
|
+
|
|
117
|
+
return VolumeProfileResult(
|
|
118
|
+
mode=mode,
|
|
119
|
+
poc=grid.price_at(poc_idx),
|
|
120
|
+
val=grid.price_at(low_idx),
|
|
121
|
+
vah=grid.price_at(high_idx),
|
|
122
|
+
average_cost=weighted_px / total,
|
|
123
|
+
profit_ratio=profit_vol / total,
|
|
124
|
+
bins=[{"price": grid.price_at(i), "volume": dist[i], "share": dist[i] / total} for i in range(bins)],
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
__all__ = ["PriceGrid", "VolumeProfileResult", "build_price_grid", "compute_distribution"]
|
|
File without changes
|