chartpipe 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.
- chartpipe-0.1.0/PKG-INFO +376 -0
- chartpipe-0.1.0/README.md +343 -0
- chartpipe-0.1.0/setup.cfg +4 -0
- chartpipe-0.1.0/setup.py +41 -0
- chartpipe-0.1.0/src/chartpipe/__init__.py +6 -0
- chartpipe-0.1.0/src/chartpipe/__main__.py +7 -0
- chartpipe-0.1.0/src/chartpipe/cli.py +83 -0
- chartpipe-0.1.0/src/chartpipe/cli_exit.py +15 -0
- chartpipe-0.1.0/src/chartpipe/commands/__init__.py +1 -0
- chartpipe-0.1.0/src/chartpipe/commands/backtest.py +154 -0
- chartpipe-0.1.0/src/chartpipe/commands/indicators.py +214 -0
- chartpipe-0.1.0/src/chartpipe/commands/ohlcv.py +155 -0
- chartpipe-0.1.0/src/chartpipe/commands/stats.py +169 -0
- chartpipe-0.1.0/src/chartpipe/core/__init__.py +6 -0
- chartpipe-0.1.0/src/chartpipe/core/backtest_input.py +185 -0
- chartpipe-0.1.0/src/chartpipe/core/charts.py +591 -0
- chartpipe-0.1.0/src/chartpipe/core/input_data.py +151 -0
- chartpipe-0.1.0/src/chartpipe/core/pipeline_json.py +79 -0
- chartpipe-0.1.0/src/chartpipe/core/styles.py +65 -0
- chartpipe-0.1.0/src/chartpipe.egg-info/PKG-INFO +376 -0
- chartpipe-0.1.0/src/chartpipe.egg-info/SOURCES.txt +27 -0
- chartpipe-0.1.0/src/chartpipe.egg-info/dependency_links.txt +1 -0
- chartpipe-0.1.0/src/chartpipe.egg-info/entry_points.txt +2 -0
- chartpipe-0.1.0/src/chartpipe.egg-info/requires.txt +6 -0
- chartpipe-0.1.0/src/chartpipe.egg-info/top_level.txt +1 -0
- chartpipe-0.1.0/tests/test_backtest_input.py +91 -0
- chartpipe-0.1.0/tests/test_cli_options.py +17 -0
- chartpipe-0.1.0/tests/test_input_data_wrappers.py +32 -0
- chartpipe-0.1.0/tests/test_pipeline_json.py +33 -0
chartpipe-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chartpipe
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Chart visualization toolkit for quantitative trading analysis
|
|
5
|
+
Home-page: https://github.com/yourusername/chartpipe
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: your.email@example.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: pandas>=2.0.0
|
|
19
|
+
Requires-Dist: numpy>=1.24.0
|
|
20
|
+
Requires-Dist: click>=8.0.0
|
|
21
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
22
|
+
Requires-Dist: mplfinance>=0.12.10b0
|
|
23
|
+
Requires-Dist: seaborn>=0.12.0
|
|
24
|
+
Dynamic: author
|
|
25
|
+
Dynamic: author-email
|
|
26
|
+
Dynamic: classifier
|
|
27
|
+
Dynamic: description
|
|
28
|
+
Dynamic: description-content-type
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: requires-dist
|
|
31
|
+
Dynamic: requires-python
|
|
32
|
+
Dynamic: summary
|
|
33
|
+
|
|
34
|
+
# ChartPipe
|
|
35
|
+
|
|
36
|
+
A professional chart visualization toolkit for quantitative trading analysis. Seamlessly integrates with seamflux CLI and quantpipe via Unix pipes.
|
|
37
|
+
|
|
38
|
+
**Pipeline contract** (CLI flags, JSON envelope, exit codes, `runs/<runId>/` layout) is defined in the repo root [`rule.md`](../rule.md). ChartPipe uses **`schemaVersion`: 1** on stdout when `--json` is set.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- ๐ฏ๏ธ **OHLCV Candlestick Charts** - Professional candlestick charts with moving average support
|
|
43
|
+
- ๐ **Backtest Visualization** - Equity curves, drawdown analysis, and trade markers
|
|
44
|
+
- ๐ **Technical Indicators** - RSI, MACD, Bollinger Bands, and more
|
|
45
|
+
- ๐ **Statistical Analysis** - Returns distribution, monthly heatmaps, and data distribution
|
|
46
|
+
- ๐จ **Dual Themes** - Dark and light themes for different environments
|
|
47
|
+
- ๐ **Pipeline-Friendly** - JSON output support for seamless integration with seamflux/quantpipe
|
|
48
|
+
- ๐ **Auto-Format Detection** - Automatically recognizes Binance, Polymarket, Uniswap, and generic OHLCV formats
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### From Source (Development)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cd chartpipe
|
|
56
|
+
pip install -e .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Using requirements.txt
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install -r requirements.txt
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
### Integration with seamflux
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Fetch data from Binance and generate candlestick chart
|
|
71
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=1h -p limit=200 | chartpipe ohlcv --stdin
|
|
72
|
+
|
|
73
|
+
# Generate RSI indicator chart
|
|
74
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=1h -p limit=200 | chartpipe indicators --indicator rsi --stdin
|
|
75
|
+
|
|
76
|
+
# Generate returns distribution chart
|
|
77
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=1h -p limit=500 | chartpipe stats --type returns --stdin
|
|
78
|
+
|
|
79
|
+
# JSON output (for pipeline chaining) โ one line on stdout; parse with jq
|
|
80
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=1h -p limit=200 | chartpipe ohlcv --stdin --json
|
|
81
|
+
# Chart path: .artifacts.chart (relative to cwd unless absolute)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Integration with quantpipe
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Recommended (rule.md): quantpipe writes equity.csv / trades.csv under runs/<id>/
|
|
88
|
+
quantpipe backtest --data btc_history.json --strategy ma_cross --run-dir runs/my-run --json
|
|
89
|
+
chartpipe backtest --run-dir runs/my-run --json
|
|
90
|
+
|
|
91
|
+
# Stdin: pipe quantpipe JSON line that includes artifacts.equity (paths from --run-dir/--run-id)
|
|
92
|
+
quantpipe backtest --data btc_history.json --strategy ma_cross --run-dir runs/my-run --json | chartpipe backtest --stdin --json
|
|
93
|
+
|
|
94
|
+
# View candlestick chart from Binance OHLCV (pipe-friendly raw payload)
|
|
95
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=1h -p limit=200 | chartpipe ohlcv --stdin
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Note:** quantpipe `--json` without `--run-dir` / `--run-id` does not emit `equity.csv`; chartpipe `backtest --stdin` then fails with a clear errorโuse `--run-dir` on quantpipe or `chartpipe backtest --run-dir`.
|
|
99
|
+
|
|
100
|
+
## Command Reference
|
|
101
|
+
|
|
102
|
+
### Global Options
|
|
103
|
+
|
|
104
|
+
| Option | Description |
|
|
105
|
+
|--------|-------------|
|
|
106
|
+
| `--version` | Show version and exit |
|
|
107
|
+
| `--json` | Machine-readable JSON envelope on stdout (single line; debug on stderr) |
|
|
108
|
+
| `-o, --output-dir PATH` | Directory to save generated charts (default: `./charts`). Works as `chartpipe -o DIR <cmd>` or `chartpipe <cmd> -o DIR`. |
|
|
109
|
+
| `-v, --verbose` | Debug logs on stderr |
|
|
110
|
+
| `--dry-run` | Validate input only; do not write chart files |
|
|
111
|
+
|
|
112
|
+
### Exit codes
|
|
113
|
+
|
|
114
|
+
| Code | Meaning |
|
|
115
|
+
|------|---------|
|
|
116
|
+
| 0 | Success |
|
|
117
|
+
| 1 | General failure (I/O, plot error, bad args) |
|
|
118
|
+
| 2 | Input / schema mismatch |
|
|
119
|
+
| 3 | Missing optional dependency (e.g. mplfinance for OHLCV) |
|
|
120
|
+
|
|
121
|
+
Run `chartpipe --help` for the full epilog.
|
|
122
|
+
|
|
123
|
+
### Headless rendering
|
|
124
|
+
|
|
125
|
+
[charts.py](src/chartpipe/core/charts.py) sets `matplotlib` to the **Agg** backend by default so charts run without a display. You may still set `MPLBACKEND=Agg` in the environment if needed.
|
|
126
|
+
|
|
127
|
+
### `chartpipe ohlcv` - Candlestick Charts
|
|
128
|
+
|
|
129
|
+
Generate professional OHLCV candlestick charts with optional moving averages and volume.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# From file
|
|
133
|
+
chartpipe ohlcv --data ohlcv.json --title "BTC/USDT" --ma 20 --ma 50 --volume
|
|
134
|
+
|
|
135
|
+
# From stdin with dark theme
|
|
136
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=ETH/USDT -p interval=1h -p limit=200 | chartpipe ohlcv --stdin --theme dark
|
|
137
|
+
|
|
138
|
+
# With multiple moving averages
|
|
139
|
+
chartpipe ohlcv --data btc.json --ma 10 --ma 30 --ma 100 --volume
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Options:**
|
|
143
|
+
|
|
144
|
+
| Option | Description |
|
|
145
|
+
|--------|-------------|
|
|
146
|
+
| `--data PATH` | Path to OHLCV data file (JSON) |
|
|
147
|
+
| `--input PATH` | Alias for `--data` |
|
|
148
|
+
| `--stdin` | Read data from standard input |
|
|
149
|
+
| `--title TEXT` | Chart title (default: "Price Chart") |
|
|
150
|
+
| `--volume / --no-volume` | Show/hide volume subplot (default: enabled) |
|
|
151
|
+
| `--ma INT` | Moving average period (can be used multiple times, default: 20, 50) |
|
|
152
|
+
| `--theme [dark\|light]` | Chart theme (default: dark) |
|
|
153
|
+
|
|
154
|
+
### `chartpipe indicators` - Technical Indicators
|
|
155
|
+
|
|
156
|
+
Generate technical indicator charts including RSI, MACD, and Bollinger Bands.
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# RSI indicator
|
|
160
|
+
chartpipe indicators --indicator rsi --data btc.json
|
|
161
|
+
|
|
162
|
+
# MACD indicator
|
|
163
|
+
chartpipe indicators --indicator macd --stdin
|
|
164
|
+
|
|
165
|
+
# Bollinger Bands
|
|
166
|
+
chartpipe indicators --indicator bb --data btc.json --theme light
|
|
167
|
+
|
|
168
|
+
# All indicators combined
|
|
169
|
+
chartpipe indicators --indicator all --data btc.json
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Options:**
|
|
173
|
+
|
|
174
|
+
| Option | Description |
|
|
175
|
+
|--------|-------------|
|
|
176
|
+
| `--indicator [rsi\|macd\|bb\|all]` | Indicator type to generate |
|
|
177
|
+
| `--data PATH` | Path to OHLCV data file |
|
|
178
|
+
| `--input PATH` | Alias for `--data` |
|
|
179
|
+
| `--stdin` | Read data from standard input |
|
|
180
|
+
| `--period INT` | RSI period (default: 14) |
|
|
181
|
+
| `--theme [dark\|light]` | Chart theme |
|
|
182
|
+
|
|
183
|
+
### `chartpipe backtest` - Backtest Visualization
|
|
184
|
+
|
|
185
|
+
Generate comprehensive backtest visualizations with equity curves, drawdowns, and trade markers.
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# Prefer: quantpipe with --run-dir, then chartpipe on same directory or stdin JSON with artifacts
|
|
189
|
+
# (see "Integration with quantpipe" above)
|
|
190
|
+
|
|
191
|
+
# From file (legacy JSON with equity_curve / history)
|
|
192
|
+
chartpipe backtest --data backtest_results.json --title "MA Cross Strategy"
|
|
193
|
+
|
|
194
|
+
# From quantpipe run directory (equity.csv, optional trades.csv, optional summary.json)
|
|
195
|
+
chartpipe backtest --run-dir runs/my-run --json
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Options:**
|
|
199
|
+
|
|
200
|
+
| Option | Description |
|
|
201
|
+
|--------|-------------|
|
|
202
|
+
| `--data PATH` | Path to backtest result file (JSON) |
|
|
203
|
+
| `--input PATH` | Alias for `--data` |
|
|
204
|
+
| `--stdin` | Read JSON from standard input (quantpipe envelope or legacy) |
|
|
205
|
+
| `--run-dir PATH` | Load `equity.csv` / `trades.csv` from a `runs/<id>/` directory |
|
|
206
|
+
| `--title TEXT` | Chart title (default: from `summary.json` strategy name or generic) |
|
|
207
|
+
|
|
208
|
+
### `chartpipe stats` - Statistical Analysis
|
|
209
|
+
|
|
210
|
+
Generate statistical analysis charts for trading data analysis.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Returns distribution
|
|
214
|
+
chartpipe stats --type returns --data btc.json
|
|
215
|
+
|
|
216
|
+
# Monthly returns heatmap
|
|
217
|
+
chartpipe stats --type monthly --stdin
|
|
218
|
+
|
|
219
|
+
# Price distribution
|
|
220
|
+
chartpipe stats --type distribution --data btc.json
|
|
221
|
+
|
|
222
|
+
# All statistical charts
|
|
223
|
+
chartpipe stats --type all --data btc.json
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Options:**
|
|
227
|
+
|
|
228
|
+
| Option | Description |
|
|
229
|
+
|--------|-------------|
|
|
230
|
+
| `--type [returns\|distribution\|monthly\|all]` | Chart type |
|
|
231
|
+
| `--data PATH` | Path to OHLCV data file |
|
|
232
|
+
| `--input PATH` | Alias for `--data` |
|
|
233
|
+
| `--stdin` | Read data from standard input |
|
|
234
|
+
| `--title TEXT` | Chart title |
|
|
235
|
+
|
|
236
|
+
## Data Formats
|
|
237
|
+
|
|
238
|
+
ChartPipe automatically detects and handles multiple data formats:
|
|
239
|
+
|
|
240
|
+
### Standard OHLCV Format
|
|
241
|
+
|
|
242
|
+
```json
|
|
243
|
+
[
|
|
244
|
+
{"timestamp": "2024-01-01", "open": 42000, "high": 43000, "low": 41000, "close": 42500, "volume": 1000},
|
|
245
|
+
{"timestamp": "2024-01-02", "open": 42500, "high": 44000, "low": 42000, "close": 43500, "volume": 1500}
|
|
246
|
+
]
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Binance Format (Auto-detected)
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
[
|
|
253
|
+
{"t": 1704067200000, "o": "42000.00", "h": "43000.00", "l": "41000.00", "c": "42500.00", "v": "1000.00"}
|
|
254
|
+
]
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Backtest Result Format
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"equity_curve": [
|
|
262
|
+
{"timestamp": "2024-01-01", "equity": 10000, "drawdown": 0, "close": 42500},
|
|
263
|
+
{"timestamp": "2024-01-02", "equity": 10200, "drawdown": 0, "close": 43500}
|
|
264
|
+
],
|
|
265
|
+
"trades": [
|
|
266
|
+
{"entry_time": "2024-01-01", "exit_time": "2024-01-02", "entry_price": 42000, "exit_price": 43000, "side": "long"}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Supported Field Mappings
|
|
272
|
+
|
|
273
|
+
| Standard | Binance | Polymarket | Uniswap |
|
|
274
|
+
|----------|---------|------------|---------|
|
|
275
|
+
| `timestamp` | `t`, `T`, `time` | - | - |
|
|
276
|
+
| `open` | `o`, `O` | - | - |
|
|
277
|
+
| `high` | `h`, `H` | - | - |
|
|
278
|
+
| `low` | `l`, `L` | - | - |
|
|
279
|
+
| `close` | `c`, `C` | - | - |
|
|
280
|
+
| `volume` | `v`, `V`, `vol` | - | - |
|
|
281
|
+
|
|
282
|
+
## Output Formats
|
|
283
|
+
|
|
284
|
+
### Standard Output
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
Chart saved: D:\codebase\seamflux-quant\charts\ohlcv_20260317_130405.png
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### JSON Output (`--json`)
|
|
291
|
+
|
|
292
|
+
Stdout is **one JSON object per invocation** (rule.md ยง4). Chart paths are under **`artifacts`** (relative to current working directory unless absolute).
|
|
293
|
+
|
|
294
|
+
Single chart:
|
|
295
|
+
|
|
296
|
+
```json
|
|
297
|
+
{
|
|
298
|
+
"schemaVersion": 1,
|
|
299
|
+
"tool": "chartpipe",
|
|
300
|
+
"command": "ohlcv",
|
|
301
|
+
"ok": true,
|
|
302
|
+
"artifacts": { "chart": "charts/ohlcv_20260317_130405.png" },
|
|
303
|
+
"meta": { "startedAt": "2026-03-19T12:00:00.000Z", "finishedAt": "2026-03-19T12:00:01.000Z" }
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`chartpipe indicators --indicator all` / `chartpipe stats --type all` use multiple keys under `artifacts` (e.g. `rsi`, `macd`, `bb`).
|
|
308
|
+
|
|
309
|
+
**Migration:** older releases used `{"img": "..."}` only; scripts should read `artifacts.chart` (or the specific artifact keys for `all` modes).
|
|
310
|
+
|
|
311
|
+
## Directory Structure
|
|
312
|
+
|
|
313
|
+
```
|
|
314
|
+
chartpipe/
|
|
315
|
+
โโโ src/
|
|
316
|
+
โ โโโ chartpipe/
|
|
317
|
+
โ โโโ __init__.py
|
|
318
|
+
โ โโโ __main__.py
|
|
319
|
+
โ โโโ cli.py
|
|
320
|
+
โ โโโ cli_exit.py
|
|
321
|
+
โ โโโ core/
|
|
322
|
+
โ โ โโโ __init__.py
|
|
323
|
+
โ โ โโโ backtest_input.py
|
|
324
|
+
โ โ โโโ charts.py
|
|
325
|
+
โ โ โโโ input_data.py
|
|
326
|
+
โ โ โโโ pipeline_json.py
|
|
327
|
+
โ โ โโโ styles.py
|
|
328
|
+
โ โโโ commands/
|
|
329
|
+
โ โโโ __init__.py
|
|
330
|
+
โ โโโ ohlcv.py
|
|
331
|
+
โ โโโ indicators.py
|
|
332
|
+
โ โโโ backtest.py
|
|
333
|
+
โ โโโ stats.py
|
|
334
|
+
โโโ tests/
|
|
335
|
+
โโโ requirements.txt
|
|
336
|
+
โโโ requirements-dev.txt
|
|
337
|
+
โโโ pytest.ini
|
|
338
|
+
โโโ setup.py
|
|
339
|
+
โโโ README.md
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Tests
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
pip install -r requirements-dev.txt
|
|
346
|
+
pytest
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Requirements
|
|
350
|
+
|
|
351
|
+
- Python >= 3.10
|
|
352
|
+
- pandas >= 2.0.0
|
|
353
|
+
- numpy >= 1.24.0
|
|
354
|
+
- matplotlib >= 3.7.0
|
|
355
|
+
- mplfinance >= 0.12.10b0
|
|
356
|
+
- seaborn >= 0.12.0
|
|
357
|
+
- click >= 8.0.0
|
|
358
|
+
|
|
359
|
+
## License
|
|
360
|
+
|
|
361
|
+
MIT License
|
|
362
|
+
|
|
363
|
+
## Contributing
|
|
364
|
+
|
|
365
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
366
|
+
|
|
367
|
+
## Changelog
|
|
368
|
+
|
|
369
|
+
### v0.1.0
|
|
370
|
+
- Initial release
|
|
371
|
+
- OHLCV candlestick charts with moving averages
|
|
372
|
+
- Technical indicators (RSI, MACD, Bollinger Bands)
|
|
373
|
+
- Backtest visualization
|
|
374
|
+
- Statistical analysis charts
|
|
375
|
+
- Dark/light themes
|
|
376
|
+
- JSON output for pipeline integration
|