@livefolio/sdk 0.3.0 → 0.3.2
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/dist/index.d.ts +104 -0
- package/dist/index.js +455 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -114,9 +114,53 @@ declare class IndicatorHandle {
|
|
|
114
114
|
private _sync;
|
|
115
115
|
private _upsertSeries;
|
|
116
116
|
private _querySeriesFromDb;
|
|
117
|
+
withMarket(market: MarketProvider): IndicatorHandle;
|
|
118
|
+
/**
|
|
119
|
+
* Apply leverage compounding to a raw bar series, anchored to a stored
|
|
120
|
+
* leveraged value. Used by both `_sync` and `computeAt` so they stay
|
|
121
|
+
* consistent.
|
|
122
|
+
*
|
|
123
|
+
* `anchorDate` is the date of the last *already-stored* leveraged bar
|
|
124
|
+
* (i.e., the bar just before `rawBars[0]`). The stored leveraged value
|
|
125
|
+
* at that date becomes `leveraged[0]`; raw returns are then compounded
|
|
126
|
+
* forward for each subsequent bar.
|
|
127
|
+
*
|
|
128
|
+
* If no stored anchor exists (first-ever sync), falls back to rawBars[0]
|
|
129
|
+
* as the starting raw value — identical to `_sync`'s behaviour.
|
|
130
|
+
*/
|
|
131
|
+
private _applyLeverage;
|
|
132
|
+
/**
|
|
133
|
+
* Compute the indicator's value at `date` using the given market (typically
|
|
134
|
+
* an overlay market for pre-close preview). Pure — no writes to storage.
|
|
135
|
+
*
|
|
136
|
+
* For fetched types (yahoo/fred): fetches a small window of bars from
|
|
137
|
+
* `market`, applies leverage compounding anchored to the stored leveraged
|
|
138
|
+
* value at the bar before `date`.
|
|
139
|
+
* For computed types (SMA, RSI, etc.): fetches enough raw price bars to
|
|
140
|
+
* cover the indicator's lookback from `market`, applies leverage anchored
|
|
141
|
+
* to the stored value just before the fetch window, runs the computation,
|
|
142
|
+
* and returns the value at `date`.
|
|
143
|
+
* For Threshold: returns the threshold constant.
|
|
144
|
+
* For calendar: computes calendar value from the trading days list.
|
|
145
|
+
* Returns null if the value cannot be computed.
|
|
146
|
+
*/
|
|
147
|
+
computeAt(market: MarketProvider, date: string): Promise<number | null>;
|
|
117
148
|
series(range?: DateRange): Promise<DailyBar[]>;
|
|
118
149
|
private _syntheticThresholdSeries;
|
|
119
150
|
value(date?: string): Promise<number | null>;
|
|
151
|
+
/**
|
|
152
|
+
* Read-only preview of the indicator series that includes an in-memory bar
|
|
153
|
+
* at `date` computed via `computeAt` against a quote-overlay market. Does
|
|
154
|
+
* NOT write to `indicators_series`. Safe to call before market close.
|
|
155
|
+
*
|
|
156
|
+
* @param date - Target trading day whose value is computed in-memory from
|
|
157
|
+
* the overridden quotes. Must be in `tradingDays.getRange()`.
|
|
158
|
+
* @param quoteOverrides - Raw (unleveraged) quotes keyed by ticker symbol.
|
|
159
|
+
* Symbols omitted here fall back to yesterday's close via the overlay.
|
|
160
|
+
* @param range - Optional filter applied to the returned bars.
|
|
161
|
+
* @returns Stored historical bars plus (or with) today's in-memory value.
|
|
162
|
+
*/
|
|
163
|
+
previewSeries(date: string, quoteOverrides: Record<string, number>, range?: DateRange): Promise<DailyBar[]>;
|
|
120
164
|
}
|
|
121
165
|
|
|
122
166
|
interface StorageProvider {
|
|
@@ -188,6 +232,7 @@ interface StorageProvider {
|
|
|
188
232
|
getSeries(strategyId: number, range?: DateRange): Promise<StrategySeriesEntry[]>;
|
|
189
233
|
writeSeries(strategyId: number, entries: StrategySeriesEntry[]): Promise<void>;
|
|
190
234
|
getLatestSeriesDate(strategyId: number): Promise<string | null>;
|
|
235
|
+
getLatestAllocationId(strategyId: number): Promise<number | null>;
|
|
191
236
|
resolveReference(linkId: string): Promise<StrategyReferenceData>;
|
|
192
237
|
};
|
|
193
238
|
tradingDays: {
|
|
@@ -228,8 +273,31 @@ declare class SignalHandle {
|
|
|
228
273
|
private _sync;
|
|
229
274
|
private _upsertSeries;
|
|
230
275
|
private _querySeriesFromDb;
|
|
276
|
+
withMarket(market: MarketProvider): SignalHandle;
|
|
277
|
+
/**
|
|
278
|
+
* Compute the signal's boolean value at `date` using the given market
|
|
279
|
+
* (typically an overlay market for pre-close preview). Pure — no writes.
|
|
280
|
+
* Returns null if either indicator cannot produce a value at `date`.
|
|
281
|
+
*
|
|
282
|
+
* @param prevBool - The signal's boolean value at the bar immediately
|
|
283
|
+
* preceding `date`, used for hysteresis when `tolerance > 0`. If not
|
|
284
|
+
* provided, falls back to `storage.signals.getLastValue` (suitable for
|
|
285
|
+
* standalone callers). On the preview path `_evaluate` passes this from
|
|
286
|
+
* the in-memory `dateMap` so we never read stale storage.
|
|
287
|
+
*/
|
|
288
|
+
computeAt(market: MarketProvider, date: string, prevBool?: boolean | null): Promise<boolean | null>;
|
|
231
289
|
series(range?: DateRange): Promise<DailyBar[]>;
|
|
232
290
|
value(date?: string): Promise<number | null>;
|
|
291
|
+
/**
|
|
292
|
+
* Read-only preview of the signal series with an in-memory bar at `date`
|
|
293
|
+
* computed via `computeAt` against a quote-overlay market. Does NOT write
|
|
294
|
+
* to `signals_series`.
|
|
295
|
+
*
|
|
296
|
+
* @param date - Target trading day whose boolean is computed in-memory.
|
|
297
|
+
* @param quoteOverrides - Raw (unleveraged) quotes keyed by ticker symbol.
|
|
298
|
+
* @param range - Optional filter applied to the returned bars.
|
|
299
|
+
*/
|
|
300
|
+
previewSeries(date: string, quoteOverrides: Record<string, number>, range?: DateRange): Promise<DailyBar[]>;
|
|
233
301
|
}
|
|
234
302
|
|
|
235
303
|
declare class AllocationHandle {
|
|
@@ -339,10 +407,46 @@ declare class StrategyHandle {
|
|
|
339
407
|
private _getLatestStrategySeriesDate;
|
|
340
408
|
private _ensureFresh;
|
|
341
409
|
private _sync;
|
|
410
|
+
/**
|
|
411
|
+
* Pure evaluate — runs the same pipeline as _sync but returns the computed
|
|
412
|
+
* evaluation instead of persisting. Used by both _sync (post-close write
|
|
413
|
+
* path) and previewAllocation (pre-close read-only path).
|
|
414
|
+
*
|
|
415
|
+
* The `market === this._market` identity check is what distinguishes the two
|
|
416
|
+
* paths: when they are the same object the method takes the write path (syncing
|
|
417
|
+
* signals through storage as normal); when they differ it takes the read-only
|
|
418
|
+
* preview path (historical bars from storage, today's value computed in-memory
|
|
419
|
+
* via `computeAt`). Callers that want the preview path must therefore supply a
|
|
420
|
+
* *different* market object — for example one produced by `createQuoteOverlay`.
|
|
421
|
+
*/
|
|
422
|
+
private _evaluate;
|
|
342
423
|
private _querySeriesFromDb;
|
|
343
424
|
series(range?: DateRange): Promise<StrategyBar[]>;
|
|
344
425
|
value(date?: string): Promise<AllocationHandle | null>;
|
|
345
426
|
simulate(options: SimulateOptions): Promise<SimulationHandle>;
|
|
427
|
+
/**
|
|
428
|
+
* Preview the allocation this strategy would produce for `date` if today
|
|
429
|
+
* closed at the provided raw quote prices. Does NOT write to strategies_series,
|
|
430
|
+
* signals_series, or indicators_series. Safe to call before market close.
|
|
431
|
+
*
|
|
432
|
+
* @param date - The trading day to preview (must be in tradingDays.getRange()).
|
|
433
|
+
* @param quoteOverrides - Raw (unleveraged) live prices keyed by ticker symbol.
|
|
434
|
+
* Symbols absent from this map will fall back to yesterday's close via the
|
|
435
|
+
* quote overlay.
|
|
436
|
+
* @returns The AllocationHandle for `date`, or null if the strategy has no
|
|
437
|
+
* evaluable entry for that date.
|
|
438
|
+
*/
|
|
439
|
+
previewAllocation(date: string, quoteOverrides: Record<string, number>): Promise<AllocationHandle | null>;
|
|
440
|
+
/**
|
|
441
|
+
* Read-only preview of the strategy's allocation series including `date`.
|
|
442
|
+
* Returns stored historical allocations plus an in-memory bar at `date`
|
|
443
|
+
* computed via the same overlay path as `previewAllocation`.
|
|
444
|
+
*
|
|
445
|
+
* @param date - Target trading day to splice in-memory via overlay market.
|
|
446
|
+
* @param quoteOverrides - Raw (unleveraged) quotes keyed by ticker symbol.
|
|
447
|
+
* @param range - Optional filter applied to the returned bars.
|
|
448
|
+
*/
|
|
449
|
+
previewSeries(date: string, quoteOverrides: Record<string, number>, range?: DateRange): Promise<StrategyBar[]>;
|
|
346
450
|
private _fetchPricesForTickers;
|
|
347
451
|
private _fetchRawClosePrices;
|
|
348
452
|
}
|