@adaptic/utils 0.0.989 → 0.0.991
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.cjs +754 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +750 -2
- package/dist/index.mjs.map +1 -1
- package/dist/types/__tests__/atr.test.d.ts +2 -0
- package/dist/types/__tests__/atr.test.d.ts.map +1 -0
- package/dist/types/__tests__/index.test.d.ts +2 -0
- package/dist/types/__tests__/index.test.d.ts.map +1 -0
- package/dist/types/__tests__/risk-metrics.test.d.ts +2 -0
- package/dist/types/__tests__/risk-metrics.test.d.ts.map +1 -0
- package/dist/types/__tests__/strategy-metrics.test.d.ts +2 -0
- package/dist/types/__tests__/strategy-metrics.test.d.ts.map +1 -0
- package/dist/types/__tests__/volatility.test.d.ts +2 -0
- package/dist/types/__tests__/volatility.test.d.ts.map +1 -0
- package/dist/types/atr.d.ts +30 -0
- package/dist/types/atr.d.ts.map +1 -0
- package/dist/types/index.d.ts +41 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/misc-utils.d.ts +37 -0
- package/dist/types/misc-utils.d.ts.map +1 -1
- package/dist/types/risk-metrics.d.ts +58 -0
- package/dist/types/risk-metrics.d.ts.map +1 -0
- package/dist/types/strategy-metrics.d.ts +65 -0
- package/dist/types/strategy-metrics.d.ts.map +1 -0
- package/dist/types/trading-policy/schemas/effective-policy.schema.d.ts +4 -4
- package/dist/types/trading-policy/schemas/execution-prefs.schema.d.ts +4 -4
- package/dist/types/trading-policy/schemas/policy-mutation.schema.d.ts +6 -6
- package/dist/types/volatility.d.ts +65 -0
- package/dist/types/volatility.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atr.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/atr.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk-metrics.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/risk-metrics.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-metrics.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/strategy-metrics.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volatility.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/volatility.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wilder ATR + EWMA-smoothed + multi-timespan variants.
|
|
3
|
+
*
|
|
4
|
+
* All functions are pure: same inputs → same output, no I/O, no time-dependence.
|
|
5
|
+
*/
|
|
6
|
+
export interface AtrBar {
|
|
7
|
+
high: number;
|
|
8
|
+
low: number;
|
|
9
|
+
close: number;
|
|
10
|
+
timespan?: "minute" | "hour" | "day";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Classic Wilder ATR (single value).
|
|
14
|
+
* @returns ATR for the most recent `period` bars, or null when insufficient bars.
|
|
15
|
+
*/
|
|
16
|
+
export declare function calculateATR(highs: number[], lows: number[], closes: number[], period: number): number | null;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the EWMA-smoothed ATR series (one ATR per bar, leading nulls until `period` bars).
|
|
19
|
+
*/
|
|
20
|
+
export declare function calculateATREMA(highs: number[], lows: number[], closes: number[], period: number): Array<number | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Wrapper that accepts AtrBar[] (timespan-tagged); identical math, the timespan tag is
|
|
23
|
+
* carried through for consumer-side logic only.
|
|
24
|
+
*
|
|
25
|
+
* @param bars - All bars must share the same timespan; the tag is metadata only
|
|
26
|
+
* and is not validated. Mixed-timespan input produces a meaningless ATR.
|
|
27
|
+
* @param period - Wilder lookback period (positive integer).
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateATRMultiTimespan(bars: AtrBar[], period: number): number | null;
|
|
30
|
+
//# sourceMappingURL=atr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atr.d.ts","sourceRoot":"","sources":["../../src/atr.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAyBf;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,GACb,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CA6BtB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAOf"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AlpacaMarketDataAPI } from "./alpaca-market-data-api";
|
|
|
3
3
|
import { AlpacaTradingAPI } from "./alpaca-trading-api";
|
|
4
4
|
import * as Alpaca from "./alpaca/legacy";
|
|
5
5
|
import * as av from "./alphavantage";
|
|
6
|
+
import * as atrNs from "./atr";
|
|
6
7
|
import * as crypto from "./crypto";
|
|
7
8
|
import * as ft from "./format-tools";
|
|
8
9
|
import * as mt from "./market-time";
|
|
@@ -12,9 +13,12 @@ import * as misc from "./misc-utils";
|
|
|
12
13
|
import * as pm from "./performance-metrics";
|
|
13
14
|
import * as pu from "./price-utils";
|
|
14
15
|
import { TokenBucketRateLimiter } from "./rate-limiter";
|
|
16
|
+
import * as riskNs from "./risk-metrics";
|
|
17
|
+
import * as strategyNs from "./strategy-metrics";
|
|
15
18
|
import * as ta from "./technical-analysis";
|
|
16
19
|
import * as tu from "./time-utils";
|
|
17
20
|
import * as Types from "./types";
|
|
21
|
+
import * as volatilityNs from "./volatility";
|
|
18
22
|
export { getLogger, resetLogger, setLogger, type Logger } from "./logger";
|
|
19
23
|
export { AdapticUtilsError, AlpacaApiError, AlphaVantageError, AuthenticationError, DataFormatError, HttpClientError, HttpServerError, MassiveApiError, NetworkError, RateLimitError, TimeoutError, ValidationError, WebSocketError, } from "./errors";
|
|
20
24
|
export { validateAlpacaCredentials, validateAlphaVantageApiKey, validateMassiveApiKey, } from "./utils/auth-validator";
|
|
@@ -22,6 +26,7 @@ export { MARKET_DATA_API, TRADING_API, WEBSOCKET_STREAMS, getCryptoStreamUrl, ge
|
|
|
22
26
|
export { DEFAULT_CACHE_OPTIONS, StampedeProtectedCache, createStampedeProtectedCache, type CacheEntry, type CacheLoader, type CacheStats, type StampedeProtectedCacheOptions, } from "./cache/stampede-protected-cache";
|
|
23
27
|
export { TokenBucketRateLimiter, rateLimiters, type RateLimiterConfig, } from "./rate-limiter";
|
|
24
28
|
export { API_RETRY_CONFIGS, isTransientNetworkError, withRetry, type RetryConfig, } from "./utils/retry";
|
|
29
|
+
export { CircuitOpenError } from "./misc-utils";
|
|
25
30
|
export { DEFAULT_TIMEOUTS, createTimeoutSignal, getTimeout, withTimeout, } from "./http-timeout";
|
|
26
31
|
export { AssetAllocationEngine, generateOptimalAllocation, getDefaultRiskProfile, } from "./asset-allocation-algorithm";
|
|
27
32
|
export * from "./types/asset-allocation-types";
|
|
@@ -36,12 +41,20 @@ export declare const createAlpacaTradingAPI: (credentials: Types.AlpacaCredentia
|
|
|
36
41
|
export declare const createAlpacaMarketDataAPI: () => AlpacaMarketDataAPI;
|
|
37
42
|
export * from "./alpaca";
|
|
38
43
|
export * as tradingPolicy from "./trading-policy";
|
|
44
|
+
export * as atr from "./atr";
|
|
45
|
+
export * as volatility from "./volatility";
|
|
46
|
+
export * as risk from "./risk-metrics";
|
|
47
|
+
export * as strategy from "./strategy-metrics";
|
|
39
48
|
export { AutonomyMode, OverlayType, OverlaySeverity, OverlayStatus, DecisionOutcome, DecisionRecordStatus, DecisionMemoryOutcome, LlmProvider, } from "./trading-policy/enums";
|
|
40
49
|
export type { AutonomyPrefs, AssetUniversePrefs, RiskBudgetPrefs, SignalConsumptionPrefs, ExecutionPrefs, PositionManagementPrefs, PortfolioConstructionPrefs, OverlayResponsePrefs, ModelPrefs, AuditNotificationPrefs, PolicyMutation, EffectiveTradingPolicy, } from "./trading-policy/schemas";
|
|
41
50
|
export { DEFAULT_TRADING_POLICY } from "./trading-policy/defaults/default-trading-policy";
|
|
42
51
|
export type { TokenProvider } from "./adaptic";
|
|
43
52
|
export declare const adaptic: {
|
|
44
53
|
types: typeof Types;
|
|
54
|
+
atr: typeof atrNs;
|
|
55
|
+
risk: typeof riskNs;
|
|
56
|
+
strategy: typeof strategyNs;
|
|
57
|
+
volatility: typeof volatilityNs;
|
|
45
58
|
backend: {
|
|
46
59
|
fetchAssetOverview: (symbol: string) => Promise<Types.AssetOverviewResponse>;
|
|
47
60
|
getApolloClient: () => Promise<import("@apollo/client").ApolloClient<import("@apollo/client").NormalizedCacheObject>>;
|
|
@@ -348,7 +361,7 @@ export declare const adaptic: {
|
|
|
348
361
|
apiKey?: string;
|
|
349
362
|
}) => Promise<Types.MassiveIndicesSnapshotResponse>;
|
|
350
363
|
fetchUniversalSnapshot: (tickers: string[], options?: {
|
|
351
|
-
apiKey
|
|
364
|
+
apiKey?: string;
|
|
352
365
|
type?: string;
|
|
353
366
|
order?: string;
|
|
354
367
|
limit?: number;
|
|
@@ -412,6 +425,17 @@ export declare const adaptic: {
|
|
|
412
425
|
logIfDebug: (message: string, data?: unknown, type?: "error" | "info" | "warn" | "debug" | "trace") => void;
|
|
413
426
|
fetchWithRetry: typeof misc.fetchWithRetry;
|
|
414
427
|
validateMassiveApiKey: typeof misc.validateMassiveApiKey;
|
|
428
|
+
/**
|
|
429
|
+
* Force-close a stuck-open per-host circuit breaker. Operator
|
|
430
|
+
* runbook utility — see {@link misc.resetCircuitBreaker}.
|
|
431
|
+
*/
|
|
432
|
+
resetCircuitBreaker: typeof misc.resetCircuitBreaker;
|
|
433
|
+
/**
|
|
434
|
+
* Read-only snapshot of all per-host circuit-breaker states for
|
|
435
|
+
* use in operational-truth endpoints. See
|
|
436
|
+
* {@link misc.getCircuitBreakerSnapshot}.
|
|
437
|
+
*/
|
|
438
|
+
getCircuitBreakerSnapshot: typeof misc.getCircuitBreakerSnapshot;
|
|
415
439
|
};
|
|
416
440
|
rateLimiter: {
|
|
417
441
|
TokenBucketRateLimiter: typeof TokenBucketRateLimiter;
|
|
@@ -424,6 +448,10 @@ export declare const adaptic: {
|
|
|
424
448
|
};
|
|
425
449
|
export declare const adptc: {
|
|
426
450
|
types: typeof Types;
|
|
451
|
+
atr: typeof atrNs;
|
|
452
|
+
risk: typeof riskNs;
|
|
453
|
+
strategy: typeof strategyNs;
|
|
454
|
+
volatility: typeof volatilityNs;
|
|
427
455
|
backend: {
|
|
428
456
|
fetchAssetOverview: (symbol: string) => Promise<Types.AssetOverviewResponse>;
|
|
429
457
|
getApolloClient: () => Promise<import("@apollo/client").ApolloClient<import("@apollo/client").NormalizedCacheObject>>;
|
|
@@ -730,7 +758,7 @@ export declare const adptc: {
|
|
|
730
758
|
apiKey?: string;
|
|
731
759
|
}) => Promise<Types.MassiveIndicesSnapshotResponse>;
|
|
732
760
|
fetchUniversalSnapshot: (tickers: string[], options?: {
|
|
733
|
-
apiKey
|
|
761
|
+
apiKey?: string;
|
|
734
762
|
type?: string;
|
|
735
763
|
order?: string;
|
|
736
764
|
limit?: number;
|
|
@@ -794,6 +822,17 @@ export declare const adptc: {
|
|
|
794
822
|
logIfDebug: (message: string, data?: unknown, type?: "error" | "info" | "warn" | "debug" | "trace") => void;
|
|
795
823
|
fetchWithRetry: typeof misc.fetchWithRetry;
|
|
796
824
|
validateMassiveApiKey: typeof misc.validateMassiveApiKey;
|
|
825
|
+
/**
|
|
826
|
+
* Force-close a stuck-open per-host circuit breaker. Operator
|
|
827
|
+
* runbook utility — see {@link misc.resetCircuitBreaker}.
|
|
828
|
+
*/
|
|
829
|
+
resetCircuitBreaker: typeof misc.resetCircuitBreaker;
|
|
830
|
+
/**
|
|
831
|
+
* Read-only snapshot of all per-host circuit-breaker states for
|
|
832
|
+
* use in operational-truth endpoints. See
|
|
833
|
+
* {@link misc.getCircuitBreakerSnapshot}.
|
|
834
|
+
*/
|
|
835
|
+
getCircuitBreakerSnapshot: typeof misc.getCircuitBreakerSnapshot;
|
|
797
836
|
};
|
|
798
837
|
rateLimiter: {
|
|
799
838
|
TokenBucketRateLimiter: typeof TokenBucketRateLimiter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,iBAAiB,MAAM,i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suppression is in effect.
|
|
4
|
+
*
|
|
5
|
+
* Carries the host, the failure ratio that tripped the breaker, and
|
|
6
|
+
* the remaining cooldown so callers can render an actionable log.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CircuitOpenError extends Error {
|
|
9
|
+
readonly code = "MASSIVE_CIRCUIT_OPEN";
|
|
10
|
+
readonly host: string;
|
|
11
|
+
readonly tripFailureRatio: number;
|
|
12
|
+
readonly cooldownRemainingMs: number;
|
|
13
|
+
constructor(host: string, tripFailureRatio: number, cooldownRemainingMs: number);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Force-close the breaker for a given host. Exposed for tests and
|
|
17
|
+
* operator-runbook scripts so a stuck-open breaker can be reset
|
|
18
|
+
* without bouncing the process. Not intended for hot-path use.
|
|
19
|
+
*
|
|
20
|
+
* @param host The hostname whose breaker should be reset.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resetCircuitBreaker(host: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Snapshot of all known per-host circuit-breaker states. Intended for
|
|
25
|
+
* an operational-truth / status endpoint to surface upstream health.
|
|
26
|
+
*
|
|
27
|
+
* @returns Map of host → {open, openedAt, recentSamples, failureRatio,
|
|
28
|
+
* lastTripFailureRatio}.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCircuitBreakerSnapshot(): Record<string, {
|
|
31
|
+
open: boolean;
|
|
32
|
+
openedAt: number;
|
|
33
|
+
cooldownRemainingMs: number;
|
|
34
|
+
recentSamples: number;
|
|
35
|
+
failureRatio: number;
|
|
36
|
+
lastTripFailureRatio: number;
|
|
37
|
+
}>;
|
|
1
38
|
declare const _LOG_TYPES: readonly ["info", "warn", "error", "debug", "trace"];
|
|
2
39
|
type LogType = (typeof _LOG_TYPES)[number];
|
|
3
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc-utils.d.ts","sourceRoot":"","sources":["../../src/misc-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":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nB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB5E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VaR, Expected Shortfall (CVaR), conditional drawdown, rolling drawdown, Sortino, Calmar.
|
|
3
|
+
*
|
|
4
|
+
* Convention: VaR and ES are returned as the actual quantile value (typically negative
|
|
5
|
+
* for losses). Drawdowns from `calculateConditionalDrawdown` are returned as non-negative
|
|
6
|
+
* magnitudes (e.g., 0.05 = 5% drawdown). Drawdowns from `calculateRollingDrawdown` are
|
|
7
|
+
* non-positive (e.g., -0.05 = 5% below rolling peak, 0 = at or above peak).
|
|
8
|
+
*
|
|
9
|
+
* All public functions reject non-finite inputs (NaN, Infinity) by throwing. Callers
|
|
10
|
+
* must pre-validate or filter their inputs.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Historical-bootstrap VaR at confidence `alpha`.
|
|
14
|
+
* E.g., alpha=0.95 returns the 5%-quantile of returns (the loss at the 5th percentile).
|
|
15
|
+
*
|
|
16
|
+
* @returns The quantile value (typically negative), or null on empty input.
|
|
17
|
+
*/
|
|
18
|
+
export declare function calculateVaRHistorical(returns: number[], alpha: number): number | null;
|
|
19
|
+
/**
|
|
20
|
+
* Gaussian parametric VaR: μ + zα·σ where zα is the (1-alpha) standard-normal quantile.
|
|
21
|
+
*
|
|
22
|
+
* @returns The Gaussian quantile, or null when fewer than 2 samples.
|
|
23
|
+
*/
|
|
24
|
+
export declare function calculateVaRParametric(returns: number[], alpha: number): number | null;
|
|
25
|
+
/**
|
|
26
|
+
* Expected Shortfall (Conditional VaR): average of returns below the (1-alpha) quantile.
|
|
27
|
+
*
|
|
28
|
+
* @returns The mean tail return (typically negative), or null on empty input.
|
|
29
|
+
*/
|
|
30
|
+
export declare function calculateExpectedShortfall(returns: number[], alpha: number): number | null;
|
|
31
|
+
/**
|
|
32
|
+
* Conditional Drawdown at Risk (CDaR): average of drawdowns in the worst (1-alpha) tail.
|
|
33
|
+
* Drawdowns are computed as (peak - equity) / peak so they are non-negative.
|
|
34
|
+
*
|
|
35
|
+
* @returns A non-negative magnitude (0 = no drawdowns), or null for fewer than 2 samples.
|
|
36
|
+
*/
|
|
37
|
+
export declare function calculateConditionalDrawdown(equity: number[], alpha: number): number | null;
|
|
38
|
+
/**
|
|
39
|
+
* Rolling-window drawdown series: for each index, drawdown = (current - rollingPeak) / rollingPeak.
|
|
40
|
+
* Non-positive values; 0 when at or above the rolling peak. Window measured in samples.
|
|
41
|
+
*
|
|
42
|
+
* @returns An array the same length as `equity`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function calculateRollingDrawdown(equity: number[], windowSize: number): number[];
|
|
45
|
+
/**
|
|
46
|
+
* Sortino ratio: (mean excess return) / downside deviation.
|
|
47
|
+
* Returns +Infinity when there are no downside returns.
|
|
48
|
+
* Returns null when fewer than 2 samples.
|
|
49
|
+
*/
|
|
50
|
+
export declare function calculateSortino(returns: number[], riskFreeRate: number): number | null;
|
|
51
|
+
/**
|
|
52
|
+
* Calmar ratio: CAGR / |max drawdown|.
|
|
53
|
+
*
|
|
54
|
+
* @returns null when there is no drawdown (division by zero), fewer than 2 samples,
|
|
55
|
+
* or `equity[0] <= 0` (CAGR undefined).
|
|
56
|
+
*/
|
|
57
|
+
export declare function calculateCalmar(equity: number[], periodsPerYear: number): number | null;
|
|
58
|
+
//# sourceMappingURL=risk-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk-metrics.d.ts","sourceRoot":"","sources":["../../src/risk-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgBH;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,IAAI,CAOf;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,IAAI,CAUf;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,IAAI,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,EAAE,EAChB,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,IAAI,CAef;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EAAE,EAChB,UAAU,EAAE,MAAM,GACjB,MAAM,EAAE,CAWV;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,GAAG,IAAI,CASf;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAmBvF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-strategy rolling metrics and backtest-divergence z-score.
|
|
3
|
+
*
|
|
4
|
+
* Conventions:
|
|
5
|
+
* - tradePnls / tradeReturns is an array of per-trade realised P&L or return
|
|
6
|
+
* (positive = win, negative = loss, zero = breakeven).
|
|
7
|
+
* - All "rolling*" functions return null when fewer than `windowSize` trades exist.
|
|
8
|
+
* - All public functions reject non-finite inputs (NaN, Infinity) by throwing.
|
|
9
|
+
* Callers must pre-validate or filter their inputs.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Rolling expectancy: mean P&L over the most-recent `windowSize` trades.
|
|
13
|
+
*
|
|
14
|
+
* @param tradePnls - Array of per-trade realised P&L values.
|
|
15
|
+
* @param windowSize - Number of most-recent trades to include. Must be a positive integer.
|
|
16
|
+
* @returns Mean P&L of the last `windowSize` trades, or null when fewer than `windowSize` exist.
|
|
17
|
+
* @throws When `windowSize` is not a positive integer or any input is non-finite.
|
|
18
|
+
*/
|
|
19
|
+
export declare function calculateRollingExpectancy(tradePnls: number[], windowSize: number): number | null;
|
|
20
|
+
/**
|
|
21
|
+
* Rolling hit-rate: fraction of strictly-positive P&L trades in the most-recent
|
|
22
|
+
* `windowSize` trades. Zero P&L counts as non-win.
|
|
23
|
+
*
|
|
24
|
+
* @param tradePnls - Array of per-trade realised P&L values.
|
|
25
|
+
* @param windowSize - Number of most-recent trades to include. Must be a positive integer.
|
|
26
|
+
* @returns Fraction of winning trades in the window, or null when fewer than `windowSize` exist.
|
|
27
|
+
* @throws When `windowSize` is not a positive integer or any input is non-finite.
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateRollingHitRate(tradePnls: number[], windowSize: number): number | null;
|
|
30
|
+
/**
|
|
31
|
+
* Rolling profit factor: sum(wins) / |sum(losses)| over the most-recent `windowSize` trades.
|
|
32
|
+
*
|
|
33
|
+
* Edge cases:
|
|
34
|
+
* - no losses and at least one win → +Infinity
|
|
35
|
+
* - no wins and no losses (all zeros) → 0
|
|
36
|
+
* - fewer than windowSize trades → null
|
|
37
|
+
*
|
|
38
|
+
* @param tradePnls - Array of per-trade realised P&L values.
|
|
39
|
+
* @param windowSize - Number of most-recent trades to include. Must be a positive integer.
|
|
40
|
+
* @returns Profit factor for the rolling window, or null when fewer than `windowSize` exist.
|
|
41
|
+
* @throws When `windowSize` is not a positive integer or any input is non-finite.
|
|
42
|
+
*/
|
|
43
|
+
export declare function calculateRollingProfitFactor(tradePnls: number[], windowSize: number): number | null;
|
|
44
|
+
/**
|
|
45
|
+
* Rolling Sortino: delegate to `calculateSortino` over the most-recent `windowSize` returns.
|
|
46
|
+
*
|
|
47
|
+
* @param tradeReturns - Array of per-trade return values.
|
|
48
|
+
* @param windowSize - Number of most-recent trades to include. Must be a positive integer.
|
|
49
|
+
* @param riskFreeRate - Risk-free rate to subtract from returns (default 0).
|
|
50
|
+
* @returns Sortino ratio for the rolling window, or null when fewer than `windowSize` exist.
|
|
51
|
+
* @throws When `windowSize` is not a positive integer or any input is non-finite.
|
|
52
|
+
*/
|
|
53
|
+
export declare function calculateRollingSortino(tradeReturns: number[], windowSize: number, riskFreeRate?: number): number | null;
|
|
54
|
+
/**
|
|
55
|
+
* Z-score of live-expectancy vs backtest-expectancy, scaled by the backtest stddev.
|
|
56
|
+
* Positive Z = live outperforming; negative Z = live underperforming.
|
|
57
|
+
*
|
|
58
|
+
* @param liveExpectancy - Mean P&L per trade in the live window.
|
|
59
|
+
* @param backtestExpectancy - Mean P&L per trade from the calibration backtest.
|
|
60
|
+
* @param backtestStddev - Stddev of per-trade P&L in the backtest. Must be > 0.
|
|
61
|
+
* @returns Z-score measuring divergence between live and backtest performance.
|
|
62
|
+
* @throws When any input is non-finite or `backtestStddev` is not positive.
|
|
63
|
+
*/
|
|
64
|
+
export declare function calculateBacktestDivergenceZ(liveExpectancy: number, backtestExpectancy: number, backtestStddev: number): number;
|
|
65
|
+
//# sourceMappingURL=strategy-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-metrics.d.ts","sourceRoot":"","sources":["../../src/strategy-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkBH;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EAAE,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CAMf;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EAAE,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CAOf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CASf;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EAAE,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,SAAI,GACf,MAAM,GAAG,IAAI,CAKf;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,MAAM,EAC1B,cAAc,EAAE,MAAM,GACrB,MAAM,CAQR"}
|
|
@@ -529,7 +529,7 @@ export declare const EffectiveTradingPolicySchema: z.ZodObject<{
|
|
|
529
529
|
partialFillPolicy: "accept_partial" | "cancel_remainder" | "replace_to_fill";
|
|
530
530
|
sizingMethod: "notional" | "quantity";
|
|
531
531
|
lotRoundingBehavior: "round_down" | "round_nearest" | "round_up";
|
|
532
|
-
afterHoursExecutionBehavior: "
|
|
532
|
+
afterHoursExecutionBehavior: "normal" | "limit_only" | "no_execution";
|
|
533
533
|
failureBehavior: "fail_safe" | "fail_open";
|
|
534
534
|
}, {
|
|
535
535
|
allowedOrderTypes?: ("limit" | "market" | "stop" | "stop_limit" | "trailing_stop")[] | undefined;
|
|
@@ -547,7 +547,7 @@ export declare const EffectiveTradingPolicySchema: z.ZodObject<{
|
|
|
547
547
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
548
548
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
549
549
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
550
|
-
afterHoursExecutionBehavior?: "
|
|
550
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
551
551
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
552
552
|
}>>;
|
|
553
553
|
positionManagementPrefs: z.ZodDefault<z.ZodObject<{
|
|
@@ -1216,7 +1216,7 @@ export declare const EffectiveTradingPolicySchema: z.ZodObject<{
|
|
|
1216
1216
|
partialFillPolicy: "accept_partial" | "cancel_remainder" | "replace_to_fill";
|
|
1217
1217
|
sizingMethod: "notional" | "quantity";
|
|
1218
1218
|
lotRoundingBehavior: "round_down" | "round_nearest" | "round_up";
|
|
1219
|
-
afterHoursExecutionBehavior: "
|
|
1219
|
+
afterHoursExecutionBehavior: "normal" | "limit_only" | "no_execution";
|
|
1220
1220
|
failureBehavior: "fail_safe" | "fail_open";
|
|
1221
1221
|
};
|
|
1222
1222
|
positionManagementPrefs: {
|
|
@@ -1553,7 +1553,7 @@ export declare const EffectiveTradingPolicySchema: z.ZodObject<{
|
|
|
1553
1553
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
1554
1554
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
1555
1555
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
1556
|
-
afterHoursExecutionBehavior?: "
|
|
1556
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
1557
1557
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
1558
1558
|
} | undefined;
|
|
1559
1559
|
positionManagementPrefs?: {
|
|
@@ -41,7 +41,7 @@ export declare const ExecutionPrefsObjectSchema: z.ZodObject<{
|
|
|
41
41
|
partialFillPolicy: "accept_partial" | "cancel_remainder" | "replace_to_fill";
|
|
42
42
|
sizingMethod: "notional" | "quantity";
|
|
43
43
|
lotRoundingBehavior: "round_down" | "round_nearest" | "round_up";
|
|
44
|
-
afterHoursExecutionBehavior: "
|
|
44
|
+
afterHoursExecutionBehavior: "normal" | "limit_only" | "no_execution";
|
|
45
45
|
failureBehavior: "fail_safe" | "fail_open";
|
|
46
46
|
}, {
|
|
47
47
|
allowedOrderTypes?: ("limit" | "market" | "stop" | "stop_limit" | "trailing_stop")[] | undefined;
|
|
@@ -59,7 +59,7 @@ export declare const ExecutionPrefsObjectSchema: z.ZodObject<{
|
|
|
59
59
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
60
60
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
61
61
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
62
|
-
afterHoursExecutionBehavior?: "
|
|
62
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
63
63
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
64
64
|
}>;
|
|
65
65
|
export declare const ExecutionPrefsSchema: z.ZodDefault<z.ZodObject<{
|
|
@@ -96,7 +96,7 @@ export declare const ExecutionPrefsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
96
96
|
partialFillPolicy: "accept_partial" | "cancel_remainder" | "replace_to_fill";
|
|
97
97
|
sizingMethod: "notional" | "quantity";
|
|
98
98
|
lotRoundingBehavior: "round_down" | "round_nearest" | "round_up";
|
|
99
|
-
afterHoursExecutionBehavior: "
|
|
99
|
+
afterHoursExecutionBehavior: "normal" | "limit_only" | "no_execution";
|
|
100
100
|
failureBehavior: "fail_safe" | "fail_open";
|
|
101
101
|
}, {
|
|
102
102
|
allowedOrderTypes?: ("limit" | "market" | "stop" | "stop_limit" | "trailing_stop")[] | undefined;
|
|
@@ -114,7 +114,7 @@ export declare const ExecutionPrefsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
114
114
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
115
115
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
116
116
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
117
|
-
afterHoursExecutionBehavior?: "
|
|
117
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
118
118
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
119
119
|
}>>;
|
|
120
120
|
/** Inferred TypeScript type for execution preferences. */
|
|
@@ -497,7 +497,7 @@ export declare const PolicyMutationSchema: z.ZodObject<{
|
|
|
497
497
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
498
498
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
499
499
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
500
|
-
afterHoursExecutionBehavior?: "
|
|
500
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
501
501
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
502
502
|
}, {
|
|
503
503
|
allowedOrderTypes?: ("limit" | "market" | "stop" | "stop_limit" | "trailing_stop")[] | undefined;
|
|
@@ -515,7 +515,7 @@ export declare const PolicyMutationSchema: z.ZodObject<{
|
|
|
515
515
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
516
516
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
517
517
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
518
|
-
afterHoursExecutionBehavior?: "
|
|
518
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
519
519
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
520
520
|
}>>;
|
|
521
521
|
positionManagementPrefs: z.ZodOptional<z.ZodObject<{
|
|
@@ -1503,7 +1503,7 @@ export declare const PolicyMutationSchema: z.ZodObject<{
|
|
|
1503
1503
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
1504
1504
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
1505
1505
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
1506
|
-
afterHoursExecutionBehavior?: "
|
|
1506
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
1507
1507
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
1508
1508
|
}, {
|
|
1509
1509
|
allowedOrderTypes?: ("limit" | "market" | "stop" | "stop_limit" | "trailing_stop")[] | undefined;
|
|
@@ -1521,7 +1521,7 @@ export declare const PolicyMutationSchema: z.ZodObject<{
|
|
|
1521
1521
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
1522
1522
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
1523
1523
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
1524
|
-
afterHoursExecutionBehavior?: "
|
|
1524
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
1525
1525
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
1526
1526
|
}>>;
|
|
1527
1527
|
positionManagementPrefs: z.ZodOptional<z.ZodObject<{
|
|
@@ -2509,7 +2509,7 @@ export declare const PolicyMutationSchema: z.ZodObject<{
|
|
|
2509
2509
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
2510
2510
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
2511
2511
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
2512
|
-
afterHoursExecutionBehavior?: "
|
|
2512
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
2513
2513
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
2514
2514
|
}, {
|
|
2515
2515
|
allowedOrderTypes?: ("limit" | "market" | "stop" | "stop_limit" | "trailing_stop")[] | undefined;
|
|
@@ -2527,7 +2527,7 @@ export declare const PolicyMutationSchema: z.ZodObject<{
|
|
|
2527
2527
|
partialFillPolicy?: "accept_partial" | "cancel_remainder" | "replace_to_fill" | undefined;
|
|
2528
2528
|
sizingMethod?: "notional" | "quantity" | undefined;
|
|
2529
2529
|
lotRoundingBehavior?: "round_down" | "round_nearest" | "round_up" | undefined;
|
|
2530
|
-
afterHoursExecutionBehavior?: "
|
|
2530
|
+
afterHoursExecutionBehavior?: "normal" | "limit_only" | "no_execution" | undefined;
|
|
2531
2531
|
failureBehavior?: "fail_safe" | "fail_open" | undefined;
|
|
2532
2532
|
}>>;
|
|
2533
2533
|
positionManagementPrefs: z.ZodOptional<z.ZodObject<{
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Realized and EWMA volatility + regime classifier + annualisation helper.
|
|
3
|
+
* All functions pure.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Volatility regime categorisation: calm (quiet markets), normal (regular trading),
|
|
7
|
+
* elevated (above-average volatility), crisis (panic/stress regime).
|
|
8
|
+
*/
|
|
9
|
+
export type VolatilityRegime = "calm" | "normal" | "elevated" | "crisis";
|
|
10
|
+
/**
|
|
11
|
+
* Threshold bands for classifying a volatility value into a {@link VolatilityRegime}.
|
|
12
|
+
*
|
|
13
|
+
* Invariant: `calmMax < elevatedMax < crisisMin` (enforced at runtime by
|
|
14
|
+
* {@link detectVolatilityRegime}).
|
|
15
|
+
*/
|
|
16
|
+
export interface RegimeBands {
|
|
17
|
+
/** Volatility at or below this is "calm". */
|
|
18
|
+
calmMax: number;
|
|
19
|
+
/** Volatility at or above this (but below crisisMin) is "elevated". */
|
|
20
|
+
elevatedMax: number;
|
|
21
|
+
/** Volatility at or above this is "crisis". */
|
|
22
|
+
crisisMin: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sample standard deviation (Bessel-corrected) of returns over the most recent
|
|
26
|
+
* `window` samples.
|
|
27
|
+
* @returns null when fewer than `window` samples.
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateRealizedVolatility(returns: number[], window: number): number | null;
|
|
30
|
+
/**
|
|
31
|
+
* EWMA volatility (RiskMetrics-style). λ ∈ (0,1); higher = longer memory.
|
|
32
|
+
* Default usage: λ = 0.94 for daily returns.
|
|
33
|
+
*
|
|
34
|
+
* For a single-element input, the function returns `|returns[0]|` (the seed)
|
|
35
|
+
* since no smoothing iterations are possible.
|
|
36
|
+
*
|
|
37
|
+
* @param returns - Period returns (e.g., log returns or simple returns).
|
|
38
|
+
* @param lambda - Decay factor in (0,1).
|
|
39
|
+
* @returns EWMA standard deviation, or null on empty input.
|
|
40
|
+
* @throws when `lambda` is outside (0,1).
|
|
41
|
+
*/
|
|
42
|
+
export declare function calculateEWMAVolatility(returns: number[], lambda: number): number | null;
|
|
43
|
+
/**
|
|
44
|
+
* Classify a volatility value into one of four regimes.
|
|
45
|
+
*
|
|
46
|
+
* Bands are checked in the order: crisis (≥crisisMin) → elevated (≥elevatedMax)
|
|
47
|
+
* → calm (≤calmMax) → normal (otherwise).
|
|
48
|
+
*
|
|
49
|
+
* @throws when bands are not strictly ordered (calmMax < elevatedMax < crisisMin).
|
|
50
|
+
*/
|
|
51
|
+
export declare function detectVolatilityRegime(volatility: number, bands: RegimeBands): VolatilityRegime;
|
|
52
|
+
/**
|
|
53
|
+
* Annualise a volatility computed at the given cadence by multiplying by
|
|
54
|
+
* the square root of the periods per year.
|
|
55
|
+
*
|
|
56
|
+
* - daily → sqrt(252) (252 trading days per year)
|
|
57
|
+
* - hourly → sqrt(252 × 6.5) (6.5 RTH hours per trading day)
|
|
58
|
+
* - minute → sqrt(252 × 6.5 × 60) (60 minutes per RTH hour)
|
|
59
|
+
*
|
|
60
|
+
* @param volatility - Per-period volatility (stddev).
|
|
61
|
+
* @param cadence - The cadence at which `volatility` was sampled.
|
|
62
|
+
* @returns The annualised volatility.
|
|
63
|
+
*/
|
|
64
|
+
export declare function annualiseVolatility(volatility: number, cadence: "daily" | "hourly" | "minute"): number;
|
|
65
|
+
//# sourceMappingURL=volatility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volatility.d.ts","sourceRoot":"","sources":["../../src/volatility.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAUf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAUf;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,WAAW,GACjB,gBAAgB,CAUlB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GACrC,MAAM,CAMR"}
|