nexustrade 0.1.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.
@@ -0,0 +1,1328 @@
1
+ export interface Asset {
2
+ type: AssetType;
3
+ symbol: string;
4
+ name?: string;
5
+ }
6
+ /** Bind to the current pipeline candidate. Never spelled as an omitted field. */
7
+ export type Candidate = {
8
+ readonly __candidate: true;
9
+ };
10
+ /**
11
+ * Explicit empty `targetAssets: []` — portfolio-wide scope (any name in the book).
12
+ * Correct for rebalance / DynamicRebalance cadence. Wrong for per-ticker DCA.
13
+ */
14
+ export type PortfolioWide = {
15
+ readonly __portfolioWide: true;
16
+ };
17
+ /** Concrete assets must be built with stockAsset() / cryptoAsset() — no bare ticker strings. */
18
+ export type AssetArg = Asset | Candidate | PortfolioWide;
19
+ /**
20
+ * Opaque: indicators are only ever constructed through the builders below.
21
+ * Candidate* brands use a unique symbol (not a string key) so they are not
22
+ * defeated by the `[key: string]: unknown` index signature — strategy() can
23
+ * reject candidate-bound gates while filter()/eligibility still accept them.
24
+ */
25
+ export interface Indicator {
26
+ type: string;
27
+ [key: string]: unknown;
28
+ }
29
+ export interface Condition {
30
+ type: string;
31
+ [key: string]: unknown;
32
+ }
33
+ declare const candidateBound: unique symbol;
34
+ /** Indicator bound to the pipeline candidate (Price(CANDIDATE), …). */
35
+ export type CandidateIndicator = Indicator & {
36
+ readonly [candidateBound]: true;
37
+ };
38
+ /** Condition that transitively contains a CandidateIndicator. */
39
+ export type CandidateCondition = Condition & {
40
+ readonly [candidateBound]: true;
41
+ };
42
+ /**
43
+ * Book-level condition for strategy(when) / sessionFlatten.
44
+ * CandidateCondition is not assignable here (symbol brand vs never).
45
+ */
46
+ export type StrategyCondition = Condition & {
47
+ readonly [candidateBound]?: never;
48
+ };
49
+ export type PipelineStage = {
50
+ type: "Filter";
51
+ condition: Condition | CandidateCondition;
52
+ } | {
53
+ type: "SelectTop";
54
+ metric: Indicator | CandidateIndicator;
55
+ limit: number;
56
+ direction: SelectDirection;
57
+ } | {
58
+ type: "SelectPercentile";
59
+ metric: Indicator | CandidateIndicator;
60
+ percentile: number;
61
+ direction: SelectDirection;
62
+ };
63
+ /**
64
+ * Discriminated like UniverseConfig: SPECIFIC_ASSETS REQUIRES assets, and the
65
+ * broad sources take none. A flat `{source, assets?}` would let a model author
66
+ * SPECIFIC_ASSETS with an empty universe (a silent zero-trade book) or attach
67
+ * assets to CRYPTO, both of which the real type forbids.
68
+ */
69
+ export type Universe = {
70
+ source: "ALL_US_STOCKS" | "SP500" | "NASDAQ100" | "DJIA" | "CRYPTO";
71
+ } | {
72
+ source: "SPECIFIC_ASSETS";
73
+ assets: Asset[];
74
+ };
75
+ export interface Allocation {
76
+ type: AllocationType;
77
+ amount: number;
78
+ }
79
+ export interface DepositWithdrawAllocation {
80
+ type: DepositWithdrawAllocationType;
81
+ amount: number;
82
+ }
83
+ export interface OptionAllocation {
84
+ type: OptionAllocationType;
85
+ amount: number;
86
+ }
87
+ /** DynamicRebalance per-name cap: contracts and buying-power percent are rejected. */
88
+ export interface PerNameAllocation {
89
+ type: "percent of portfolio" | "dollars";
90
+ amount: number;
91
+ }
92
+ export interface DeploymentBudget {
93
+ type: DeploymentBudgetType;
94
+ amount: number;
95
+ }
96
+ export interface ExpirationSelector {
97
+ minDaysToExpiration: number;
98
+ maxDaysToExpiration: number;
99
+ preference: ExpirationPreference;
100
+ }
101
+ /** Calls: positive distance = OTM (higher strike). Puts: positive = OTM (lower strike). 0 = ATM. Delta = absolute target delta. */
102
+ export interface StrikeSelector {
103
+ distanceType: StrikeDistanceType;
104
+ distance: number;
105
+ }
106
+ /** Search window when the primary strike is unaffordable / missing. */
107
+ export interface StrikeRange {
108
+ startDistance: number;
109
+ endDistance: number;
110
+ iteration: StrikeRangeIteration;
111
+ }
112
+ /** Search window when the primary expiration is unaffordable / missing. */
113
+ export interface ExpirationRange {
114
+ minDte: number;
115
+ maxDte: number;
116
+ iteration: ExpirationRangeIteration;
117
+ }
118
+ /** Optional Greek bounds applied during contract resolution. */
119
+ export interface GreekFilter {
120
+ minIv?: number;
121
+ maxIv?: number;
122
+ minDelta?: number;
123
+ maxDelta?: number;
124
+ minGamma?: number;
125
+ maxGamma?: number;
126
+ minTheta?: number;
127
+ maxTheta?: number;
128
+ minVega?: number;
129
+ maxVega?: number;
130
+ minRho?: number;
131
+ maxRho?: number;
132
+ }
133
+ export interface OptionsBuilderLeg {
134
+ optionType: OptionType;
135
+ direction: OptionDirection;
136
+ expirationSelector: ExpirationSelector;
137
+ strikeSelector: StrikeSelector;
138
+ /** Non-delta fallback when strikeSelector.distanceType is "delta". */
139
+ fallbackStrikeSelector?: StrikeSelector;
140
+ strikeRange?: StrikeRange;
141
+ expirationRange?: ExpirationRange;
142
+ ratio?: number;
143
+ greekFilter?: GreekFilter;
144
+ }
145
+ /** Shared fields for `leg(...)` (discriminated on distanceType). */
146
+ export type LegConfigBase = {
147
+ optionType: OptionType;
148
+ direction: OptionDirection;
149
+ minDaysToExpiration: number;
150
+ maxDaysToExpiration: number;
151
+ preference?: ExpirationPreference;
152
+ strikeRange?: StrikeRange;
153
+ expirationRange?: ExpirationRange;
154
+ ratio?: number;
155
+ greekFilter?: GreekFilter;
156
+ };
157
+ /** Percent/dollars strike — fallback optional. */
158
+ export type LegConfigPercentOrDollars = LegConfigBase & {
159
+ distance: number;
160
+ distanceType?: "percent" | "dollars";
161
+ fallbackDistance?: number;
162
+ fallbackDistanceType?: "percent" | "dollars";
163
+ fallbackStrikeSelector?: StrikeSelector;
164
+ };
165
+ /** Delta targeting REQUIRES a non-delta fallback (same contract as YAML). */
166
+ export type LegConfigDelta = LegConfigBase & {
167
+ distance: number;
168
+ distanceType: "delta";
169
+ } & ({
170
+ fallbackDistance: number;
171
+ fallbackDistanceType: "percent" | "dollars";
172
+ fallbackStrikeSelector?: never;
173
+ } | {
174
+ fallbackStrikeSelector: StrikeSelector;
175
+ fallbackDistance?: never;
176
+ fallbackDistanceType?: never;
177
+ });
178
+ export type LegConfig = LegConfigPercentOrDollars | LegConfigDelta;
179
+ export interface DynamicUnderlying {
180
+ universe: Universe;
181
+ pipeline?: PipelineStage[];
182
+ limit?: number;
183
+ }
184
+ export interface OptionsBuilder {
185
+ legs: OptionsBuilderLeg[];
186
+ underlyingSymbol?: string;
187
+ dynamicUnderlying?: DynamicUnderlying;
188
+ spreadType?: OptionSpreadType;
189
+ }
190
+ export interface OptionStructureTemplate {
191
+ legs: OptionsBuilderLeg[];
192
+ name?: string;
193
+ /** May be candidate-bound (evaluated per underlying). */
194
+ eligibility?: Condition | CandidateCondition;
195
+ spreadType?: OptionSpreadType;
196
+ }
197
+ /** Sleeves share the action-level totalBudget and cannot define their own. */
198
+ export interface RebalanceOptionSleeve {
199
+ name: string;
200
+ universe?: Universe;
201
+ pipeline?: PipelineStage[];
202
+ weightIndicator?: Indicator | CandidateIndicator;
203
+ limit?: number;
204
+ perNameAllocation?: OptionAllocation;
205
+ structureTemplates?: OptionStructureTemplate[];
206
+ }
207
+ export type CloseOptionTrigger = {
208
+ type: "pnl";
209
+ minPnlPercent?: number;
210
+ maxPnlPercent?: number;
211
+ } | {
212
+ type: "dte";
213
+ minDte?: number;
214
+ maxDte?: number;
215
+ } | {
216
+ type: "daysHeld";
217
+ minDaysHeld?: number;
218
+ maxDaysHeld?: number;
219
+ } | {
220
+ type: "greeks";
221
+ minSpreadDelta?: number;
222
+ maxSpreadDelta?: number;
223
+ minIv?: number;
224
+ maxIv?: number;
225
+ minSpreadTheta?: number;
226
+ maxSpreadTheta?: number;
227
+ };
228
+ export interface BuyOrSellAction {
229
+ type: "Buy" | "Sell";
230
+ targetAsset: Asset;
231
+ amount: Allocation;
232
+ }
233
+ export interface DepositOrWithdrawAction {
234
+ type: "Deposit" | "Withdraw";
235
+ amount: DepositWithdrawAllocation;
236
+ }
237
+ export interface AlertAction {
238
+ type: "Alert";
239
+ message: string;
240
+ }
241
+ export interface LaunchAgentAction {
242
+ type: "LaunchAgent";
243
+ planningModel: string;
244
+ executionModel: string;
245
+ initialMessage: string;
246
+ maxIterations: number;
247
+ includeMarketData: boolean;
248
+ continueExisting: boolean;
249
+ skipPlanning: boolean;
250
+ cooldownMinutes?: number;
251
+ }
252
+ /** Book-level sizing is deploymentPercent. totalBudget is RebalanceOption-only and absent by design. */
253
+ export interface DynamicRebalanceAction {
254
+ type: "DynamicRebalance";
255
+ universe: Universe;
256
+ pipeline: PipelineStage[];
257
+ weightIndicator: Indicator | CandidateIndicator;
258
+ limit?: number;
259
+ deploymentPercent?: number;
260
+ perNameAllocation?: PerNameAllocation;
261
+ /**
262
+ * Candidate-bound gate on NON-TARGET FULL EXITS only. Omitted = always sell
263
+ * (legacy behavior). Trims of still-selected names are not gated. Unavailable
264
+ * indicator values fail closed (retain). deploymentPercent: 0 overrides.
265
+ */
266
+ canSell?: Condition | CandidateCondition;
267
+ }
268
+ /** Book-level sizing is totalBudget. deploymentPercent is DynamicRebalance-only and absent by design. */
269
+ export interface RebalanceOptionAction {
270
+ type: "RebalanceOption";
271
+ universe: Universe;
272
+ pipeline: PipelineStage[];
273
+ weightIndicator: Indicator | CandidateIndicator;
274
+ structureTemplates: OptionStructureTemplate[];
275
+ limit?: number;
276
+ totalBudget?: DeploymentBudget;
277
+ perNameAllocation?: OptionAllocation;
278
+ positionScope?: RebalanceOptionPositionScope;
279
+ sleeves?: RebalanceOptionSleeve[];
280
+ }
281
+ export type OptionParentSelectionSort = "oldest" | "highestPnl" | "nearestExpiry";
282
+ export type ParentStrikeOffset = {
283
+ type: "amount";
284
+ value: number;
285
+ } | {
286
+ type: "percent";
287
+ value: number;
288
+ };
289
+ /** Parent-position selector for writing a short against an existing long (covered write). */
290
+ export interface OptionPositionSelector {
291
+ underlyings?: string[];
292
+ optionType: OptionType;
293
+ direction: OptionDirection;
294
+ minParentPnlPercent?: number;
295
+ maxParentPnlPercent?: number;
296
+ selection?: {
297
+ sort: OptionParentSelectionSort;
298
+ limit?: number;
299
+ };
300
+ coverageRatio?: number;
301
+ requireShortStrikeAboveParentStrike?: boolean;
302
+ strikeOffsetFromParent?: ParentStrikeOffset;
303
+ }
304
+ export interface OpenOptionAction {
305
+ type: "OpenOption";
306
+ builder: OptionsBuilder;
307
+ allocation?: OptionAllocation;
308
+ against?: OptionPositionSelector;
309
+ }
310
+ export type CloseQuantity = {
311
+ type: "all";
312
+ } | {
313
+ type: "contracts";
314
+ count: number;
315
+ } | {
316
+ type: "percent";
317
+ percent: number;
318
+ };
319
+ /** Position selectors AND together; triggers[] OR together. */
320
+ export interface CloseOptionAction {
321
+ type: "CloseOption";
322
+ underlyings?: string[];
323
+ optionType?: OptionType;
324
+ direction?: OptionDirection;
325
+ spreadType?: OptionSpreadType;
326
+ closeScope?: CloseScope;
327
+ triggers?: CloseOptionTrigger[];
328
+ quantity?: CloseQuantity;
329
+ }
330
+ export type Action = BuyOrSellAction | DepositOrWithdrawAction | AlertAction | LaunchAgentAction | DynamicRebalanceAction | RebalanceOptionAction | OpenOptionAction | CloseOptionAction;
331
+ /**
332
+ * `automaticOrderApproval` is deliberately absent. It is system-managed and always
333
+ * false for agent-created strategies, and placing it on an action fails validation —
334
+ * so exposing it would only let a model author something the server rejects.
335
+ */
336
+ export interface Strategy {
337
+ name: string;
338
+ condition: StrategyCondition;
339
+ action: Action;
340
+ active?: boolean;
341
+ }
342
+ export interface Portfolio {
343
+ name: string;
344
+ initialValue?: number;
345
+ strategies: Strategy[];
346
+ main?: boolean;
347
+ supportsFractionalShares?: boolean;
348
+ supportsCrypto?: boolean;
349
+ alertsEnabled?: boolean;
350
+ }
351
+ export type AssetType = "Stock" | "Cryptocurrency" | "Option" | "Other";
352
+ export type Interval = "Day" | "Hour" | "Minute";
353
+ export type Comparator = "lessThan" | "greaterThan" | "lessThanOrEqual" | "greaterThanOrEqual" | "equal" | "notEqual";
354
+ export type SelectDirection = "Highest" | "Lowest";
355
+ export type UniverseSource = "ALL_US_STOCKS" | "SP500" | "NASDAQ100" | "DJIA" | "CRYPTO" | "SPECIFIC_ASSETS";
356
+ export type AllocationType = "percent of portfolio" | "percent of buying power" | "percent of current positions" | "dollars" | "number of assets";
357
+ export type DepositWithdrawAllocationType = "percent of portfolio" | "percent of buying power" | "dollars";
358
+ export type OptionAllocationType = "dollars" | "percent of portfolio" | "percent of buying power" | "contracts";
359
+ export type DeploymentBudgetType = "dollars" | "percent of portfolio";
360
+ export type ExpirationPreference = "nearest" | "middle" | "furthest";
361
+ export type StrikeDistanceType = "percent" | "dollars" | "delta";
362
+ export type StrikeRangeIteration = "OTMToITM" | "ITMToOTM";
363
+ export type ExpirationRangeIteration = "ShortestFirst" | "LongestFirst";
364
+ export type CloseQuantityType = "all" | "contracts" | "percent";
365
+ export type OptionType = "call" | "put";
366
+ export type OptionDirection = "long" | "short";
367
+ export type OptionSpreadType = "vertical" | "calendar" | "diagonal" | "ironCondor" | "straddle" | "strangle" | "custom";
368
+ export type CloseScope = "spread" | "leg";
369
+ export type RebalanceOptionPositionScope = "portfolio" | "strategy";
370
+ export type FundamentalMetric = "totalRevenue" | "grossProfit" | "operatingIncome" | "ebitda" | "epsActual" | "epsEstimate" | "netIncome" | "freeCashFlow" | "totalAssets" | "totalLiab" | "shortTermDebt" | "longTermDebt" | "commonStockSharesOutstanding" | "dividendYield" | "openingPrice" | "highestPrice" | "lowestPrice" | "closingPrice" | "volume" | "marketCap" | "peRatioTTM" | "psRatioTTM" | "pbRatioTTM" | "enterpriseValue";
371
+ export type PositionEffect = "open" | "close";
372
+ export type OrderStatus = "Pending" | "Accepted" | "Pending User Approval" | "Canceled" | "Filled" | "Partially Filled";
373
+ export type Side = "Buy" | "Sell";
374
+ export type MinOrMax = "min" | "max";
375
+ export declare const CANDIDATE: Candidate;
376
+ /** Portfolio-wide targetAssets: [] — rebalance cadence, not per-ticker DCA. */
377
+ export declare const PORTFOLIO_WIDE: PortfolioWide;
378
+ /** Equity/ETF asset — required for stock/ETF buy/sell/indicators. */
379
+ export declare const stockAsset: (symbol: string) => Asset;
380
+ /** Cryptocurrency asset (BTC → BTC-USD) — required for crypto buy/sell/indicators. */
381
+ export declare const cryptoAsset: (symbol: string) => Asset;
382
+ export declare const gt: (l: Indicator, r: Indicator | number) => Condition;
383
+ export declare const lt: (l: Indicator, r: Indicator | number) => Condition;
384
+ export declare const gte: (l: Indicator, r: Indicator | number) => Condition;
385
+ export declare const lte: (l: Indicator, r: Indicator | number) => Condition;
386
+ export declare const eq: (l: Indicator, r: Indicator | number) => Condition;
387
+ export declare const neq: (l: Indicator, r: Indicator | number) => Condition;
388
+ export declare const and: (...conditions: Condition[]) => Condition;
389
+ export declare const or: (...conditions: Condition[]) => Condition;
390
+ /** Multi: true when at least `count` of `conditions` hold. */
391
+ export declare const atLeast: (count: number, ...conditions: Condition[]) => Condition;
392
+ /** Multi: true when at most `count` of `conditions` hold. */
393
+ export declare const atMost: (count: number, ...conditions: Condition[]) => Condition;
394
+ /** Multi: true when fewer than `count` of `conditions` hold. */
395
+ export declare const fewerThan: (count: number, ...conditions: Condition[]) => Condition;
396
+ /** Multi: true when exactly `count` of `conditions` hold. */
397
+ export declare const exactly: (count: number, ...conditions: Condition[]) => Condition;
398
+ /** Multi with an explicit Comparator (same wire shape as YAML Multi). */
399
+ export declare const multi: (count: number, comparison: Comparator, ...conditions: Condition[]) => Condition;
400
+ /** Always-true gate for strategies whose cadence lives in the pipeline. */
401
+ export declare const always: () => Condition;
402
+ export declare const filter: (condition: Condition) => PipelineStage;
403
+ export declare const selectTop: (metric: Indicator, limit: number, direction?: SelectDirection) => PipelineStage;
404
+ export declare const selectPercentile: (metric: Indicator, percentile: number, direction?: SelectDirection) => PipelineStage;
405
+ export declare function universe(source: "ALL_US_STOCKS" | "SP500" | "NASDAQ100" | "DJIA" | "CRYPTO"): Universe;
406
+ export declare function universe(source: "SPECIFIC_ASSETS", assets: AssetArg[]): Universe;
407
+ export declare const buy: (target: AssetArg, amount: number, type?: AllocationType) => BuyOrSellAction;
408
+ export declare const sell: (target: AssetArg, amount: number, type?: AllocationType) => BuyOrSellAction;
409
+ export declare const deposit: (amount: number, type?: DepositWithdrawAllocationType) => DepositOrWithdrawAction;
410
+ export declare const withdraw: (amount: number, type?: DepositWithdrawAllocationType) => DepositOrWithdrawAction;
411
+ export declare const alert: (message: string) => AlertAction;
412
+ export declare const launchAgent: (config: {
413
+ planningModel: string;
414
+ executionModel: string;
415
+ initialMessage: string;
416
+ maxIterations: number;
417
+ includeMarketData: boolean;
418
+ continueExisting: boolean;
419
+ skipPlanning: boolean;
420
+ cooldownMinutes?: number;
421
+ }) => LaunchAgentAction;
422
+ export declare const dynamicRebalance: (config: {
423
+ universe: Universe;
424
+ pipeline: PipelineStage[];
425
+ weightIndicator: Indicator | CandidateIndicator;
426
+ limit?: number;
427
+ deploymentPercent?: number;
428
+ perNameAllocation?: PerNameAllocation;
429
+ canSell?: Condition | CandidateCondition;
430
+ }) => DynamicRebalanceAction;
431
+ /**
432
+ * One leg of a spread. Distance is signed from ATM; 0 is ATM.
433
+ * Delta targeting is a discriminated union: distanceType: "delta" requires
434
+ * fallbackDistance+fallbackDistanceType OR fallbackStrikeSelector.
435
+ */
436
+ export declare const leg: (config: LegConfig) => OptionsBuilderLeg;
437
+ export declare const optionsBuilder: (config: {
438
+ legs: OptionsBuilderLeg[];
439
+ underlyingSymbol?: string;
440
+ dynamicUnderlying?: DynamicUnderlying;
441
+ spreadType?: OptionSpreadType;
442
+ }) => OptionsBuilder;
443
+ export declare const againstParent: (config: OptionPositionSelector) => OptionPositionSelector;
444
+ export declare const openOption: (config: {
445
+ builder: OptionsBuilder;
446
+ allocation?: OptionAllocation;
447
+ against?: OptionPositionSelector;
448
+ }) => OpenOptionAction;
449
+ export declare const structureTemplate: (config: {
450
+ legs: OptionsBuilderLeg[];
451
+ name?: string;
452
+ eligibility?: Condition | CandidateCondition;
453
+ spreadType?: OptionSpreadType;
454
+ }) => OptionStructureTemplate;
455
+ export declare const sleeve: (config: {
456
+ name: string;
457
+ universe?: Universe;
458
+ pipeline?: PipelineStage[];
459
+ weightIndicator?: Indicator | CandidateIndicator;
460
+ limit?: number;
461
+ perNameAllocation?: OptionAllocation;
462
+ structureTemplates?: OptionStructureTemplate[];
463
+ }) => RebalanceOptionSleeve;
464
+ /**
465
+ * Rank a universe and rotate an option book. Keep take-profit / stop-loss / DTE
466
+ * exits in separate closeOption strategies, not here.
467
+ */
468
+ export declare const rebalanceOption: (config: {
469
+ universe: Universe;
470
+ pipeline: PipelineStage[];
471
+ weightIndicator: Indicator | CandidateIndicator;
472
+ structureTemplates: OptionStructureTemplate[];
473
+ limit?: number;
474
+ totalBudget?: DeploymentBudget;
475
+ perNameAllocation?: OptionAllocation;
476
+ positionScope?: RebalanceOptionPositionScope;
477
+ sleeves?: RebalanceOptionSleeve[];
478
+ }) => RebalanceOptionAction;
479
+ export declare const pnlTrigger: (bounds: {
480
+ minPnlPercent?: number;
481
+ maxPnlPercent?: number;
482
+ }) => CloseOptionTrigger;
483
+ export declare const dteTrigger: (bounds: {
484
+ minDte?: number;
485
+ maxDte?: number;
486
+ }) => CloseOptionTrigger;
487
+ export declare const daysHeldTrigger: (bounds: {
488
+ minDaysHeld?: number;
489
+ maxDaysHeld?: number;
490
+ }) => CloseOptionTrigger;
491
+ export declare const greeksTrigger: (bounds: {
492
+ minSpreadDelta?: number;
493
+ maxSpreadDelta?: number;
494
+ minIv?: number;
495
+ maxIv?: number;
496
+ minSpreadTheta?: number;
497
+ maxSpreadTheta?: number;
498
+ }) => CloseOptionTrigger;
499
+ export declare const closeOption: (config?: {
500
+ underlyings?: string[];
501
+ optionType?: OptionType;
502
+ direction?: OptionDirection;
503
+ spreadType?: OptionSpreadType;
504
+ closeScope?: CloseScope;
505
+ triggers?: CloseOptionTrigger[];
506
+ quantity?: CloseQuantity;
507
+ }) => CloseOptionAction;
508
+ export declare const strategy: (name: string, condition: StrategyCondition, action: Action, options?: {
509
+ active?: boolean;
510
+ }) => Strategy;
511
+ /**
512
+ * Session / clock flatten — condition carries the gate (MinutesAfterOpen, Day, …).
513
+ * Never pairs with always(); PnL/DTE/daysHeld exits use closeOption({ triggers }).
514
+ * Book-level only — CandidateCondition is rejected (same as strategy when).
515
+ */
516
+ export declare const sessionFlatten: (condition: StrategyCondition, config?: {
517
+ underlyings?: string[];
518
+ optionType?: OptionType;
519
+ direction?: OptionDirection;
520
+ spreadType?: OptionSpreadType;
521
+ closeScope?: CloseScope;
522
+ quantity?: CloseQuantity;
523
+ }, name?: string) => Strategy;
524
+ export declare const portfolio: (name: string, strategies: Strategy[], options?: {
525
+ initialValue?: number;
526
+ main?: boolean;
527
+ supportsFractionalShares?: boolean;
528
+ supportsCrypto?: boolean;
529
+ alertsEnabled?: boolean;
530
+ }) => Portfolio;
531
+ /**
532
+ * AbsoluteValue indicator.
533
+ */
534
+ export declare function AbsoluteValue(operand: Indicator): Indicator;
535
+ /**
536
+ * AverageTrueRange indicator.
537
+ * @param asset Ticker name (ex. SPY, BTC)
538
+ * @param length Length of time
539
+ * @param interval Unit of time
540
+ */
541
+ export declare function AverageTrueRange(asset: AssetArg, length?: number, interval?: Interval): Indicator;
542
+ /**
543
+ * BearishFairValueGap indicator.
544
+ * @param asset Ticker name (ex. SPY, BTC)
545
+ */
546
+ export declare function BearishFairValueGap(asset: AssetArg): Indicator;
547
+ /**
548
+ * BollingerBand indicator.
549
+ * @param asset Ticker name (ex. SPY, BTC)
550
+ * @param length Length of time
551
+ * @param interval Unit of time
552
+ * @param numStandardDeviations How many standard deviations from the mean
553
+ */
554
+ export declare function BollingerBand(asset: AssetArg, length?: number, interval?: Interval, numStandardDeviations?: number): Indicator;
555
+ export declare const BBand: typeof BollingerBand;
556
+ /**
557
+ * BullishFairValueGap indicator.
558
+ * @param asset Ticker name (ex. SPY, BTC)
559
+ */
560
+ export declare function BullishFairValueGap(asset: AssetArg): Indicator;
561
+ /**
562
+ * BuyingPower indicator.
563
+ */
564
+ export declare function BuyingPower(): Indicator;
565
+ /**
566
+ * CompoundAnnualGrowthRate indicator.
567
+ * @param asset Ticker name (ex. SPY, BTC)
568
+ * @param metric The fundamental metric to use
569
+ * @param years Floating point years value
570
+ */
571
+ export declare function CompoundAnnualGrowthRate(asset: AssetArg, metric: FundamentalMetric, years: number): Indicator;
572
+ /**
573
+ * ConsecutiveTrue indicator.
574
+ * @param condition Condition evaluated over the window.
575
+ * @param length Length of time
576
+ * @param interval Unit of time
577
+ */
578
+ export declare function ConsecutiveTrue(condition: Condition, length?: number, interval?: Interval): Indicator;
579
+ /**
580
+ * CountTrue indicator.
581
+ * @param condition Condition evaluated over the window.
582
+ * @param length Length of time
583
+ * @param interval Unit of time
584
+ */
585
+ export declare function CountTrue(condition: Condition, length?: number, interval?: Interval): Indicator;
586
+ /**
587
+ * CrossAbove indicator.
588
+ */
589
+ export declare function CrossAbove(left: Indicator, right: Indicator): Indicator;
590
+ /**
591
+ * CrossBelow indicator.
592
+ */
593
+ export declare function CrossBelow(left: Indicator, right: Indicator): Indicator;
594
+ /**
595
+ * CurrentTimeHours indicator.
596
+ */
597
+ export declare function CurrentTimeHours(): Indicator;
598
+ /**
599
+ * CurrentTimeMinutes indicator.
600
+ */
601
+ export declare function CurrentTimeMinutes(): Indicator;
602
+ /**
603
+ * CurrentTimeSeconds indicator.
604
+ */
605
+ export declare function CurrentTimeSeconds(): Indicator;
606
+ /**
607
+ * CustomIndicator indicator.
608
+ * @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
609
+ * @param customIndicatorId 24-char hex ObjectId of the owned series (list_custom_indicators).
610
+ */
611
+ export declare function CustomIndicator(asset: AssetArg, customIndicatorId: string): Indicator;
612
+ /**
613
+ * Date indicator.
614
+ */
615
+ export declare function Date(): Indicator;
616
+ /**
617
+ * Day indicator.
618
+ */
619
+ export declare function Day(): Indicator;
620
+ /**
621
+ * DaysSinceAgent indicator.
622
+ */
623
+ export declare function DaysSinceAgent(): Indicator;
624
+ /**
625
+ * DaysSinceAlert indicator.
626
+ * @param message (Optional) Message to display when the indicator is triggered
627
+ */
628
+ export declare function DaysSinceAlert(message: string): Indicator;
629
+ /**
630
+ * DaysSinceEarnings indicator.
631
+ * @param asset Ticker name (ex. SPY, BTC)
632
+ */
633
+ export declare function DaysSinceEarnings(asset: AssetArg): Indicator;
634
+ /**
635
+ * DaysSinceLastRebalanceOptionOrder indicator.
636
+ */
637
+ export declare function DaysSinceLastRebalanceOptionOrder(): Indicator;
638
+ /**
639
+ * DaysSinceOptionOrder indicator.
640
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
641
+ * @param optionType Filter by Call or Put. Leave empty for all.
642
+ * @param direction Filter by Long or Short. Leave empty for all.
643
+ * @param spreadType Filter by spread type. Leave empty for all.
644
+ * @param positionEffect Filter by Open (entering position) or Close (exiting). Leave empty for all.
645
+ * @param minDte Minimum days to expiration at order time. Leave empty for no minimum.
646
+ * @param maxDte Maximum days to expiration at order time. Leave empty for no maximum.
647
+ * @param orderStatus Matches option order events with this status
648
+ */
649
+ export declare function DaysSinceOptionOrder(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType, positionEffect: PositionEffect, minDte: number, maxDte: number, orderStatus?: OrderStatus): Indicator;
650
+ /**
651
+ * DaysSinceOrder indicator.
652
+ * @param assets Ticker(s) whose orders are counted. One string or an array.
653
+ * @param side Buy or Sell
654
+ */
655
+ export declare function DaysSinceOrder(assets: AssetArg | AssetArg[], side: Side, orderStatus?: OrderStatus): Indicator;
656
+ /**
657
+ * DaysSinceStrategyFired indicator.
658
+ */
659
+ export declare function DaysSinceStrategyFired(): Indicator;
660
+ /**
661
+ * DaysSinceTransaction indicator.
662
+ * @param transactionType Matches transaction events with this type (deposit or withdraw)
663
+ * @param transactionStatus Matches transaction events with this status
664
+ */
665
+ export declare function DaysSinceTransaction(transactionType: "Deposit" | "Withdraw", transactionStatus?: "Pending" | "Canceled" | "Completed"): Indicator;
666
+ /**
667
+ * DaysUntilEarnings indicator.
668
+ * @param asset Ticker name (ex. SPY, BTC)
669
+ */
670
+ export declare function DaysUntilEarnings(asset: AssetArg): Indicator;
671
+ /**
672
+ * Divide indicator.
673
+ */
674
+ export declare function Divide(left: Indicator, right: Indicator): Indicator;
675
+ /**
676
+ * Economic indicator.
677
+ * @param metric The economic indicator to use
678
+ */
679
+ export declare function Economic(metric: "NonfarmPayrolls" | "UnemploymentRate" | "MoneySupply" | "TreasuryYield3Month" | "CPI"): Indicator;
680
+ /**
681
+ * ExponentialMovingAverage indicator.
682
+ * @param asset Ticker name (ex. SPY, BTC)
683
+ * @param length Length of time
684
+ * @param interval Unit of time
685
+ */
686
+ export declare function ExponentialMovingAverage(asset: AssetArg, length: number, interval?: Interval): Indicator;
687
+ export declare const EMA: typeof ExponentialMovingAverage;
688
+ /**
689
+ * Exponentiation indicator.
690
+ * @param exponent The exponent to raise the value to
691
+ */
692
+ export declare function Exponentiation(operand: Indicator, exponent?: number): Indicator;
693
+ /**
694
+ * Fundamental indicator.
695
+ * @param asset Ticker name (ex. SPY, BTC)
696
+ * @param metric The fundamental metric to use
697
+ */
698
+ export declare function Fundamental(asset: AssetArg, metric: FundamentalMetric): Indicator;
699
+ /**
700
+ * GapPercentage indicator.
701
+ * @param asset Ticker name (ex. SPY, BTC)
702
+ */
703
+ export declare function GapPercentage(asset: AssetArg): Indicator;
704
+ /**
705
+ * GapSize indicator.
706
+ * @param asset Ticker name (ex. SPY, BTC)
707
+ */
708
+ export declare function GapSize(asset: AssetArg): Indicator;
709
+ /**
710
+ * HighOfDay indicator.
711
+ * @param asset Ticker name (ex. SPY, BTC)
712
+ */
713
+ export declare function HighOfDay(asset: AssetArg): Indicator;
714
+ /**
715
+ * Index indicator.
716
+ * @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
717
+ */
718
+ export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "DXY" | "TNX"): Indicator;
719
+ /**
720
+ * IndicatorAtMinutesAfterOpen indicator.
721
+ * @param minutesAfterOpen The number of minutes after market open to capture the indicator value
722
+ */
723
+ export declare function IndicatorAtMinutesAfterOpen(operand: Indicator, minutesAfterOpen?: number): Indicator;
724
+ /**
725
+ * IndicatorExponentialMovingAverage indicator.
726
+ * @param length Length of time
727
+ * @param interval Unit of time
728
+ */
729
+ export declare function IndicatorExponentialMovingAverage(operand: Indicator, length?: number, interval?: Interval): Indicator;
730
+ /**
731
+ * IndicatorMeanAbsoluteDeviation indicator.
732
+ * @param length Length of time
733
+ * @param interval Unit of time
734
+ */
735
+ export declare function IndicatorMeanAbsoluteDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
736
+ /**
737
+ * IndicatorRateOfChange indicator.
738
+ * @param length Length of time
739
+ * @param interval Unit of time
740
+ */
741
+ export declare function IndicatorRateOfChange(operand: Indicator, length?: number, interval?: Interval): Indicator;
742
+ /**
743
+ * IndicatorSimpleMovingAverage indicator.
744
+ * @param length Length of time
745
+ * @param interval Unit of time
746
+ */
747
+ export declare function IndicatorSimpleMovingAverage(operand: Indicator, length?: number, interval?: Interval): Indicator;
748
+ /**
749
+ * IndicatorStandardDeviation indicator.
750
+ * @param length Length of time
751
+ * @param interval Unit of time
752
+ */
753
+ export declare function IndicatorStandardDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
754
+ /**
755
+ * IndicatorWindowAgo indicator.
756
+ * @param length Length of time
757
+ * @param interval Unit of time
758
+ */
759
+ export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval): Indicator;
760
+ /**
761
+ * InitialValue indicator.
762
+ */
763
+ export declare function InitialValue(): Indicator;
764
+ /**
765
+ * IsAsset indicator.
766
+ * @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
767
+ * @param asset Ticker name (ex. SPY, BTC)
768
+ */
769
+ export declare function IsAsset(matchAsset: AssetArg, asset: AssetArg): Indicator;
770
+ /**
771
+ * IsAssetType indicator.
772
+ * @param asset Ticker name (ex. SPY, BTC)
773
+ * @param assetType The asset type to check against
774
+ */
775
+ export declare function IsAssetType(asset: AssetArg, assetType?: AssetType): Indicator;
776
+ /**
777
+ * IsIndexMember indicator.
778
+ * @param asset Ticker name (ex. SPY, BTC)
779
+ * @param index The index to check membership against
780
+ */
781
+ export declare function IsIndexMember(asset: AssetArg, index?: "SP500" | "NASDAQ100" | "DJIA"): Indicator;
782
+ /**
783
+ * IsIndustry indicator.
784
+ * @param asset Ticker name (ex. SPY, BTC)
785
+ * @param industry The industry to check membership against
786
+ */
787
+ export declare function IsIndustry(asset: AssetArg, industry: "technology" | "financialServices" | "healthcare" | "energy" | "consumerGoods" | "entertainmentAndMedia" | "manufacturing" | "transportation" | "realEstate" | "utilities" | "agriculture" | "education" | "retail" | "artificialIntelligence" | "aiInfrastructure" | "analytics" | "cloudComputing" | "dataCenter" | "database" | "cybersecurity" | "developerTools" | "software" | "saas" | "enterpriseSoftware" | "customerExperienceSoftware" | "productivityTools" | "collaborationSoftware" | "digitalSignatureAndAuthentication" | "hardware" | "consumerElectronics" | "networking" | "semiconductor" | "chipDesign" | "chipManufacturing" | "semiconductorEquipment" | "gpuAndAccelerators" | "memoryAndStorage" | "quantumComputing" | "robotics" | "industrialAutomation" | "iot" | "smartDevices" | "wearable" | "3dPrinting" | "augmentedReality" | "virtualReality" | "space" | "satellites" | "aerospace" | "defense" | "drones" | "financialInfrastructure" | "capitalMarketsTechnology" | "banking" | "assetManagement" | "brokerage" | "payments" | "fintech" | "insurance" | "autoInsurance" | "homeInsurance" | "lifeInsurance" | "healthInsurance" | "blockchain" | "cryptocurrency" | "biotechnology" | "pharmaceuticals" | "medicalDevices" | "digitalHealth" | "lifeSciencesSoftware" | "bioinformatics" | "computationalBiology" | "computationalDrugDiscovery" | "oncology" | "immunotherapy" | "vaccines" | "veterinary" | "oil" | "gas" | "oilfieldServices" | "cleanEnergy" | "renewableEnergy" | "solarEnergy" | "windEnergy" | "nuclearEnergy" | "hydrogen" | "batteryTechnology" | "miningAndNaturalResources" | "gold" | "silver" | "chemicals" | "advancedMaterials" | "waterInfrastructure" | "wasteManagementAndRecycling" | "forestry" | "construction" | "buildingMaterials" | "electricalAndGridInfrastructure" | "logisticsAndSupplyChain" | "airline" | "maritime" | "railroads" | "automotive" | "electricVehicle" | "autonomousTransportation" | "recreationalVehicle" | "cruise" | "rideShare" | "printing" | "packaging" | "householdProducts" | "ecommerce" | "digitalMarketplace" | "fashionAndApparel" | "luxuryGoods" | "jewelry" | "foodAndBeverage" | "foodDelivery" | "nutrition" | "petCare" | "outdoorAndRecreationalEquipment" | "sportsAndFitness" | "cannabis" | "hospitalityAndTravel" | "homeSecurity" | "advertising" | "gaming" | "gambling" | "sportsBetting" | "socialMedia" | "streaming" | "movies" | "musicAndAudio" | "publishing" | "telecommunications" | "edtech" | "proptech" | "informationTechnology" | "personalAndHouseholdGoods" | "investing" | "spaceExploration" | "alternativeEnergy" | "clothesAndApparal" | "computationalChemistry" | "customerEngagement" | "dataVisualization" | "graphicsCard" | "materialScience" | "medicine" | "messaging" | "phones" | "security" | "socialNetwork" | "television" | "videoConferencing" | "videos" | "waterPurifaction" | "waterTreatment"): Indicator;
788
+ /**
789
+ * IsNotAsset indicator.
790
+ * @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
791
+ * @param asset Ticker name (ex. SPY, BTC)
792
+ */
793
+ export declare function IsNotAsset(matchAsset: AssetArg, asset: AssetArg): Indicator;
794
+ /**
795
+ * LastOrderPrice indicator.
796
+ * @param asset Ticker name (ex. SPY, BTC)
797
+ * @param side Matches order events with this side (buy or sell)
798
+ * @param orderStatus Matches order events with this status
799
+ */
800
+ export declare function LastOrderPrice(asset: AssetArg, side: Side, orderStatus?: OrderStatus): Indicator;
801
+ /**
802
+ * Log indicator.
803
+ * @param base The base for the logarithm
804
+ */
805
+ export declare function Log(operand: Indicator, base?: number): Indicator;
806
+ /**
807
+ * LowOfDay indicator.
808
+ * @param asset Ticker name (ex. SPY, BTC)
809
+ */
810
+ export declare function LowOfDay(asset: AssetArg): Indicator;
811
+ /**
812
+ * Max indicator.
813
+ */
814
+ export declare function Max(left: Indicator, right: Indicator): Indicator;
815
+ /**
816
+ * MaxDrawdown indicator.
817
+ * @param asset Ticker name (ex. SPY, BTC)
818
+ * @param length Length of time
819
+ * @param interval Unit of time
820
+ */
821
+ export declare function MaxDrawdown(asset: AssetArg, length?: number, interval?: Interval): Indicator;
822
+ /**
823
+ * MaxDrawup indicator.
824
+ * @param asset Ticker name (ex. SPY, BTC)
825
+ * @param length Length of time
826
+ * @param interval Unit of time
827
+ */
828
+ export declare function MaxDrawup(asset: AssetArg, length?: number, interval?: Interval): Indicator;
829
+ /**
830
+ * MaximumPrice indicator.
831
+ * @param asset Ticker name (ex. SPY, BTC)
832
+ * @param length Length of time
833
+ * @param interval Unit of time
834
+ */
835
+ export declare function MaximumPrice(asset: AssetArg, length?: number, interval?: Interval): Indicator;
836
+ /**
837
+ * Min indicator.
838
+ */
839
+ export declare function Min(left: Indicator, right: Indicator): Indicator;
840
+ /**
841
+ * MinimumPrice indicator.
842
+ * @param asset Ticker name (ex. SPY, BTC)
843
+ * @param length Length of time
844
+ * @param interval Unit of time
845
+ */
846
+ export declare function MinimumPrice(asset: AssetArg, length?: number, interval?: Interval): Indicator;
847
+ /**
848
+ * Minus indicator.
849
+ */
850
+ export declare function Minus(left: Indicator, right: Indicator): Indicator;
851
+ /**
852
+ * MinutesAfterOpen indicator.
853
+ */
854
+ export declare function MinutesAfterOpen(): Indicator;
855
+ /**
856
+ * MinutesSinceAgent indicator.
857
+ */
858
+ export declare function MinutesSinceAgent(): Indicator;
859
+ /**
860
+ * MinutesSinceAlert indicator.
861
+ * @param message (Optional) Message to display when the indicator is triggered
862
+ */
863
+ export declare function MinutesSinceAlert(message: string): Indicator;
864
+ /**
865
+ * MinutesSinceOptionOrder indicator.
866
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
867
+ * @param optionType Filter by Call or Put. Leave empty for all.
868
+ * @param direction Filter by Long or Short. Leave empty for all.
869
+ * @param spreadType Filter by spread type. Leave empty for all.
870
+ * @param positionEffect Filter by Open (entering position) or Close (exiting). Leave empty for all.
871
+ * @param minDte Minimum days to expiration at order time. Leave empty for no minimum.
872
+ * @param maxDte Maximum days to expiration at order time. Leave empty for no maximum.
873
+ * @param orderStatus Matches option order events with this status
874
+ */
875
+ export declare function MinutesSinceOptionOrder(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType, positionEffect: PositionEffect, minDte: number, maxDte: number, orderStatus?: OrderStatus): Indicator;
876
+ /**
877
+ * MinutesSinceOrder indicator.
878
+ * @param assets Ticker(s) whose orders are counted. One string or an array.
879
+ * @param side Buy or Sell
880
+ */
881
+ export declare function MinutesSinceOrder(assets: AssetArg | AssetArg[], side: Side, orderStatus?: OrderStatus): Indicator;
882
+ /**
883
+ * MinutesUntilClose indicator.
884
+ */
885
+ export declare function MinutesUntilClose(): Indicator;
886
+ /**
887
+ * Month indicator.
888
+ */
889
+ export declare function Month(): Indicator;
890
+ /**
891
+ * Multiply indicator.
892
+ */
893
+ export declare function Multiply(left: Indicator, right: Indicator): Indicator;
894
+ /**
895
+ * Negative indicator.
896
+ */
897
+ export declare function Negative(operand: Indicator): Indicator;
898
+ /**
899
+ * OpeningPrice indicator.
900
+ * @param asset Ticker name (ex. SPY, BTC)
901
+ */
902
+ export declare function OpeningPrice(asset: AssetArg): Indicator;
903
+ /**
904
+ * OptionCollateral indicator.
905
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
906
+ * @param optionType Filter by Call or Put. Leave empty for all.
907
+ * @param direction Filter by Long or Short. Leave empty for all.
908
+ * @param spreadType Filter by spread type. Leave empty for all.
909
+ */
910
+ export declare function OptionCollateral(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
911
+ /**
912
+ * OptionDaysHeld indicator.
913
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
914
+ * @param optionType Filter by Call or Put. Leave empty for all.
915
+ * @param direction Filter by Long or Short. Leave empty for all.
916
+ * @param spreadType Filter by spread type. Leave empty for all.
917
+ * @param minOrMax Return minimum or maximum value across matching spreads.
918
+ */
919
+ export declare function OptionDaysHeld(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType, minOrMax?: MinOrMax): Indicator;
920
+ /**
921
+ * OptionDaysToExpiration indicator.
922
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
923
+ * @param optionType Filter by Call or Put. Leave empty for all.
924
+ * @param direction Filter by Long or Short. Leave empty for all.
925
+ * @param spreadType Filter by spread type. Leave empty for all.
926
+ * @param minOrMax Return minimum or maximum value across matching spreads.
927
+ */
928
+ export declare function OptionDaysToExpiration(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType, minOrMax?: MinOrMax): Indicator;
929
+ /**
930
+ * OptionGrossExposurePercent indicator.
931
+ */
932
+ export declare function OptionGrossExposurePercent(): Indicator;
933
+ /**
934
+ * OptionPositionCount indicator.
935
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
936
+ * @param optionType Filter by Call or Put. Leave empty for all.
937
+ * @param direction Filter by Long or Short. Leave empty for all.
938
+ * @param spreadType Filter by spread type. Leave empty for all.
939
+ */
940
+ export declare function OptionPositionCount(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
941
+ /**
942
+ * OptionPositionMaxDrawdown indicator.
943
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
944
+ * @param optionType Filter by Call or Put. Leave empty for all.
945
+ * @param direction Filter by Long or Short. Leave empty for all.
946
+ * @param spreadType Filter by spread type. Leave empty for all.
947
+ */
948
+ export declare function OptionPositionMaxDrawdown(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
949
+ /**
950
+ * OptionPositionPercentChange indicator.
951
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
952
+ * @param optionType Filter by Call or Put. Leave empty for all.
953
+ * @param direction Filter by Long or Short. Leave empty for all.
954
+ * @param spreadType Filter by spread type. Leave empty for all.
955
+ */
956
+ export declare function OptionPositionPercentChange(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
957
+ /**
958
+ * OptionPositionValue indicator.
959
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
960
+ * @param optionType Filter by Call or Put. Leave empty for all.
961
+ * @param direction Filter by Long or Short. Leave empty for all.
962
+ * @param spreadType Filter by spread type. Leave empty for all.
963
+ */
964
+ export declare function OptionPositionValue(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
965
+ /**
966
+ * OptionSpreadCount indicator.
967
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
968
+ * @param optionType Filter by Call or Put. Leave empty for all.
969
+ * @param direction Filter by Long or Short. Leave empty for all.
970
+ * @param spreadType Filter by spread type. Leave empty for all.
971
+ */
972
+ export declare function OptionSpreadCount(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
973
+ /**
974
+ * OptionUnrealizedPnL indicator.
975
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
976
+ * @param optionType Filter by Call or Put. Leave empty for all.
977
+ * @param direction Filter by Long or Short. Leave empty for all.
978
+ * @param spreadType Filter by spread type. Leave empty for all.
979
+ */
980
+ export declare function OptionUnrealizedPnL(underlying: string, optionType: OptionType, direction: OptionDirection, spreadType: OptionSpreadType): Indicator;
981
+ /**
982
+ * Plus indicator.
983
+ */
984
+ export declare function Plus(left: Indicator, right: Indicator): Indicator;
985
+ /**
986
+ * PortfolioValue indicator.
987
+ */
988
+ export declare function PortfolioValue(): Indicator;
989
+ /**
990
+ * PositionMaxDrawdown indicator.
991
+ * @param asset Ticker name (ex. SPY, BTC)
992
+ */
993
+ export declare function PositionMaxDrawdown(asset: AssetArg): Indicator;
994
+ /**
995
+ * PositionMaxDrawup indicator.
996
+ * @param asset Ticker name (ex. SPY, BTC)
997
+ */
998
+ export declare function PositionMaxDrawup(asset: AssetArg): Indicator;
999
+ /**
1000
+ * PositionPercentChange indicator.
1001
+ * @param assets Ticker name (ex. SPY, BTC)
1002
+ */
1003
+ export declare function PositionPercentChange(assets: AssetArg | AssetArg[]): Indicator;
1004
+ /**
1005
+ * PositionValue indicator.
1006
+ * @param assets Ticker name (ex. SPY, BTC)
1007
+ */
1008
+ export declare function PositionValue(assets: AssetArg | AssetArg[]): Indicator;
1009
+ /**
1010
+ * PreviousClosingPrice indicator.
1011
+ * @param asset Ticker name (ex. SPY, BTC)
1012
+ */
1013
+ export declare function PreviousClosingPrice(asset: AssetArg): Indicator;
1014
+ /**
1015
+ * Price indicator.
1016
+ * @param asset Ticker name (ex. SPY, BTC)
1017
+ */
1018
+ export declare function Price(asset: AssetArg): Indicator;
1019
+ /**
1020
+ * PriceChangeSinceOpen indicator.
1021
+ * @param asset Ticker name (ex. SPY, BTC)
1022
+ */
1023
+ export declare function PriceChangeSinceOpen(asset: AssetArg): Indicator;
1024
+ /**
1025
+ * PriceMeanAbsoluteDeviation indicator.
1026
+ * @param asset Ticker name (ex. SPY, BTC)
1027
+ * @param length Length of time
1028
+ * @param interval Unit of time
1029
+ */
1030
+ export declare function PriceMeanAbsoluteDeviation(asset: AssetArg, length?: number, interval?: Interval): Indicator;
1031
+ /**
1032
+ * PriceRateOfChange indicator.
1033
+ * @param asset Ticker name (ex. SPY, BTC)
1034
+ * @param length Length of time
1035
+ * @param interval Unit of time
1036
+ */
1037
+ export declare function PriceRateOfChange(asset: AssetArg, length?: number, interval?: Interval): Indicator;
1038
+ /**
1039
+ * PriceStandardDeviation indicator.
1040
+ * @param asset Ticker name (ex. SPY, BTC)
1041
+ * @param length Length of time
1042
+ * @param interval Unit of time
1043
+ */
1044
+ export declare function PriceStandardDeviation(asset: AssetArg, length?: number, interval?: Interval): Indicator;
1045
+ export declare const PriceStdDev: typeof PriceStandardDeviation;
1046
+ /**
1047
+ * RelativeStrengthIndex indicator.
1048
+ * @param asset Ticker name (ex. SPY, BTC)
1049
+ * @param length Length of time
1050
+ * @param interval Unit of time
1051
+ */
1052
+ export declare function RelativeStrengthIndex(asset: AssetArg, length?: number, interval?: Interval): Indicator;
1053
+ export declare const RSI: typeof RelativeStrengthIndex;
1054
+ /**
1055
+ * SimpleMovingAverage indicator.
1056
+ * @param asset Ticker name (ex. SPY, BTC)
1057
+ * @param length Length of time
1058
+ * @param interval Unit of time
1059
+ */
1060
+ export declare function SimpleMovingAverage(asset: AssetArg, length?: number, interval?: Interval): Indicator;
1061
+ export declare const SMA: typeof SimpleMovingAverage;
1062
+ /**
1063
+ * SquareRoot indicator.
1064
+ */
1065
+ export declare function SquareRoot(operand: Indicator): Indicator;
1066
+ /**
1067
+ * StockReport indicator.
1068
+ * @param asset Ticker name (ex. SPY, BTC)
1069
+ */
1070
+ export declare function StockReport(asset: AssetArg): Indicator;
1071
+ /**
1072
+ * SumOrderAmount indicator.
1073
+ * @param side Matches order events with this side (buy or sell)
1074
+ * @param orderStatus Matches order events with this status
1075
+ * @param length Length of time
1076
+ * @param interval Unit of time
1077
+ * @param assets Ticker name (ex. SPY, BTC)
1078
+ */
1079
+ export declare function SumOrderAmount(side: Side, orderStatus?: OrderStatus, length?: number, interval?: Interval, assets?: AssetArg | AssetArg[]): Indicator;
1080
+ /**
1081
+ * SumOrderQuantity indicator.
1082
+ * @param side Matches order events with this side (buy or sell)
1083
+ * @param orderStatus Matches order events with this status
1084
+ * @param length Length of time
1085
+ * @param interval Unit of time
1086
+ * @param assets Ticker name (ex. SPY, BTC)
1087
+ */
1088
+ export declare function SumOrderQuantity(side: Side, orderStatus?: OrderStatus, length?: number, interval?: Interval, assets?: AssetArg | AssetArg[]): Indicator;
1089
+ /**
1090
+ * TrailingSum indicator.
1091
+ * @param length Length of the rolling window
1092
+ */
1093
+ export declare function TrailingSum(operand: Indicator, length?: number): Indicator;
1094
+ /**
1095
+ * TrueRange indicator.
1096
+ * @param asset Ticker name (ex. SPY, BTC)
1097
+ */
1098
+ export declare function TrueRange(asset: AssetArg): Indicator;
1099
+ /**
1100
+ * UnderlyingMaxDrawdown indicator.
1101
+ * @param asset Ticker name (ex. SPY, BTC)
1102
+ */
1103
+ export declare function UnderlyingMaxDrawdown(asset: AssetArg): Indicator;
1104
+ /**
1105
+ * Value indicator.
1106
+ * @param value Constant value
1107
+ */
1108
+ export declare function Value(value?: number): Indicator;
1109
+ /**
1110
+ * Volume indicator.
1111
+ * @param asset Ticker name (ex. SPY, BTC)
1112
+ * @param metric The fundamental metric to use
1113
+ */
1114
+ export declare function Volume(asset: AssetArg, metric?: FundamentalMetric): Indicator;
1115
+ /**
1116
+ * VWAP indicator.
1117
+ * @param asset Ticker name (ex. SPY, BTC)
1118
+ */
1119
+ export declare function VWAP(asset: AssetArg): Indicator;
1120
+ /**
1121
+ * Year indicator.
1122
+ */
1123
+ export declare function Year(): Indicator;
1124
+ export type FitnessFunction = "sharpeRatio" | "sortinoRatio" | "maxDrawdown" | "avgDrawdown" | "percentChange" | "dollarsSold" | "ulcerPerformanceIndex" | "participationRate" | "distinctUnderlyingsTraded" | "medianDeployment";
1125
+ export interface FeeAmount {
1126
+ amount: number;
1127
+ type: "percent" | "dollars";
1128
+ }
1129
+ /** Fee contract keyed by asset class. Omit for shared defaults (Option $0.65/contract). */
1130
+ export interface FeeConfig {
1131
+ Stock?: FeeAmount;
1132
+ Cryptocurrency?: FeeAmount;
1133
+ Option?: FeeAmount;
1134
+ /** Rust-owned option fill slippage; absent means the engine's 0.5 default. */
1135
+ OptionSlippageFraction?: number;
1136
+ }
1137
+ export interface MetricConstraint {
1138
+ metric: FitnessFunction;
1139
+ comparison: "lessThan" | "greaterThan" | "lessThanOrEqual" | "greaterThanOrEqual" | "equal" | "notEqual";
1140
+ value: number;
1141
+ }
1142
+ /** Winner-selection floors/objectives. Never hard-fails the run. */
1143
+ export type SelectionPolicy = {
1144
+ mode: "constrainedPrimary";
1145
+ primary: FitnessFunction;
1146
+ constraints?: MetricConstraint[];
1147
+ tieBreakers?: FitnessFunction[];
1148
+ } | {
1149
+ mode: "pareto";
1150
+ objectives: FitnessFunction[];
1151
+ constraints?: MetricConstraint[];
1152
+ tieBreakers?: FitnessFunction[];
1153
+ };
1154
+ /**
1155
+ * Not on the SDK surface — genes are authored with the typed gene* builders and
1156
+ * passed as `genes: Gene[]`. Kept as a named alias only for completeness; the
1157
+ * host assembles the real SweepConfig (see models/optimization/sweep.ts).
1158
+ */
1159
+ export type SweepConfig = Record<string, unknown>;
1160
+ /** Adaptive walk-forward controls — see AdaptiveConfig in models/walkForward. */
1161
+ export type AdaptiveConfig = Record<string, unknown>;
1162
+ /** A constructed job request. The host submits it; the SDK cannot. */
1163
+ export interface JobRequest {
1164
+ tool: "backtest_portfolio" | "run_walk_forward_study" | "optimize_portfolio";
1165
+ portfolio: Portfolio;
1166
+ args: Record<string, unknown>;
1167
+ }
1168
+ export interface BacktestConfig {
1169
+ /** Backtest start date (ISO format, e.g. 2024-01-01) */
1170
+ startDate: string;
1171
+ /** Backtest end date (ISO format, e.g. 2024-12-31) */
1172
+ endDate: string;
1173
+ /** Benchmark for comparisonValue (buy-and-hold of this ticker). Defaults to SPY if omitted — use SPY only for broad equity/market strategies. For single-name options, set to that underlying (AAPL options → AAPL). For multi-name options books, run separate backtests with each material underlying as baseline (AAPL for AAPL sleeve, MSFT for MSFT), or equal-weight B&H of the traded universe — do not default to SPY. */
1174
+ baselineSymbol?: string;
1175
+ /** Time interval: Day or Minute (default Day) */
1176
+ interval?: "Day" | "Minute";
1177
+ /** Starting portfolio value (default 10000) Range 1..inf. */
1178
+ initialValue?: number;
1179
+ /** Generate detailed event data (signals, orders, audits) during backtest. Costs 5x research tokens. Events are Mongo hot-store traces retained for 3 days. Use query_backtest_events to explore them while retained. */
1180
+ generateEvents?: boolean;
1181
+ /** Optional fee contract keyed by AssetTypeEnum (Stock/Cryptocurrency/Option) with {amount, type: percent|dollars}. Omit for shared defaults (Option $0.65/contract). For replay of an optimizer/walk-forward study, pass that study's persisted feeConfig. Option fill slippage (OptionSlippageFraction) is not set here — engine default 0.5 applies. */
1182
+ feeConfig?: FeeConfig;
1183
+ }
1184
+ export interface WalkForwardConfig {
1185
+ /** Global calendar start for the walk-forward study (ISO date). */
1186
+ globalStartDate: string;
1187
+ /** Global calendar end for the walk-forward study (ISO date). */
1188
+ globalEndDate: string;
1189
+ /** Number of forward folds (2–8, required). Range 2..8. */
1190
+ foldCount: number;
1191
+ /** Child optimizer engine: ga (default) or sweep. Prefer sweep for deploy certification and options rotation books; use ga for exploratory continuous mutation. */
1192
+ engineKind?: "ga" | "sweep";
1193
+ /** Anchored (default) or rolling outer window mode. */
1194
+ walkForwardMode?: "anchored" | "rolling";
1195
+ /** OOS window width in calendar days (default 252). Range 1..inf. */
1196
+ oosWidthDays?: number;
1197
+ /** Validation share inside each fold's development window (1–50). Default 20 for exploratory runs. Default 50 when certification: true (sweep or GA) — longer validation reduces fold-winner selection noise. Range 1..50. */
1198
+ validationPercent?: number;
1199
+ /** Embargo gap between training and validation (default 14). Range 0..inf. */
1200
+ embargoDays?: number;
1201
+ /** GA population size (default 6). Range 3..12. */
1202
+ populationSize?: number;
1203
+ /** GA generations (default 6). Range 1..10. */
1204
+ numGenerations?: number;
1205
+ /** Inner rolling training windows (default 3). Range 1..20. */
1206
+ numWindows?: number;
1207
+ /** Inner train/validation split percent (default 75). Range 10..95. */
1208
+ trainingPercent?: number;
1209
+ /** Inner rolling window overlap percent (default 50). Range 0..95. */
1210
+ windowOverlapPercent?: number;
1211
+ fitnessFunctions?: ("sharpeRatio" | "sortinoRatio" | "maxDrawdown" | "avgDrawdown" | "percentChange" | "dollarsSold" | "ulcerPerformanceIndex" | "participationRate" | "distinctUnderlyingsTraded" | "medianDeployment")[];
1212
+ /** Winner selection policy (objectives, constraints, tieBreakers). Applies to sweep leaderboard and fold winner selection. For GA WF, also sets NSGA-II activity constraints when fold_selection_policy is omitted. */
1213
+ selectionPolicy?: SelectionPolicy;
1214
+ /** Explicit fold winner selection policy. Overrides selection_policy for fold winner pick. When set, train→validation degradation penalty defaults to 0.5 unless degradation_penalty is set. */
1215
+ foldSelectionPolicy?: SelectionPolicy;
1216
+ /** Optional fee contract keyed by AssetTypeEnum (Stock/Cryptocurrency/Option) with {amount, type: percent|dollars}. Frozen on the study and applied to all fold scoring / OOS. Omit for shared defaults matching standalone backtests (Option $0.65/contract). Unknown keys are rejected. */
1217
+ feeConfig?: FeeConfig;
1218
+ /** Train→validation degradation weight for fold winner ranking (default 0.5 when an explicit policy is set; 0.0 for legacy GA Sharpe-only studies). Range 0..1. */
1219
+ degradationPenalty?: number;
1220
+ /** Sweep leaderboard size when using gene_intents (default 25). Range 1..250. */
1221
+ leaderboardSize?: number;
1222
+ /** Sweep search mode: auto (default), exhaustive, or generational. */
1223
+ searchMode?: "auto" | "exhaustive" | "generational";
1224
+ /** When true, compile and validate the walk-forward plan without creating a study or charging tokens. Returns fold calendar, estimated token cost, and compiled sweepGenes (when engine_kind is sweep). */
1225
+ previewOnly?: boolean;
1226
+ interval?: "Day" | "Minute";
1227
+ /** Start orchestrator immediately (default true). */
1228
+ autoRun?: boolean;
1229
+ /** Optional study label. */
1230
+ name?: string;
1231
+ /** Study scoring mode: validation (per-fold independent OOS, default), adaptive (stitched re-optimized policy curve), or both. */
1232
+ mode?: "validation" | "adaptive" | "both";
1233
+ /** Validation-only OOS stride in days; when less than oos_width_days folds overlap. Ignored in adaptive/both (contiguous tiling). Range 1..inf. */
1234
+ oosStrideDays?: number;
1235
+ /** Adaptive/both only: { reoptimizeWindow: anchored|rolling, hysteresisMarginPct, maxTurnoverPerRollPct? }. */
1236
+ adaptiveConfig?: AdaptiveConfig;
1237
+ /** Per-fold inner execution: optimize (default, run GA/sweep per fold) or backtest_only (certify fixed portfolio — train/val/OOS backtests only, no inner optimizer). */
1238
+ innerMode?: "optimize" | "backtest_only";
1239
+ /** When true with inner_mode optimize, apply default certification selection policy (activity floors + percentChange≥0 + sortino≥0.5) unless explicit selection_policy is set. Also defaults validation_percent to 50. Prefer engine_kind sweep for deploy certification; GA+certification is rejected unless allow_ga_certification is true. */
1240
+ certification?: boolean;
1241
+ /** Explicit override to allow engine_kind ga with certification: true. Default false — use sweep+certification or inner_mode backtest_only for deployable studies. */
1242
+ allowGaCertification?: boolean;
1243
+ /** Alias for certification — applies DEFAULT_CERTIFICATION_SELECTION_POLICY on optimize-mode studies. */
1244
+ useCertificationSelectionPolicy?: boolean;
1245
+ /** Typed sweep genes built with the gene* builders (deterministic; no LLM compile). */
1246
+ genes?: Gene[];
1247
+ }
1248
+ export interface OptimizationConfig {
1249
+ /** Optimization start date (ISO format, e.g. 2024-01-01) */
1250
+ startDate: string;
1251
+ /** Optimization end date (ISO format, e.g. 2024-12-31) */
1252
+ endDate: string;
1253
+ /** Fitness functions: sharpeRatio, sortinoRatio, maxDrawdown, avgDrawdown, percentChange, dollarsSold, ulcerPerformanceIndex, participationRate, distinctUnderlyingsTraded, medianDeployment */
1254
+ fitnessFunctions?: ("sharpeRatio" | "sortinoRatio" | "maxDrawdown" | "avgDrawdown" | "percentChange" | "dollarsSold" | "ulcerPerformanceIndex" | "participationRate" | "distinctUnderlyingsTraded" | "medianDeployment")[];
1255
+ /** Population size for genetic algorithm (default 6, range 3-12) Range 3..12. */
1256
+ populationSize?: number;
1257
+ /** Number of generations (default 6, max 10) Range 1..10. */
1258
+ numGenerations?: number;
1259
+ /** Number of rolling training windows (default 3, max 20) Range 1..20. */
1260
+ numWindows?: number;
1261
+ /** Whole-percent share of the requested date range used for training; the remaining tail is validation (default 75). Uses app-style percent units, e.g. 75 not 0.75. Range 10..95. */
1262
+ trainingPercent?: number;
1263
+ /** Whole-percent overlap between adjacent rolling training windows (default 50). Uses app-style percent units, e.g. 50 not 0.5. Range 0..95. */
1264
+ windowOverlapPercent?: number;
1265
+ /** Time interval: Day or Minute (default Day) */
1266
+ interval?: "Day" | "Minute";
1267
+ /** Optional winner-selection policy with activity/quality/posture floors (participationRate, distinctUnderlyingsTraded, medianDeployment, percentChange, sortinoRatio, etc.). Steers GA away from thin or over-deployed validation winners during evolution and leaderboard ranking. Never hard-fails the run. */
1268
+ selectionPolicy?: SelectionPolicy;
1269
+ /** Optional fee contract keyed by AssetTypeEnum (Stock/Cryptocurrency/Option) with {amount, type: percent|dollars}. Omit for shared defaults matching standalone backtests (Option $0.65/contract). Unknown keys are rejected. */
1270
+ feeConfig?: FeeConfig;
1271
+ /** Typed sweep genes built with the gene* builders (deterministic; no LLM compile). */
1272
+ genes?: Gene[];
1273
+ }
1274
+ /** Submit a backtest. Returns a handle; results are read after it completes. */
1275
+ export declare const backtest: (portfolio: Portfolio, config: BacktestConfig) => JobRequest;
1276
+ /** Submit a walk-forward study (anchored or rolling folds, GA or sweep engine). */
1277
+ export declare const walkForward: (portfolio: Portfolio, config: WalkForwardConfig) => JobRequest;
1278
+ /** Submit a genetic optimization over the portfolio's tunable genes. */
1279
+ export declare const optimization: (portfolio: Portfolio, config: OptimizationConfig) => JobRequest;
1280
+ export type SweepSortDirection = "Highest" | "Lowest";
1281
+ /** One authored sweep gene. Opaque to callers — built via the gene* builders. */
1282
+ export interface Gene {
1283
+ field: string;
1284
+ scope: string;
1285
+ target: Record<string, unknown>;
1286
+ values: unknown[];
1287
+ }
1288
+ /** Sweep Subject (Portfolio scope) over a value set. */
1289
+ export declare const geneSubject: (values: AssetArg[][]) => Gene;
1290
+ /** Sweep EntryCondition (Strategy scope) over a value set. */
1291
+ export declare const geneEntryCondition: (strategyIndex: number, values: Condition[]) => Gene;
1292
+ /** Sweep ExitCondition (Strategy scope) over a value set. */
1293
+ export declare const geneExitCondition: (strategyIndex: number, values: Condition[]) => Gene;
1294
+ /** Sweep EntryCooldownDays (Strategy scope) over a value set. */
1295
+ export declare const geneEntryCooldownDays: (strategyIndex: number, values: number[]) => Gene;
1296
+ /** Sweep RankSignal (Action scope) over a value set. */
1297
+ export declare const geneRankSignal: (strategyIndex: number, values: {
1298
+ indicator: Indicator;
1299
+ direction: SweepSortDirection;
1300
+ }[]) => Gene;
1301
+ /** Sweep BuyingPowerPct (Action scope) over a value set. */
1302
+ export declare const geneBuyingPowerPct: (strategyIndex: number, values: number[]) => Gene;
1303
+ /** Sweep AllocationPct (Action scope) over a value set. */
1304
+ export declare const geneAllocationPct: (strategyIndex: number, values: number[]) => Gene;
1305
+ /** Sweep TotalBudgetPct (Action scope) over a value set. */
1306
+ export declare const geneTotalBudgetPct: (strategyIndex: number, values: number[]) => Gene;
1307
+ /** Sweep DeploymentPct (Action scope) over a value set. */
1308
+ export declare const geneDeploymentPct: (strategyIndex: number, values: number[]) => Gene;
1309
+ /** Sweep RollTriggerDte (Action scope) over a value set. */
1310
+ export declare const geneRollTriggerDte: (strategyIndex: number, values: number[]) => Gene;
1311
+ /** Sweep TakeProfitPct (Action scope) over a value set. */
1312
+ export declare const geneTakeProfitPct: (strategyIndex: number, values: number[]) => Gene;
1313
+ /** Sweep StructureKind (Action scope) over a value set. */
1314
+ export declare const geneStructureKind: (strategyIndex: number, values: string[]) => Gene;
1315
+ /** Sweep OptionDelta (OptionLeg scope) over a value set. */
1316
+ export declare const geneOptionDelta: (strategyIndex: number, legIndex: number, values: number[]) => Gene;
1317
+ /** Sweep StrikeDistance (OptionLeg scope) over a value set. */
1318
+ export declare const geneStrikeDistance: (strategyIndex: number, legIndex: number, values: {
1319
+ distanceType: StrikeDistanceType;
1320
+ distance: number;
1321
+ }[]) => Gene;
1322
+ /** Sweep DteBracket (OptionLeg scope) over a value set. */
1323
+ export declare const geneDteBracket: (strategyIndex: number, legIndex: number, values: [number, number][]) => Gene;
1324
+ /** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
1325
+ export declare const geneSelectTopLimit: (strategyIndex: number, stageIndex: number, values: number[]) => Gene;
1326
+ /** Sweep UniversePipelineFilter (UniversePipeline scope) over a value set. */
1327
+ export declare const geneUniversePipelineFilter: (strategyIndex: number, stageIndex: number, values: Condition[]) => Gene;
1328
+ export {};