openalgo-charts 2.2.2 → 2.3.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 +20 -20
- package/dist/index.d.ts +1 -1
- package/dist/openalgo-charts.draw.mjs +1 -1
- package/dist/openalgo-charts.draw.mjs.map +1 -1
- package/dist/openalgo-charts.mjs +1 -1
- package/dist/openalgo-charts.mjs.map +1 -1
- package/dist/openalgo-charts.standalone.js +1 -1
- package/dist/openalgo-charts.standalone.js.map +1 -1
- package/dist/openalgo-charts.transform.mjs +1 -1
- package/dist/openalgo-charts.transform.mjs.map +1 -1
- package/dist/openalgo-charts.widget.mjs +1 -1
- package/dist/openalgo-charts.widget.mjs.map +1 -1
- package/dist/transform/index.d.ts +129 -1
- package/package.json +1 -1
|
@@ -226,6 +226,134 @@ declare class KagiTransform implements ISeriesTransform {
|
|
|
226
226
|
flush(): Bar[];
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Symbol arithmetic: a chart of `NIFTY1!/NSE:RELIANCE`, `(A+B)/2`, `1/GOLD`.
|
|
231
|
+
*
|
|
232
|
+
* Two halves, deliberately separate. `parseExpression` turns a string into an
|
|
233
|
+
* AST and, crucially, tells the caller which symbols it needs *before* any data
|
|
234
|
+
* is fetched, so a host can resolve and load exactly those legs.
|
|
235
|
+
* `evaluateExpression` then folds the legs into one synthetic bar series.
|
|
236
|
+
*
|
|
237
|
+
* The engine does no fetching. A host owns symbol resolution and history, the
|
|
238
|
+
* same way `addComparison` takes bars rather than a symbol.
|
|
239
|
+
*
|
|
240
|
+
* ## Why the high and low are approximations
|
|
241
|
+
*
|
|
242
|
+
* A bar says where a market opened, closed, and how far it travelled, but not
|
|
243
|
+
* *when* it was at each price. For `A/B` the true high of the ratio needs the
|
|
244
|
+
* instant A was highest relative to B, and two OHLC bars do not record that.
|
|
245
|
+
*
|
|
246
|
+
* So the extremes are computed by interval arithmetic: each leg contributes
|
|
247
|
+
* `[low, high]`, every operator maps intervals to intervals, and the result's
|
|
248
|
+
* interval is the range the expression *could* have covered. That bound is
|
|
249
|
+
* guaranteed to contain the truth and is usually wider than it, because it
|
|
250
|
+
* assumes the legs hit their extremes at the worst possible moments. Open and
|
|
251
|
+
* close need no such trick: they are read from the legs' own opens and closes,
|
|
252
|
+
* which are simultaneous by definition, and so are exact.
|
|
253
|
+
*
|
|
254
|
+
* One consequence worth knowing: an interval cannot tell that two mentions of
|
|
255
|
+
* the same symbol move together, so `A/A` bounds to `[low/high, high/low]`
|
|
256
|
+
* rather than collapsing to 1. That is the classic dependency problem, and it
|
|
257
|
+
* is why `ohlc: 'close'` (a line from exact closes) is the default.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/** A parsed expression, with the symbols it needs. */
|
|
261
|
+
interface SymbolExpression {
|
|
262
|
+
/** The source, as typed. */
|
|
263
|
+
readonly source: string;
|
|
264
|
+
/** Distinct symbols, in first-seen order. The first is the default time grid. */
|
|
265
|
+
readonly symbols: readonly string[];
|
|
266
|
+
/** Opaque syntax tree. */
|
|
267
|
+
readonly ast: Node;
|
|
268
|
+
}
|
|
269
|
+
interface EvaluateOptions {
|
|
270
|
+
/**
|
|
271
|
+
* `'close'` (default) evaluates only the closes, giving a flat bar whose four
|
|
272
|
+
* values are equal: exact, and honest about what two OHLC bars can support.
|
|
273
|
+
* `'interval'` additionally bounds the high and low as described above.
|
|
274
|
+
*/
|
|
275
|
+
ohlc?: 'close' | 'interval';
|
|
276
|
+
/**
|
|
277
|
+
* The leg whose bars define the time grid. Defaults to the first symbol.
|
|
278
|
+
* Every other leg is matched to it by timestamp; a bar with no match on some
|
|
279
|
+
* leg produces a gap rather than a guess.
|
|
280
|
+
*/
|
|
281
|
+
primary?: string;
|
|
282
|
+
}
|
|
283
|
+
type Node = {
|
|
284
|
+
k: 'num';
|
|
285
|
+
v: number;
|
|
286
|
+
} | {
|
|
287
|
+
k: 'sym';
|
|
288
|
+
name: string;
|
|
289
|
+
} | {
|
|
290
|
+
k: 'neg';
|
|
291
|
+
a: Node;
|
|
292
|
+
} | {
|
|
293
|
+
k: 'bin';
|
|
294
|
+
op: '+' | '-' | '*' | '/' | '^';
|
|
295
|
+
a: Node;
|
|
296
|
+
b: Node;
|
|
297
|
+
} | {
|
|
298
|
+
k: 'fn';
|
|
299
|
+
name: FnName;
|
|
300
|
+
args: Node[];
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Functions are limited to ones whose interval image is cheap and correct to
|
|
304
|
+
* derive. Anything non-monotonic in a way that needs calculus is left out
|
|
305
|
+
* rather than shipped with a bound that is quietly wrong.
|
|
306
|
+
*/
|
|
307
|
+
declare const FN_ARITY: {
|
|
308
|
+
readonly abs: 1;
|
|
309
|
+
readonly sqrt: 1;
|
|
310
|
+
readonly ln: 1;
|
|
311
|
+
readonly log: 1;
|
|
312
|
+
readonly log10: 1;
|
|
313
|
+
readonly exp: 1;
|
|
314
|
+
readonly min: 2;
|
|
315
|
+
readonly max: 2;
|
|
316
|
+
readonly pow: 2;
|
|
317
|
+
};
|
|
318
|
+
type FnName = keyof typeof FN_ARITY;
|
|
319
|
+
declare class ExpressionError extends Error {
|
|
320
|
+
readonly position: number;
|
|
321
|
+
constructor(message: string, position: number);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Parse `source` into an expression and the symbols it needs.
|
|
325
|
+
*
|
|
326
|
+
* ```ts
|
|
327
|
+
* const e = parseExpression('NIFTY1!/NSE:RELIANCE');
|
|
328
|
+
* e.symbols; // ['NIFTY1!', 'NSE:RELIANCE'] -> fetch exactly these
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* Throws `ExpressionError` with the offending character's index, so a search
|
|
332
|
+
* box can underline it. A bare symbol parses too, which lets one code path
|
|
333
|
+
* handle both an ordinary chart and a synthetic one.
|
|
334
|
+
*/
|
|
335
|
+
declare function parseExpression(source: string): SymbolExpression;
|
|
336
|
+
/** True when `source` is a single plain symbol, needing no arithmetic. */
|
|
337
|
+
declare function isPlainSymbol(source: string): boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Fold the legs into one synthetic series.
|
|
340
|
+
*
|
|
341
|
+
* `legs` maps each symbol in `expr.symbols` to its bars. A symbol with no
|
|
342
|
+
* entry, or a bar the primary has and a leg does not, yields no output bar: the
|
|
343
|
+
* series gaps there rather than carrying a stale price forward, because a
|
|
344
|
+
* ratio against yesterday's close is a number that was never true.
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* const e = parseExpression('NIFTY1!/NSE:RELIANCE');
|
|
348
|
+
* const bars = evaluateExpression(e, { 'NIFTY1!': a, 'NSE:RELIANCE': b });
|
|
349
|
+
* chart.addSeries('line').setData(bars);
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* `volume` is deliberately absent from the result. The volume of a ratio is not
|
|
353
|
+
* a quantity anyone traded, and picking one leg's would be arbitrary.
|
|
354
|
+
*/
|
|
355
|
+
declare function evaluateExpression(expr: SymbolExpression, legs: Readonly<Record<string, readonly Bar[]>>, options?: EvaluateOptions): Bar[];
|
|
356
|
+
|
|
229
357
|
declare const TRANSFORM_TIER: "transform";
|
|
230
358
|
/**
|
|
231
359
|
* Register the Family-B custom renderers (point-figure, kagi). Called as a side
|
|
@@ -238,4 +366,4 @@ declare const TRANSFORM_TIER: "transform";
|
|
|
238
366
|
*/
|
|
239
367
|
declare function registerTransformChartTypes(): void;
|
|
240
368
|
|
|
241
|
-
export { HeikinAshiTransform, type ISeriesTransform, type KagiOptions, KagiTransform, type LineBreakOptions, LineBreakTransform, type PointFigureBoxMode, type PointFigureColumn, type PointFigureMethod, type PointFigureOptions, PointFigureTransform, RangeBarsTransform, type RangeOptions, type RenkoOptions, RenkoTransform, TRANSFORM_TIER, ensureIncreasingTimes, registerTransformChartTypes, runTransform };
|
|
369
|
+
export { type EvaluateOptions, ExpressionError, HeikinAshiTransform, type ISeriesTransform, type KagiOptions, KagiTransform, type LineBreakOptions, LineBreakTransform, type PointFigureBoxMode, type PointFigureColumn, type PointFigureMethod, type PointFigureOptions, PointFigureTransform, RangeBarsTransform, type RangeOptions, type RenkoOptions, RenkoTransform, type SymbolExpression, TRANSFORM_TIER, ensureIncreasingTimes, evaluateExpression, isPlainSymbol, parseExpression, registerTransformChartTypes, runTransform };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openalgo-charts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "From-scratch, dependency-free canvas charting engine for OpenAlgo: professional-grade interactive rendering, advanced on-chart trading, and a one-call widget tier that adds the toolbar, drawing rail, dialogs and shortcuts.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "marketcalls",
|