tradelab 0.1.2 → 0.2.0

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.
package/README.md CHANGED
@@ -2,21 +2,25 @@
2
2
 
3
3
  # tradelab
4
4
 
5
- `tradelab` is a candle-based backtesting toolkit for Node.js. It is built for two use cases:
6
- - you already have candles and want a solid execution/backtest engine
7
- - you want to fetch Yahoo Finance data or import CSVs and backtest with minimal setup
5
+ `tradelab` is a Node.js backtesting toolkit for trading strategy research. It lets you:
6
+ - load candles from Yahoo Finance or CSV
7
+ - run candle-based backtests with sizing, exits, and risk controls
8
+ - export trades, metrics, and HTML reports
8
9
 
9
- The package stays focused on historical research and testing, and is not trying to be a broker adapter or a live trading framework.
10
+ The package is modular by design, so you can use just the parts you need: data loading, backtesting, reporting, or the utility layer on its own.
11
+
12
+ It is built for historical research and testing, not broker connectivity or live trading.
10
13
 
11
14
  ## Features
12
15
 
13
- - Backtest engine with pending entries, OCO exits, scale-outs, pyramiding, cooldowns, daily risk limits, and optional replay data
14
- - Yahoo Finance historical downloader with local caching
15
- - Flexible CSV import for common OHLCV layouts
16
- - Metrics for positions and realized legs
17
- - CSV trade export
18
- - Self-contained HTML report export
19
- - Utility indicators and session helpers for strategy code
16
+ - Modular structure: use the full workflow or just the engine, data layer, reporting, or helpers
17
+ - Backtest engine with pending entries, OCO exits, scale-outs, pyramiding, cooldowns, daily loss limits, and optional replay/equity capture
18
+ - Historical data loading from Yahoo Finance, with local caching to avoid repeated downloads
19
+ - CSV import for common OHLCV formats and custom column mappings
20
+ - Position-level and leg-level metrics, including drawdown, expectancy, hold-time stats, and side breakdowns
21
+ - HTML report export, metrics JSON export, and trade CSV export
22
+ - Utility indicators and session helpers for strategy development
23
+ - TypeScript definitions for the public API
20
24
 
21
25
  ## Installation
22
26
 
@@ -26,6 +30,22 @@ npm install tradelab
26
30
 
27
31
  Node `18+` is required.
28
32
 
33
+ ## Importing
34
+
35
+ ### CommonJS
36
+
37
+ ```js
38
+ const { backtest, getHistoricalCandles, ema } = require("tradelab");
39
+ const { fetchHistorical } = require("tradelab/data");
40
+ ```
41
+
42
+ ### ESM
43
+
44
+ ```js
45
+ import { backtest, getHistoricalCandles, ema } from "tradelab";
46
+ import { fetchHistorical } from "tradelab/data";
47
+ ```
48
+
29
49
  ## Quick Start
30
50
 
31
51
  ```js
@@ -72,7 +92,7 @@ exportBacktestArtifacts({
72
92
 
73
93
  ## Getting Historical Data
74
94
 
75
- The simplest entry point is `getHistoricalCandles()`.
95
+ The simplest entry point is `getHistoricalCandles()`. For most users, it is the only data-loading function you need.
76
96
 
77
97
  ### Yahoo Finance
78
98
 
@@ -154,6 +174,7 @@ Quality-of-life behavior:
154
174
  - `takeProfit` can be omitted if `rr` or `_rr` is provided
155
175
  - `qty` or `size` can override risk-based sizing
156
176
  - `riskPct` or `riskFraction` can override the global risk setting per signal
177
+ - `strict: true` throws if the strategy directly accesses candles beyond the current index
157
178
 
158
179
  Optional engine hints:
159
180
 
@@ -173,8 +194,8 @@ Optional engine hints:
173
194
 
174
195
  - `trades`: every realized leg, including scale-outs
175
196
  - `positions`: completed positions only
176
- - `metrics`: aggregate performance stats
177
- - `eqSeries`: realized equity history
197
+ - `metrics`: aggregate stats including `winRate`, `expectancy`, `profitFactor`, `maxDrawdown`, `sharpe`, `avgHold`, and `sideBreakdown`
198
+ - `eqSeries`: realized equity history as `{ time, timestamp, equity }`
178
199
  - `replay`: chart-friendly frame and event data
179
200
 
180
201
  ## Main Exports
@@ -186,11 +207,12 @@ Optional engine hints:
186
207
  - `loadCandlesFromCSV(filePath, options)`
187
208
  - `saveCandlesToCache(candles, meta)`
188
209
  - `loadCandlesFromCache(symbol, interval, period, outDir)`
210
+ - `exportMetricsJSON({ result, outDir })`
189
211
  - `exportBacktestArtifacts({ result, outDir })`
190
212
 
191
213
  ## Reports
192
214
 
193
- The HTML report is self-contained apart from the Plotly CDN script. Report markup, CSS, and client-side chart code live under `templates/`, not inline in the report renderer.
215
+ The HTML report is self-contained apart from the Plotly CDN script. Report markup, CSS, and client-side chart code live under `templates/`.
194
216
 
195
217
  Export helpers default CSV output to completed positions. Use `csvSource: "trades"` if you want every realized leg in the CSV.
196
218
 
@@ -206,3 +228,4 @@ node examples/yahooEmaCross.js SPY 1d 1y
206
228
  - Yahoo downloads can be cached under `output/data` by default.
207
229
  - The engine is intended for historical research, not brokerage execution.
208
230
  - File output only happens through the reporting and cache helpers.
231
+ - CommonJS and ESM are both supported.