nexustrade 1.60.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -0
- package/dist/cjs/generated/ntSdk.generated.js +145 -40
- package/dist/esm/client.d.ts +3 -1
- package/dist/esm/generated/ntSdk.generated.d.ts +126 -27
- package/dist/esm/generated/ntSdk.generated.js +130 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1120,3 +1120,81 @@ agent needs to write correct NexusTrade strategies on the first pass.
|
|
|
1120
1120
|
## License
|
|
1121
1121
|
|
|
1122
1122
|
MIT
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
## Compositional trading controls (2.1)
|
|
1126
|
+
|
|
1127
|
+
Account rules compose the existing `PortfolioValue`, arithmetic, `IndicatorWindowAgo`,
|
|
1128
|
+
`IndicatorAtCondition` and ordinary conditions. A conditional snapshot can retain
|
|
1129
|
+
any numeric operand; it has no built-in gain thresholds or release policy.
|
|
1130
|
+
Its `selection` is `First`, `Latest`, `Maximum` or `Minimum`. An initial value
|
|
1131
|
+
is only a fallback before a capture (or after expiry), not part of the extrema.
|
|
1132
|
+
For a second crossing within an hour, capture with `First` and use
|
|
1133
|
+
`andThen(60, "Minute", crossing(), crossing())` as the condition, where
|
|
1134
|
+
`crossing()` builds `gt(CrossAbove(Price(asset), Value(level)), Value(0))`.
|
|
1135
|
+
Staying above the level is not another crossing. The first capture remains
|
|
1136
|
+
fixed on later crossings unless an expiry was configured.
|
|
1137
|
+
`PositionEntryPrice`, `PositionPeakPrice` and `PositionMinutesSinceHigh` are
|
|
1138
|
+
narrow position measurements. Reuse `MinutesSinceOrder` for purchase cadence.
|
|
1139
|
+
Settlement accounting remains on the portfolio.
|
|
1140
|
+
|
|
1141
|
+
`sellHoldings` (Python `sell_holdings`) is a Sell action with a candidate-bound
|
|
1142
|
+
holding condition. Its strategy condition supplies the account/market gate;
|
|
1143
|
+
only actual qualifying stock holdings are sold. Ordinary fixed-asset Sell
|
|
1144
|
+
actions retain their existing behavior.
|
|
1145
|
+
|
|
1146
|
+
A Buy action can configure `funding`: candidate `condition`, `rankBy` indicator,
|
|
1147
|
+
`direction` (Highest/Lowest), and source sale `amount` expressed as a percentage
|
|
1148
|
+
of current positions. The strategy owns its pending workflow and every order.
|
|
1149
|
+
It waits for actual fills and settlement and rechecks its current condition;
|
|
1150
|
+
proposed proceeds never become cash. Symbol order breaks equal ranking scores.
|
|
1151
|
+
|
|
1152
|
+
Buy/Sell `executionPriority` is an integer: lower numbers execute first.
|
|
1153
|
+
Funding sales may supply their own numeric priority, otherwise they inherit the
|
|
1154
|
+
purchase priority. Untagged trading events keep FIFO order. Broker submission
|
|
1155
|
+
ordering is scoped per portfolio; one account cannot delay another account's
|
|
1156
|
+
orders through its priority settings. Already submitted broker orders cannot be
|
|
1157
|
+
reordered. `pendingOrderPolicy: "WaitForTarget"` checks orders for the actual
|
|
1158
|
+
target asset without cancellation; the default waits for portfolio orders.
|
|
1159
|
+
Priority never changes a safety gate or chooses which holdings are weak.
|
|
1160
|
+
|
|
1161
|
+
The portfolio retains `cashSettlement: "T1"` and engine-owned actual-fill
|
|
1162
|
+
settlement accounting. Configure it before deployment; edits to this setting
|
|
1163
|
+
are restricted to undeployed drafts. Current integration supports stock/ETF
|
|
1164
|
+
Buy/Sell actions, alerts and watchlist producers. Other asset/executor paths
|
|
1165
|
+
remain explicitly rejected with T1 until integrated.
|
|
1166
|
+
|
|
1167
|
+
Public cash-only requests use `useMargin: false`. Live admission additionally
|
|
1168
|
+
uses Public's cash-only withdrawal balance as a conservative cap, which can be
|
|
1169
|
+
stricter than settled trading cash. Missing cash/calendar evidence blocks buys.
|
|
1170
|
+
Other brokers need a live T1 evidence adapter. Existing owner approval and trade
|
|
1171
|
+
limits apply. Native strategy/indicator runtime uses the existing checkpoint
|
|
1172
|
+
path; its verification does not establish live broker execution.
|
|
1173
|
+
|
|
1174
|
+
`ConsecutiveTrue` measures elapsed time while its ordinary condition stays true.
|
|
1175
|
+
`CountTrue` counts matching intervals inside a time lookback. For example, a
|
|
1176
|
+
20 `TradingDay` lookback with `countInterval: {length: 5, interval: "Minute"}`
|
|
1177
|
+
counts at most one match per five-minute interval across twenty exchange sessions.
|
|
1178
|
+
Omitting `countInterval` means one unit of the lookback interval. Comparisons and
|
|
1179
|
+
visit/crossing events belong in the ordinary `condition`, including `Then`.
|
|
1180
|
+
There are no sampled-comparison, distinct, cadence-count or clock modes.
|
|
1181
|
+
|
|
1182
|
+
`PortfolioValue` keeps its existing cash-plus-positions semantics during warmup
|
|
1183
|
+
and trading. Backtesting and paper trading do not depend on the selected pricing
|
|
1184
|
+
broker. Live capability checks reject T1 when the adapter lacks verified settled
|
|
1185
|
+
cash or cash-only submission support. Broker facts remain in the existing account
|
|
1186
|
+
reconciliation path. Porting a T1 strategy preserves its settlement policy.
|
|
1187
|
+
|
|
1188
|
+
For conditional capture, expiry runs from the retained observation's capture
|
|
1189
|
+
time. Minimum/Maximum with expiry is not a sliding-window minimum/maximum.
|
|
1190
|
+
`IndicatorMinimum` and `IndicatorMaximum` provide rolling extrema of one numeric
|
|
1191
|
+
operand. `CurrentValue(operand)` explicitly binds today's reference inside a
|
|
1192
|
+
historical CountTrue condition; historical operands retain their observed values.
|
|
1193
|
+
Outside that query it returns its operand. Bind the complete stateful operand,
|
|
1194
|
+
rather than inserting a reference inside its recurrence.
|
|
1195
|
+
|
|
1196
|
+
`TradingDay` windows use observed exchange sessions, including holidays and early
|
|
1197
|
+
closes. Elapsed Day/Hour/Minute windows keep their calendar meaning.
|
|
1198
|
+
`IndicatorWindowAgo` with `TradingDay` reads the confirmed value at the end of the
|
|
1199
|
+
reference session. Missing session evidence returns no value. `CurrentTimestamp`
|
|
1200
|
+
returns the evaluation time in Unix seconds, for ordinary candle-age comparisons.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.screenPercentile = exports.screenTop = exports.screenAny = exports.screenAll = exports.screenCompare = exports.screenDisclosure = exports.screenBarDollarVolume = exports.screenBarVolume = exports.screenPrice = exports.screenColumn = exports.updateScreenerWatchlist = exports.updateInsiderWatchlist = exports.updateInstitutionalWatchlist = exports.updateWatchlist = exports.launchAgent = exports.alert = exports.sell = exports.buy = exports.watchlistUniverse = exports.selectPercentile = exports.selectTop = exports.filter = exports.RebalanceNetBenefit = exports.RebalanceExpectedBenefit = exports.RebalanceEstimatedCost = exports.RebalancePlannedTurnover = exports.RebalanceAllocationDrift = exports.volatilityTarget = exports.maximumDiversificationAllocation = exports.riskParityAllocation = exports.meanVarianceAllocation = exports.always = exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = void 0;
|
|
3
|
+
exports.screenPercentile = exports.screenTop = exports.screenAny = exports.screenAll = exports.screenCompare = exports.screenDisclosure = exports.screenBarDollarVolume = exports.screenBarVolume = exports.screenPrice = exports.screenColumn = exports.updateScreenerWatchlist = exports.updateInsiderWatchlist = exports.updateInstitutionalWatchlist = exports.updateWatchlist = exports.launchAgent = exports.alert = exports.sellHoldings = exports.sell = exports.buy = exports.watchlistUniverse = exports.selectPercentile = exports.selectTop = exports.filter = exports.RebalanceNetBenefit = exports.RebalanceExpectedBenefit = exports.RebalanceEstimatedCost = exports.RebalancePlannedTurnover = exports.RebalanceAllocationDrift = exports.volatilityTarget = exports.maximumDiversificationAllocation = exports.riskParityAllocation = exports.meanVarianceAllocation = exports.always = exports.multi = exports.exactly = exports.fewerThan = exports.atMost = exports.atLeast = exports.or = exports.and = exports.neq = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.cryptoAsset = exports.stockAsset = exports.PORTFOLIO_WIDE = exports.CANDIDATE = void 0;
|
|
4
|
+
exports.geneAllocationPolicy = exports.geneStructureKind = exports.geneStopLossPct = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationDollars = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneConditionThreshold = exports.geneConditionWindowLength = exports.geneEntryCooldownDays = exports.geneReplaceExitCondition = exports.geneExitCondition = exports.geneReplaceEntryCondition = exports.geneEntryCondition = exports.geneSubject = exports.optimization = exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = exports.portfolio = exports.sessionFlatten = exports.strategy = exports.goodForMinutes = exports.goodForDay = exports.minimumNetCredit = exports.maximumNetDebit = exports.unitPriceLimit = exports.currentLimit = exports.limitOrder = exports.closeOption = exports.greeksTrigger = exports.daysHeldTrigger = exports.dteTrigger = exports.pnlTrigger = exports.rebalanceOption = exports.sleeve = exports.structureTemplate = exports.openOption = exports.againstParent = exports.optionsBuilder = exports.leg = exports.dynamicRebalance = void 0;
|
|
5
|
+
exports.geneAppendUniversePipelineFilter = exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = void 0;
|
|
6
|
+
exports.andThen = andThen;
|
|
6
7
|
exports.universe = universe;
|
|
7
8
|
exports.AbsoluteValue = AbsoluteValue;
|
|
8
9
|
exports.AccumulationDistribution = AccumulationDistribution;
|
|
@@ -26,6 +27,8 @@ exports.CrossBelow = CrossBelow;
|
|
|
26
27
|
exports.CurrentTimeHours = CurrentTimeHours;
|
|
27
28
|
exports.CurrentTimeMinutes = CurrentTimeMinutes;
|
|
28
29
|
exports.CurrentTimeSeconds = CurrentTimeSeconds;
|
|
30
|
+
exports.CurrentTimestamp = CurrentTimestamp;
|
|
31
|
+
exports.CurrentValue = CurrentValue;
|
|
29
32
|
exports.CustomIndicator = CustomIndicator;
|
|
30
33
|
exports.Date = Date;
|
|
31
34
|
exports.Day = Day;
|
|
@@ -51,10 +54,13 @@ exports.HighOfDay = HighOfDay;
|
|
|
51
54
|
exports.IchimokuCloud = IchimokuCloud;
|
|
52
55
|
exports.ImpliedVolatility = ImpliedVolatility;
|
|
53
56
|
exports.Index = Index;
|
|
57
|
+
exports.IndicatorAtCondition = IndicatorAtCondition;
|
|
54
58
|
exports.IndicatorAtEntry = IndicatorAtEntry;
|
|
55
59
|
exports.IndicatorAtMinutesAfterOpen = IndicatorAtMinutesAfterOpen;
|
|
56
60
|
exports.IndicatorExponentialMovingAverage = IndicatorExponentialMovingAverage;
|
|
61
|
+
exports.IndicatorMaximum = IndicatorMaximum;
|
|
57
62
|
exports.IndicatorMeanAbsoluteDeviation = IndicatorMeanAbsoluteDeviation;
|
|
63
|
+
exports.IndicatorMinimum = IndicatorMinimum;
|
|
58
64
|
exports.IndicatorRateOfChange = IndicatorRateOfChange;
|
|
59
65
|
exports.IndicatorSimpleMovingAverage = IndicatorSimpleMovingAverage;
|
|
60
66
|
exports.IndicatorStandardDeviation = IndicatorStandardDeviation;
|
|
@@ -121,8 +127,11 @@ exports.Plus = Plus;
|
|
|
121
127
|
exports.PoliticalPurchaseShare = PoliticalPurchaseShare;
|
|
122
128
|
exports.PoliticalTrades = PoliticalTrades;
|
|
123
129
|
exports.PortfolioValue = PortfolioValue;
|
|
130
|
+
exports.PositionEntryPrice = PositionEntryPrice;
|
|
124
131
|
exports.PositionMaxDrawdown = PositionMaxDrawdown;
|
|
125
132
|
exports.PositionMaxDrawup = PositionMaxDrawup;
|
|
133
|
+
exports.PositionMinutesSinceHigh = PositionMinutesSinceHigh;
|
|
134
|
+
exports.PositionPeakPrice = PositionPeakPrice;
|
|
126
135
|
exports.PositionPercentChange = PositionPercentChange;
|
|
127
136
|
exports.PositionValue = PositionValue;
|
|
128
137
|
exports.PreviousClosingPrice = PreviousClosingPrice;
|
|
@@ -260,6 +269,7 @@ function compact(obj) {
|
|
|
260
269
|
}
|
|
261
270
|
function compare(lhs, rhs, comparison) {
|
|
262
271
|
const right = typeof rhs === "number" ? Value(rhs) : rhs;
|
|
272
|
+
// Wire nodes carry no brand at runtime; nodeKind exists only in the types.
|
|
263
273
|
return { type: "Base", lhs, comparison, rhs: right };
|
|
264
274
|
}
|
|
265
275
|
const gt = (l, r) => compare(l, r, "greaterThan");
|
|
@@ -293,25 +303,11 @@ exports.exactly = exactly;
|
|
|
293
303
|
/** Multi with an explicit Comparator (same wire shape as YAML Multi). */
|
|
294
304
|
const multi = (count, comparison, ...conditions) => ({ type: "Multi", comparison, value: count, conditions });
|
|
295
305
|
exports.multi = multi;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
* transition, so with three or more steps each one must occur within the window
|
|
302
|
-
* of the step before it. Nesting is legal and means something different:
|
|
303
|
-
* `andThen(W, andThen(W, A, B), C)` is not `andThen(W, A, B, C)`.
|
|
304
|
-
*
|
|
305
|
-
* `interval` is REQUIRED and has no default. An omitted interval would fall
|
|
306
|
-
* back to Day and silently kill an intraday setup.
|
|
307
|
-
*
|
|
308
|
-
* Named `andThen` rather than `then`: a module namespace with a callable
|
|
309
|
-
* `then` export is assimilated as a thenable, so `await import("nexustrade")`
|
|
310
|
-
* would call it with resolve/reject and never settle. Emits wire type "Then",
|
|
311
|
-
* the same way atLeast/atMost/exactly emit "Multi".
|
|
312
|
-
*/
|
|
313
|
-
const andThen = (length, interval, ...conditions) => ({ type: "Then", conditions, window: { length, interval } });
|
|
314
|
-
exports.andThen = andThen;
|
|
306
|
+
function andThen(timing, first, ...rest) {
|
|
307
|
+
return (typeof timing === "number"
|
|
308
|
+
? { type: "Then", conditions: rest, window: { length: timing, interval: first } }
|
|
309
|
+
: { type: "Then", ...timing, conditions: [first, ...rest] });
|
|
310
|
+
}
|
|
315
311
|
/** Always-true gate for strategies whose cadence lives in the pipeline. */
|
|
316
312
|
const always = () => compare(Value(1), Value(0), "greaterThan");
|
|
317
313
|
exports.always = always;
|
|
@@ -384,10 +380,14 @@ function universe(source, assets) {
|
|
|
384
380
|
const watchlistUniverse = (watchlistKey) => ({ source: "WATCHLIST", watchlistKey });
|
|
385
381
|
exports.watchlistUniverse = watchlistUniverse;
|
|
386
382
|
// ---- equity + cash actions ----
|
|
387
|
-
const buy = (target, amount, type = "percent of portfolio") => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount } });
|
|
383
|
+
const buy = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
388
384
|
exports.buy = buy;
|
|
389
|
-
const sell = (target, amount, type = "percent of portfolio") => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount } });
|
|
385
|
+
const sell = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
390
386
|
exports.sell = sell;
|
|
387
|
+
/** Sell only actual holdings that pass a candidate-bound condition. */
|
|
388
|
+
const sellHoldings = (condition, amount = 100, type = "percent of current positions", options = {}) => ({ type: "Sell", targetAsset: (0, exports.stockAsset)("__PLACEHOLDER__"),
|
|
389
|
+
holdingCondition: condition, amount: { type, amount }, ...options });
|
|
390
|
+
exports.sellHoldings = sellHoldings;
|
|
391
391
|
const alert = (message) => ({ type: "Alert", message });
|
|
392
392
|
exports.alert = alert;
|
|
393
393
|
const launchAgent = (config) => compact({ type: "LaunchAgent", ...config });
|
|
@@ -748,7 +748,7 @@ function ConsecutiveIncrease(indicator, period, lookback) {
|
|
|
748
748
|
return d;
|
|
749
749
|
}
|
|
750
750
|
/**
|
|
751
|
-
*
|
|
751
|
+
* Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
|
|
752
752
|
* @param condition Condition evaluated over the window.
|
|
753
753
|
* @param length Length of time
|
|
754
754
|
* @param interval Unit of time
|
|
@@ -772,14 +772,17 @@ function Correlation(operands, length = 60, interval = "Day") {
|
|
|
772
772
|
return d;
|
|
773
773
|
}
|
|
774
774
|
/**
|
|
775
|
-
*
|
|
776
|
-
* @param condition
|
|
777
|
-
* @param length
|
|
778
|
-
* @param interval
|
|
775
|
+
* Count matching intervals inside a time lookback. The ordinary condition owns comparisons/events. countInterval contributes at most one match per interval; omitted means one unit of the lookback interval. TradingDay skips closed exchange dates.
|
|
776
|
+
* @param condition Ordinary condition whose matching intervals are counted.
|
|
777
|
+
* @param length Lookback length.
|
|
778
|
+
* @param interval Lookback time unit; TradingDay uses observed exchange sessions.
|
|
779
|
+
* @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
|
|
779
780
|
*/
|
|
780
|
-
function CountTrue(condition, length = 1, interval = "Day") {
|
|
781
|
+
function CountTrue(condition, length = 1, interval = "Day", countInterval) {
|
|
781
782
|
const d = { type: "CountTrue" };
|
|
782
783
|
d.condition = condition;
|
|
784
|
+
if (countInterval !== undefined)
|
|
785
|
+
d["countInterval"] = countInterval;
|
|
783
786
|
d.window = { length: length, interval: interval };
|
|
784
787
|
return d;
|
|
785
788
|
}
|
|
@@ -820,6 +823,21 @@ function CurrentTimeSeconds() {
|
|
|
820
823
|
const d = { type: "CurrentTimeSeconds" };
|
|
821
824
|
return d;
|
|
822
825
|
}
|
|
826
|
+
/**
|
|
827
|
+
* Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
|
|
828
|
+
*/
|
|
829
|
+
function CurrentTimestamp() {
|
|
830
|
+
const d = { type: "CurrentTimestamp" };
|
|
831
|
+
return d;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Inside a CountTrue historical condition, bind this operand at its value now while other operands use their historical observations. Elsewhere return the operand normally. Wrap a complete stateful operand, not an expression inside its recurrence.
|
|
835
|
+
*/
|
|
836
|
+
function CurrentValue(operand) {
|
|
837
|
+
const d = { type: "CurrentValue" };
|
|
838
|
+
d.indicators = [operand];
|
|
839
|
+
return d;
|
|
840
|
+
}
|
|
823
841
|
/**
|
|
824
842
|
* CustomIndicator indicator.
|
|
825
843
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
|
|
@@ -1078,17 +1096,34 @@ function Index(metric = "VIX") {
|
|
|
1078
1096
|
d["metric"] = metric;
|
|
1079
1097
|
return d;
|
|
1080
1098
|
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Retain the operand from matching observations: First, Latest, Maximum, or Minimum. Ordinary conditions decide when to capture. An optional window expires observations; TradingDay skips closed exchange dates. Use this to freeze a qualified setup before entry or ratchet a numeric level, not IndicatorAtEntry when no fill exists yet.
|
|
1101
|
+
* @param condition Condition evaluated over the window.
|
|
1102
|
+
*/
|
|
1103
|
+
function IndicatorAtCondition(operand, condition, selection = "First", clock = "Calendar", initialValue, length, interval) {
|
|
1104
|
+
const d = { type: "IndicatorAtCondition" };
|
|
1105
|
+
d.condition = condition;
|
|
1106
|
+
d["selection"] = selection;
|
|
1107
|
+
d["clock"] = clock;
|
|
1108
|
+
if (initialValue !== undefined)
|
|
1109
|
+
d["initialValue"] = initialValue;
|
|
1110
|
+
d.indicators = [operand];
|
|
1111
|
+
if (length !== undefined || interval !== undefined)
|
|
1112
|
+
d.window = { length: length, interval: interval };
|
|
1113
|
+
return d;
|
|
1114
|
+
}
|
|
1081
1115
|
/**
|
|
1082
1116
|
* IndicatorAtEntry indicator.
|
|
1083
1117
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1084
1118
|
* @param side The side of the fill the value is anchored to
|
|
1085
1119
|
* @param orderStatus Matches order events with this status
|
|
1086
1120
|
*/
|
|
1087
|
-
function IndicatorAtEntry(operand, asset, side, orderStatus = "Filled") {
|
|
1121
|
+
function IndicatorAtEntry(operand, asset, side, orderStatus = "Filled", anchor = "LatestFill") {
|
|
1088
1122
|
const d = { type: "IndicatorAtEntry" };
|
|
1089
1123
|
setAsset(d, "targetAsset", asset);
|
|
1090
1124
|
d["side"] = side;
|
|
1091
1125
|
d["orderStatus"] = orderStatus;
|
|
1126
|
+
d["anchor"] = anchor;
|
|
1092
1127
|
d.indicators = [operand];
|
|
1093
1128
|
return d;
|
|
1094
1129
|
}
|
|
@@ -1113,6 +1148,17 @@ function IndicatorExponentialMovingAverage(operand, length = 30, interval = "Day
|
|
|
1113
1148
|
d.window = { length: length, interval: interval };
|
|
1114
1149
|
return d;
|
|
1115
1150
|
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Rolling maximum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
|
|
1153
|
+
* @param length Length of time
|
|
1154
|
+
* @param interval Unit of time
|
|
1155
|
+
*/
|
|
1156
|
+
function IndicatorMaximum(operand, length = 30, interval = "Day") {
|
|
1157
|
+
const d = { type: "IndicatorMaximum" };
|
|
1158
|
+
d.indicators = [operand];
|
|
1159
|
+
d.window = { length: length, interval: interval };
|
|
1160
|
+
return d;
|
|
1161
|
+
}
|
|
1116
1162
|
/**
|
|
1117
1163
|
* IndicatorMeanAbsoluteDeviation indicator.
|
|
1118
1164
|
* @param length Length of time
|
|
@@ -1124,6 +1170,17 @@ function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval = "Day")
|
|
|
1124
1170
|
d.window = { length: length, interval: interval };
|
|
1125
1171
|
return d;
|
|
1126
1172
|
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Rolling minimum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
|
|
1175
|
+
* @param length Length of time
|
|
1176
|
+
* @param interval Unit of time
|
|
1177
|
+
*/
|
|
1178
|
+
function IndicatorMinimum(operand, length = 30, interval = "Day") {
|
|
1179
|
+
const d = { type: "IndicatorMinimum" };
|
|
1180
|
+
d.indicators = [operand];
|
|
1181
|
+
d.window = { length: length, interval: interval };
|
|
1182
|
+
return d;
|
|
1183
|
+
}
|
|
1127
1184
|
/**
|
|
1128
1185
|
* IndicatorRateOfChange indicator.
|
|
1129
1186
|
* @param length Length of time
|
|
@@ -1158,20 +1215,22 @@ function IndicatorStandardDeviation(operand, length = 30, interval = "Day") {
|
|
|
1158
1215
|
return d;
|
|
1159
1216
|
}
|
|
1160
1217
|
/**
|
|
1161
|
-
*
|
|
1218
|
+
* Value at an elapsed time in the past. TradingDay instead reads the confirmed closing value of the reference exchange session, including early closes. Missing session evidence returns no value; initialValue applies before enough history exists.
|
|
1162
1219
|
* @param length Length of time
|
|
1163
1220
|
* @param interval Unit of time
|
|
1164
1221
|
*/
|
|
1165
|
-
function IndicatorWindowAgo(operand, length, interval) {
|
|
1222
|
+
function IndicatorWindowAgo(operand, length, interval, initialValue) {
|
|
1166
1223
|
const d = { type: "IndicatorWindowAgo" };
|
|
1224
|
+
if (initialValue !== undefined)
|
|
1225
|
+
d["initialValue"] = initialValue;
|
|
1167
1226
|
d.indicators = [operand];
|
|
1168
1227
|
d.window = { length: length, interval: interval };
|
|
1169
1228
|
return d;
|
|
1170
1229
|
}
|
|
1171
1230
|
/**
|
|
1172
|
-
* News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines.
|
|
1231
|
+
* News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. The value is the same for every asset: it takes no target asset.
|
|
1173
1232
|
* @param industry Canonical industry tag whose news to read, as IsIndustry lists it. Legacy aliases are separate news series and are rejected, never mapped.
|
|
1174
|
-
* @param measure Median: middle score from -1 to 1 (the average of the two middle scores for an even count), with no value when no qualifying headline. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying headline. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value
|
|
1233
|
+
* @param measure Median: middle score from -1 to 1 (the average of the two middle scores for an even count), with no value when no qualifying headline. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying headline. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value across missing snapshots or when the due snapshot is unpublished. Before coverage begins on 2019-09-23 the window holds the sessions available.
|
|
1175
1234
|
* @param lookbackDays Whole trading sessions of daily 09:15 New York news snapshots; 1 is the latest and about 20 is the usual window. The same value for every asset.
|
|
1176
1235
|
*/
|
|
1177
1236
|
function IndustryNewsSentiment(industry, measure = "Mean", lookbackDays = 1) {
|
|
@@ -1513,12 +1572,15 @@ function MinutesSinceOptionOrder(underlying, optionType, direction, spreadType,
|
|
|
1513
1572
|
* MinutesSinceOrder indicator.
|
|
1514
1573
|
* @param assets Ticker(s) whose orders are counted. One string or an array.
|
|
1515
1574
|
* @param side Buy or Sell
|
|
1575
|
+
* @param clock Optional elapsed-time clock; omitted retains calendar minutes.
|
|
1516
1576
|
*/
|
|
1517
|
-
function MinutesSinceOrder(assets, side, orderStatus = "Filled") {
|
|
1577
|
+
function MinutesSinceOrder(assets, side, orderStatus = "Filled", clock) {
|
|
1518
1578
|
const d = { type: "MinutesSinceOrder" };
|
|
1519
1579
|
setAssets(d, "targetAssets", assets);
|
|
1520
1580
|
d["side"] = side;
|
|
1521
1581
|
d["orderStatus"] = orderStatus;
|
|
1582
|
+
if (clock !== undefined)
|
|
1583
|
+
d["clock"] = clock;
|
|
1522
1584
|
return d;
|
|
1523
1585
|
}
|
|
1524
1586
|
/**
|
|
@@ -1624,9 +1686,9 @@ function NewPoliticalDisclosure(memberId, instrument, disclosureAction) {
|
|
|
1624
1686
|
return d;
|
|
1625
1687
|
}
|
|
1626
1688
|
/**
|
|
1627
|
-
* News sentiment about the asset over its last lookbackDays daily news snapshots (default 1, the latest). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that names the company: whether it is really about the company, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the asset had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the company count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines.
|
|
1689
|
+
* News sentiment about the asset over its last lookbackDays daily news snapshots (default 1, the latest). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that names the company: whether it is really about the company, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the asset had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the company count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. Headlines are matched to the issuer, so every listed share class reads the same news and META reads Facebook-era headlines.
|
|
1628
1690
|
* @param asset Pass CANDIDATE in a dynamic rebalance pipeline.
|
|
1629
|
-
* @param measure Median: middle score from -1 to 1, with no value when no qualifying news. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying news. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value
|
|
1691
|
+
* @param measure Median: middle score from -1 to 1, with no value when no qualifying news. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying news. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value across missing snapshots or when the due snapshot is unpublished. Before coverage begins on 2019-09-23 the window holds the sessions available.
|
|
1630
1692
|
* @param lookbackDays Whole trading sessions of daily 09:15 New York news snapshots; 1 is the latest. A row is visible from the snapshot the lake assigned it, the same time in backtests and live trading.
|
|
1631
1693
|
*/
|
|
1632
1694
|
function NewsSentiment(asset, measure = "Mean", lookbackDays = 1) {
|
|
@@ -1922,6 +1984,15 @@ function PortfolioValue() {
|
|
|
1922
1984
|
const d = { type: "PortfolioValue" };
|
|
1923
1985
|
return d;
|
|
1924
1986
|
}
|
|
1987
|
+
/**
|
|
1988
|
+
* Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
|
|
1989
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1990
|
+
*/
|
|
1991
|
+
function PositionEntryPrice(asset) {
|
|
1992
|
+
const d = { type: "PositionEntryPrice" };
|
|
1993
|
+
setAsset(d, "targetAsset", asset);
|
|
1994
|
+
return d;
|
|
1995
|
+
}
|
|
1925
1996
|
/**
|
|
1926
1997
|
* PositionMaxDrawdown indicator.
|
|
1927
1998
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
@@ -1940,6 +2011,24 @@ function PositionMaxDrawup(asset) {
|
|
|
1940
2011
|
setAsset(d, "targetAsset", asset);
|
|
1941
2012
|
return d;
|
|
1942
2013
|
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Exchange trading minutes since the current holding's last new high. Closed-market minutes do not count. Added shares preserve the holding's observation path.
|
|
2016
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
2017
|
+
*/
|
|
2018
|
+
function PositionMinutesSinceHigh(asset) {
|
|
2019
|
+
const d = { type: "PositionMinutesSinceHigh" };
|
|
2020
|
+
setAsset(d, "targetAsset", asset);
|
|
2021
|
+
return d;
|
|
2022
|
+
}
|
|
2023
|
+
/**
|
|
2024
|
+
* Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
|
|
2025
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
2026
|
+
*/
|
|
2027
|
+
function PositionPeakPrice(asset) {
|
|
2028
|
+
const d = { type: "PositionPeakPrice" };
|
|
2029
|
+
setAsset(d, "targetAsset", asset);
|
|
2030
|
+
return d;
|
|
2031
|
+
}
|
|
1943
2032
|
/**
|
|
1944
2033
|
* PositionPercentChange indicator.
|
|
1945
2034
|
* @param assets Ticker name (ex. SPY, BTC)
|
|
@@ -2394,6 +2483,14 @@ const geneAllocationPct = (strategyIndex, values) => ({
|
|
|
2394
2483
|
values: values,
|
|
2395
2484
|
});
|
|
2396
2485
|
exports.geneAllocationPct = geneAllocationPct;
|
|
2486
|
+
/** Sweep AllocationDollars (Action scope) over a value set. */
|
|
2487
|
+
const geneAllocationDollars = (strategyIndex, values) => ({
|
|
2488
|
+
field: "AllocationDollars",
|
|
2489
|
+
scope: "Action",
|
|
2490
|
+
target: { scope: "Action", field: "AllocationDollars", strategyIndex },
|
|
2491
|
+
values: values,
|
|
2492
|
+
});
|
|
2493
|
+
exports.geneAllocationDollars = geneAllocationDollars;
|
|
2397
2494
|
/** Sweep TotalBudgetPct (Action scope) over a value set. */
|
|
2398
2495
|
const geneTotalBudgetPct = (strategyIndex, values) => ({
|
|
2399
2496
|
field: "TotalBudgetPct",
|
|
@@ -2491,10 +2588,10 @@ const geneMaxSpreadPct = (strategyIndex, legIndex, values) => ({
|
|
|
2491
2588
|
});
|
|
2492
2589
|
exports.geneMaxSpreadPct = geneMaxSpreadPct;
|
|
2493
2590
|
/** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
|
|
2494
|
-
const geneSelectTopLimit = (strategyIndex,
|
|
2591
|
+
const geneSelectTopLimit = (strategyIndex, values, sleeveName) => ({
|
|
2495
2592
|
field: "SelectTopLimit",
|
|
2496
2593
|
scope: "UniversePipeline",
|
|
2497
|
-
target: { scope: "UniversePipeline", field: "SelectTopLimit", strategyIndex,
|
|
2594
|
+
target: { scope: "UniversePipeline", field: "SelectTopLimit", strategyIndex, ...(sleeveName === undefined ? {} : { sleeveName }) },
|
|
2498
2595
|
values: values,
|
|
2499
2596
|
});
|
|
2500
2597
|
exports.geneSelectTopLimit = geneSelectTopLimit;
|
|
@@ -2506,3 +2603,11 @@ const geneUniversePipelineFilter = (strategyIndex, stageIndex, values) => ({
|
|
|
2506
2603
|
values: values,
|
|
2507
2604
|
});
|
|
2508
2605
|
exports.geneUniversePipelineFilter = geneUniversePipelineFilter;
|
|
2606
|
+
/** Sweep UniversePipelineFilter (UniversePipeline scope) by adding a Filter stage to a pipeline that has none to replace. The stage goes ahead of the first SelectTop/SelectPercentile, so it narrows the universe before ranking. */
|
|
2607
|
+
const geneAppendUniversePipelineFilter = (strategyIndex, values, sleeveName) => ({
|
|
2608
|
+
field: "UniversePipelineFilter",
|
|
2609
|
+
scope: "UniversePipeline",
|
|
2610
|
+
target: { scope: "UniversePipeline", field: "UniversePipelineFilter", strategyIndex, ...(sleeveName === undefined ? {} : { sleeveName }), append: true },
|
|
2611
|
+
values: values,
|
|
2612
|
+
});
|
|
2613
|
+
exports.geneAppendUniversePipelineFilter = geneAppendUniversePipelineFilter;
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -75,7 +75,9 @@ export interface ReplaceStrategiesOperation {
|
|
|
75
75
|
/** Complete finished authored patch; omitted fields retain their saved values. */
|
|
76
76
|
export interface UpdatePortfolioOperation {
|
|
77
77
|
type: "updatePortfolio";
|
|
78
|
-
portfolio: Partial<Pick<Portfolio, "name" | "initialValue" | "strategies" | "deployment" | "policy" | "dividendPolicy" | "alertsEnabled" | "supportsFractionalShares" | "supportsCrypto"
|
|
78
|
+
portfolio: Partial<Pick<Portfolio, "name" | "initialValue" | "strategies" | "deployment" | "policy" | "dividendPolicy" | "alertsEnabled" | "supportsFractionalShares" | "supportsCrypto">> & {
|
|
79
|
+
cashSettlement?: Portfolio["cashSettlement"] | null;
|
|
80
|
+
};
|
|
79
81
|
}
|
|
80
82
|
/** All operations in one call for this portfolio are validated and saved atomically. */
|
|
81
83
|
export type PortfolioEditOperation = UpdatePortfolioOperation | PortfolioRenameOperation | AddStrategiesOperation | RemoveStrategiesOperation | ReplaceStrategyOperation | ReplaceStrategiesOperation;
|
|
@@ -18,19 +18,40 @@ export type PortfolioWide = {
|
|
|
18
18
|
/** Concrete assets must be built with stockAsset() / cryptoAsset() — no bare ticker strings. */
|
|
19
19
|
export type AssetArg = Asset | Candidate | PortfolioWide;
|
|
20
20
|
/**
|
|
21
|
-
* Opaque: indicators are only ever constructed through the
|
|
22
|
-
*
|
|
23
|
-
* defeated by the `[key: string]: unknown` index signature
|
|
24
|
-
*
|
|
21
|
+
* Opaque: indicators and conditions are only ever constructed through the
|
|
22
|
+
* builders below. Brands use unique symbols (not string keys) so they are not
|
|
23
|
+
* defeated by the `[key: string]: unknown` index signature.
|
|
24
|
+
*
|
|
25
|
+
* nodeKind keeps the two nominally distinct. Without it both interfaces are the
|
|
26
|
+
* same structure, so a bare `IsIndustry(CANDIDATE, "technology")` inside
|
|
27
|
+
* `and(...)` (or cast `as CandidateCondition`) typechecked and only failed at
|
|
28
|
+
* save time. The literal values are the text the typecheck error shows.
|
|
29
|
+
*
|
|
30
|
+
* candidateBound lets strategy() reject candidate-bound gates while
|
|
31
|
+
* filter()/eligibility still accept them.
|
|
25
32
|
*/
|
|
33
|
+
declare const nodeKind: unique symbol;
|
|
26
34
|
export interface Indicator {
|
|
27
35
|
type: string;
|
|
36
|
+
readonly [nodeKind]: "Indicator (a number, not a condition): compare it to get a condition, e.g. gt(IsIndustry(CANDIDATE, 'technology'), Value(0)) or lt(RSI(CANDIDATE, 14), Value(30))";
|
|
28
37
|
[key: string]: unknown;
|
|
29
38
|
}
|
|
30
39
|
export interface Condition {
|
|
31
40
|
type: string;
|
|
41
|
+
readonly [nodeKind]: "Condition (true/false, not an indicator)";
|
|
32
42
|
[key: string]: unknown;
|
|
33
43
|
}
|
|
44
|
+
/** Existing native Then timing: optional maximum window and trading-time wait. */
|
|
45
|
+
export interface ThenTiming {
|
|
46
|
+
window?: {
|
|
47
|
+
length: number;
|
|
48
|
+
interval: Interval;
|
|
49
|
+
};
|
|
50
|
+
transition: {
|
|
51
|
+
minimumTradingMinutes: number;
|
|
52
|
+
waiting: boolean;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
34
55
|
declare const candidateBound: unique symbol;
|
|
35
56
|
/** Indicator bound to the pipeline candidate (Price(CANDIDATE), …). */
|
|
36
57
|
export type CandidateIndicator = Indicator & {
|
|
@@ -254,10 +275,21 @@ export type CloseOptionTrigger = {
|
|
|
254
275
|
minSpreadTheta?: number;
|
|
255
276
|
maxSpreadTheta?: number;
|
|
256
277
|
};
|
|
278
|
+
export type ExecutionPriority = number;
|
|
279
|
+
export interface PurchaseFunding {
|
|
280
|
+
executionPriority?: number;
|
|
281
|
+
condition: Condition;
|
|
282
|
+
rankBy: Indicator;
|
|
283
|
+
direction: SelectDirection;
|
|
284
|
+
amount: Allocation;
|
|
285
|
+
}
|
|
257
286
|
export interface BuyOrSellAction {
|
|
258
287
|
type: "Buy" | "Sell";
|
|
259
288
|
targetAsset: Asset;
|
|
260
289
|
amount: Allocation;
|
|
290
|
+
executionPriority?: ExecutionPriority;
|
|
291
|
+
funding?: PurchaseFunding;
|
|
292
|
+
holdingCondition?: Condition;
|
|
261
293
|
}
|
|
262
294
|
export interface DepositOrWithdrawAction {
|
|
263
295
|
type: "Deposit" | "Withdraw";
|
|
@@ -524,7 +556,7 @@ export interface Strategy {
|
|
|
524
556
|
/** Omitted means Market. Limit always requires an explicit price policy. */
|
|
525
557
|
orderExecution?: StrategyOrderExecutionPolicy;
|
|
526
558
|
/** Backtest-only exit priority. CancelConflictingBuys cannot deploy to paper/live trading. */
|
|
527
|
-
pendingOrderPolicy?: "Wait" | "CancelConflictingBuys";
|
|
559
|
+
pendingOrderPolicy?: "Wait" | "WaitForTarget" | "CancelConflictingBuys";
|
|
528
560
|
}
|
|
529
561
|
export interface AuthoredIndustryFilter {
|
|
530
562
|
mode: "ALL" | "INCLUDE_ONLY";
|
|
@@ -567,12 +599,14 @@ export interface Portfolio {
|
|
|
567
599
|
alertsEnabled?: boolean;
|
|
568
600
|
/** "cash" (default when omitted) or "reinvest" into the paying stock. */
|
|
569
601
|
dividendPolicy?: DividendPolicy;
|
|
602
|
+
/** Cash-only T+1 proceeds. Missing live cash-cap evidence blocks purchases. */
|
|
603
|
+
cashSettlement?: "T1" | null;
|
|
570
604
|
policy?: AuthoredPortfolioPolicy;
|
|
571
605
|
deployment?: AuthoredDeploymentTiming;
|
|
572
606
|
}
|
|
573
607
|
export type DividendPolicy = "cash" | "reinvest";
|
|
574
608
|
export type AssetType = "Stock" | "Cryptocurrency" | "Option" | "Other";
|
|
575
|
-
export type Interval = "Day" | "Hour" | "Minute";
|
|
609
|
+
export type Interval = "Day" | "Hour" | "Minute" | "TradingDay";
|
|
576
610
|
export type Comparator = "lessThan" | "greaterThan" | "lessThanOrEqual" | "greaterThanOrEqual" | "equal" | "notEqual";
|
|
577
611
|
export type SelectDirection = "Highest" | "Lowest";
|
|
578
612
|
export type UniverseSource = "ALL_US_STOCKS" | "SP500" | "NASDAQ100" | "DJIA" | "CRYPTO" | "SPECIFIC_ASSETS" | "WATCHLIST";
|
|
@@ -595,6 +629,7 @@ export type Period = "Year" | "Quarter" | "Month";
|
|
|
595
629
|
export type PositionEffect = "open" | "close";
|
|
596
630
|
export type OrderStatus = "Pending" | "Accepted" | "Pending User Approval" | "Canceled" | "Filled" | "Partially Filled";
|
|
597
631
|
export type Side = "Buy" | "Sell";
|
|
632
|
+
export type Clock = "Calendar" | "Trading";
|
|
598
633
|
export type Measure = "Mean" | "Median" | "NetCount" | "ArticleCount";
|
|
599
634
|
export type Role = "Any" | "Officer" | "Director" | "TenPercentOwner" | "OfficerOrDirector";
|
|
600
635
|
export type Instrument = "Equity" | "Call" | "Put";
|
|
@@ -643,7 +678,8 @@ export declare const multi: (count: number, comparison: Comparator, ...condition
|
|
|
643
678
|
* would call it with resolve/reject and never settle. Emits wire type "Then",
|
|
644
679
|
* the same way atLeast/atMost/exactly emit "Multi".
|
|
645
680
|
*/
|
|
646
|
-
export declare
|
|
681
|
+
export declare function andThen(length: number, interval: Interval, ...conditions: Condition[]): Condition;
|
|
682
|
+
export declare function andThen(timing: ThenTiming, ...conditions: Condition[]): Condition;
|
|
647
683
|
/** Always-true gate for strategies whose cadence lives in the pipeline. */
|
|
648
684
|
export declare const always: () => Condition;
|
|
649
685
|
export declare const meanVarianceAllocation: (config?: Partial<Omit<MeanVarianceAllocationPolicy, "type">>) => MeanVarianceAllocationPolicy;
|
|
@@ -662,8 +698,17 @@ export declare function universe(source: "ALL_US_STOCKS" | "SP500" | "NASDAQ100"
|
|
|
662
698
|
export declare function universe(source: "SPECIFIC_ASSETS", assets: AssetArg[]): Universe;
|
|
663
699
|
/** The latest revision of the list an updateWatchlist producer in this portfolio maintains. */
|
|
664
700
|
export declare const watchlistUniverse: (watchlistKey: string) => Universe;
|
|
665
|
-
export declare const buy: (target: AssetArg, amount: number, type?: AllocationType
|
|
666
|
-
|
|
701
|
+
export declare const buy: (target: AssetArg, amount: number, type?: AllocationType, options?: {
|
|
702
|
+
executionPriority?: ExecutionPriority;
|
|
703
|
+
funding?: PurchaseFunding;
|
|
704
|
+
}) => BuyOrSellAction;
|
|
705
|
+
export declare const sell: (target: AssetArg, amount: number, type?: AllocationType, options?: {
|
|
706
|
+
executionPriority?: ExecutionPriority;
|
|
707
|
+
}) => BuyOrSellAction;
|
|
708
|
+
/** Sell only actual holdings that pass a candidate-bound condition. */
|
|
709
|
+
export declare const sellHoldings: (condition: Condition, amount?: number, type?: AllocationType, options?: {
|
|
710
|
+
executionPriority?: ExecutionPriority;
|
|
711
|
+
}) => BuyOrSellAction;
|
|
667
712
|
export declare const alert: (message: string) => AlertAction;
|
|
668
713
|
export declare const launchAgent: (config: {
|
|
669
714
|
planningModel: string;
|
|
@@ -845,6 +890,8 @@ export declare const portfolio: (name: string, strategies: Strategy[], options?:
|
|
|
845
890
|
supportsCrypto?: boolean;
|
|
846
891
|
alertsEnabled?: boolean;
|
|
847
892
|
dividendPolicy?: DividendPolicy;
|
|
893
|
+
/** Cash-only T+1 proceeds. Missing live cash-cap evidence blocks purchases. */
|
|
894
|
+
cashSettlement?: "T1" | null;
|
|
848
895
|
policy?: AuthoredPortfolioPolicy;
|
|
849
896
|
deployment?: AuthoredDeploymentTiming;
|
|
850
897
|
}) => PortfolioHandle;
|
|
@@ -912,7 +959,7 @@ export declare function ChaikinMoneyFlow(asset: AssetArg, length?: number, inter
|
|
|
912
959
|
* @param offsetBars Skip this many latest completed candles. 1 selects the previous window.
|
|
913
960
|
* @param minutePolicy strict requires every minute. observed aggregates actual eligible-trade prints, skips empty candles, and publishes after the clock bucket closes. No synthetic prices; source coverage is a separate check.
|
|
914
961
|
*/
|
|
915
|
-
export declare function ChartBar(asset: AssetArg, barMinutes?: number, line?: "open" | "high" | "low" | "close" | "sma", bars?: number, offsetBars?: number, minutePolicy?: "strict" | "observed"): Indicator;
|
|
962
|
+
export declare function ChartBar(asset: AssetArg, barMinutes?: number, line?: "open" | "high" | "low" | "close" | "sma" | "endTime", bars?: number, offsetBars?: number, minutePolicy?: "strict" | "observed"): Indicator;
|
|
916
963
|
/**
|
|
917
964
|
* CommodityChannelIndex indicator.
|
|
918
965
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
@@ -943,7 +990,7 @@ export declare function ConsecutiveDecrease(indicator: Indicator, period: Period
|
|
|
943
990
|
*/
|
|
944
991
|
export declare function ConsecutiveIncrease(indicator: Indicator, period: Period, lookback: number): Indicator;
|
|
945
992
|
/**
|
|
946
|
-
*
|
|
993
|
+
* Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
|
|
947
994
|
* @param condition Condition evaluated over the window.
|
|
948
995
|
* @param length Length of time
|
|
949
996
|
* @param interval Unit of time
|
|
@@ -957,12 +1004,16 @@ export declare function ConsecutiveTrue(condition: Condition, length?: number, i
|
|
|
957
1004
|
*/
|
|
958
1005
|
export declare function Correlation(operands: Indicator[], length?: number, interval?: Interval): Indicator;
|
|
959
1006
|
/**
|
|
960
|
-
*
|
|
961
|
-
* @param condition
|
|
962
|
-
* @param length
|
|
963
|
-
* @param interval
|
|
1007
|
+
* Count matching intervals inside a time lookback. The ordinary condition owns comparisons/events. countInterval contributes at most one match per interval; omitted means one unit of the lookback interval. TradingDay skips closed exchange dates.
|
|
1008
|
+
* @param condition Ordinary condition whose matching intervals are counted.
|
|
1009
|
+
* @param length Lookback length.
|
|
1010
|
+
* @param interval Lookback time unit; TradingDay uses observed exchange sessions.
|
|
1011
|
+
* @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
|
|
964
1012
|
*/
|
|
965
|
-
export declare function CountTrue(condition: Condition, length?: number, interval?: Interval
|
|
1013
|
+
export declare function CountTrue(condition: Condition, length?: number, interval?: Interval, countInterval?: {
|
|
1014
|
+
length: number;
|
|
1015
|
+
interval: Interval;
|
|
1016
|
+
}): Indicator;
|
|
966
1017
|
/**
|
|
967
1018
|
* CrossAbove indicator.
|
|
968
1019
|
*/
|
|
@@ -983,6 +1034,14 @@ export declare function CurrentTimeMinutes(): Indicator;
|
|
|
983
1034
|
* CurrentTimeSeconds indicator.
|
|
984
1035
|
*/
|
|
985
1036
|
export declare function CurrentTimeSeconds(): Indicator;
|
|
1037
|
+
/**
|
|
1038
|
+
* Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
|
|
1039
|
+
*/
|
|
1040
|
+
export declare function CurrentTimestamp(): Indicator;
|
|
1041
|
+
/**
|
|
1042
|
+
* Inside a CountTrue historical condition, bind this operand at its value now while other operands use their historical observations. Elsewhere return the operand normally. Wrap a complete stateful operand, not an expression inside its recurrence.
|
|
1043
|
+
*/
|
|
1044
|
+
export declare function CurrentValue(operand: Indicator): Indicator;
|
|
986
1045
|
/**
|
|
987
1046
|
* CustomIndicator indicator.
|
|
988
1047
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
|
|
@@ -1125,13 +1184,18 @@ export declare function ImpliedVolatility(asset: AssetArg, dte?: number): Indica
|
|
|
1125
1184
|
* @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
|
|
1126
1185
|
*/
|
|
1127
1186
|
export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "USDBROAD" | "TNX"): Indicator;
|
|
1187
|
+
/**
|
|
1188
|
+
* Retain the operand from matching observations: First, Latest, Maximum, or Minimum. Ordinary conditions decide when to capture. An optional window expires observations; TradingDay skips closed exchange dates. Use this to freeze a qualified setup before entry or ratchet a numeric level, not IndicatorAtEntry when no fill exists yet.
|
|
1189
|
+
* @param condition Condition evaluated over the window.
|
|
1190
|
+
*/
|
|
1191
|
+
export declare function IndicatorAtCondition(operand: Indicator, condition: Condition, selection?: "First" | "Latest" | "Maximum" | "Minimum", clock?: Clock, initialValue?: number, length?: number, interval?: Interval): Indicator;
|
|
1128
1192
|
/**
|
|
1129
1193
|
* IndicatorAtEntry indicator.
|
|
1130
1194
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1131
1195
|
* @param side The side of the fill the value is anchored to
|
|
1132
1196
|
* @param orderStatus Matches order events with this status
|
|
1133
1197
|
*/
|
|
1134
|
-
export declare function IndicatorAtEntry(operand: Indicator, asset: AssetArg, side: Side, orderStatus?: OrderStatus): Indicator;
|
|
1198
|
+
export declare function IndicatorAtEntry(operand: Indicator, asset: AssetArg, side: Side, orderStatus?: OrderStatus, anchor?: "LatestFill" | "HoldingEntry"): Indicator;
|
|
1135
1199
|
/**
|
|
1136
1200
|
* IndicatorAtMinutesAfterOpen indicator.
|
|
1137
1201
|
* @param minutesAfterOpen The number of minutes after market open to capture the indicator value
|
|
@@ -1143,12 +1207,24 @@ export declare function IndicatorAtMinutesAfterOpen(operand: Indicator, minutesA
|
|
|
1143
1207
|
* @param interval Unit of time
|
|
1144
1208
|
*/
|
|
1145
1209
|
export declare function IndicatorExponentialMovingAverage(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1210
|
+
/**
|
|
1211
|
+
* Rolling maximum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
|
|
1212
|
+
* @param length Length of time
|
|
1213
|
+
* @param interval Unit of time
|
|
1214
|
+
*/
|
|
1215
|
+
export declare function IndicatorMaximum(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1146
1216
|
/**
|
|
1147
1217
|
* IndicatorMeanAbsoluteDeviation indicator.
|
|
1148
1218
|
* @param length Length of time
|
|
1149
1219
|
* @param interval Unit of time
|
|
1150
1220
|
*/
|
|
1151
1221
|
export declare function IndicatorMeanAbsoluteDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1222
|
+
/**
|
|
1223
|
+
* Rolling minimum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
|
|
1224
|
+
* @param length Length of time
|
|
1225
|
+
* @param interval Unit of time
|
|
1226
|
+
*/
|
|
1227
|
+
export declare function IndicatorMinimum(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1152
1228
|
/**
|
|
1153
1229
|
* IndicatorRateOfChange indicator.
|
|
1154
1230
|
* @param length Length of time
|
|
@@ -1168,15 +1244,15 @@ export declare function IndicatorSimpleMovingAverage(operand: Indicator, length?
|
|
|
1168
1244
|
*/
|
|
1169
1245
|
export declare function IndicatorStandardDeviation(operand: Indicator, length?: number, interval?: Interval): Indicator;
|
|
1170
1246
|
/**
|
|
1171
|
-
*
|
|
1247
|
+
* Value at an elapsed time in the past. TradingDay instead reads the confirmed closing value of the reference exchange session, including early closes. Missing session evidence returns no value; initialValue applies before enough history exists.
|
|
1172
1248
|
* @param length Length of time
|
|
1173
1249
|
* @param interval Unit of time
|
|
1174
1250
|
*/
|
|
1175
|
-
export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval): Indicator;
|
|
1251
|
+
export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval, initialValue?: number): Indicator;
|
|
1176
1252
|
/**
|
|
1177
|
-
* News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines.
|
|
1253
|
+
* News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. The value is the same for every asset: it takes no target asset.
|
|
1178
1254
|
* @param industry Canonical industry tag whose news to read, as IsIndustry lists it. Legacy aliases are separate news series and are rejected, never mapped.
|
|
1179
|
-
* @param measure Median: middle score from -1 to 1 (the average of the two middle scores for an even count), with no value when no qualifying headline. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying headline. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value
|
|
1255
|
+
* @param measure Median: middle score from -1 to 1 (the average of the two middle scores for an even count), with no value when no qualifying headline. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying headline. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value across missing snapshots or when the due snapshot is unpublished. Before coverage begins on 2019-09-23 the window holds the sessions available.
|
|
1180
1256
|
* @param lookbackDays Whole trading sessions of daily 09:15 New York news snapshots; 1 is the latest and about 20 is the usual window. The same value for every asset.
|
|
1181
1257
|
*/
|
|
1182
1258
|
export declare function IndustryNewsSentiment(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", measure?: Measure, lookbackDays?: number): Indicator;
|
|
@@ -1361,8 +1437,9 @@ export declare function MinutesSinceOptionOrder(underlying: string, optionType:
|
|
|
1361
1437
|
* MinutesSinceOrder indicator.
|
|
1362
1438
|
* @param assets Ticker(s) whose orders are counted. One string or an array.
|
|
1363
1439
|
* @param side Buy or Sell
|
|
1440
|
+
* @param clock Optional elapsed-time clock; omitted retains calendar minutes.
|
|
1364
1441
|
*/
|
|
1365
|
-
export declare function MinutesSinceOrder(assets: AssetArg | AssetArg[], side: Side, orderStatus?: OrderStatus): Indicator;
|
|
1442
|
+
export declare function MinutesSinceOrder(assets: AssetArg | AssetArg[], side: Side, orderStatus?: OrderStatus, clock?: Clock): Indicator;
|
|
1366
1443
|
/**
|
|
1367
1444
|
* MinutesUntilClose indicator.
|
|
1368
1445
|
*/
|
|
@@ -1418,9 +1495,9 @@ export declare function NewInstitutionalFiling(manager: string): Indicator;
|
|
|
1418
1495
|
*/
|
|
1419
1496
|
export declare function NewPoliticalDisclosure(memberId: string, instrument: Instrument2, disclosureAction: "Any" | "Purchase" | "Sale"): Indicator;
|
|
1420
1497
|
/**
|
|
1421
|
-
* News sentiment about the asset over its last lookbackDays daily news snapshots (default 1, the latest). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that names the company: whether it is really about the company, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the asset had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the company count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines.
|
|
1498
|
+
* News sentiment about the asset over its last lookbackDays daily news snapshots (default 1, the latest). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that names the company: whether it is really about the company, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the asset had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the company count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. Headlines are matched to the issuer, so every listed share class reads the same news and META reads Facebook-era headlines.
|
|
1422
1499
|
* @param asset Pass CANDIDATE in a dynamic rebalance pipeline.
|
|
1423
|
-
* @param measure Median: middle score from -1 to 1, with no value when no qualifying news. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying news. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value
|
|
1500
|
+
* @param measure Median: middle score from -1 to 1, with no value when no qualifying news. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying news. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value across missing snapshots or when the due snapshot is unpublished. Before coverage begins on 2019-09-23 the window holds the sessions available.
|
|
1424
1501
|
* @param lookbackDays Whole trading sessions of daily 09:15 New York news snapshots; 1 is the latest. A row is visible from the snapshot the lake assigned it, the same time in backtests and live trading.
|
|
1425
1502
|
*/
|
|
1426
1503
|
export declare function NewsSentiment(asset: AssetArg, measure?: Measure, lookbackDays?: number): Indicator;
|
|
@@ -1576,6 +1653,11 @@ export declare function PoliticalTrades(asset: AssetArg, filer: string, metric?:
|
|
|
1576
1653
|
* PortfolioValue indicator.
|
|
1577
1654
|
*/
|
|
1578
1655
|
export declare function PortfolioValue(): Indicator;
|
|
1656
|
+
/**
|
|
1657
|
+
* Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
|
|
1658
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1659
|
+
*/
|
|
1660
|
+
export declare function PositionEntryPrice(asset: AssetArg): Indicator;
|
|
1579
1661
|
/**
|
|
1580
1662
|
* PositionMaxDrawdown indicator.
|
|
1581
1663
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
@@ -1586,6 +1668,16 @@ export declare function PositionMaxDrawdown(asset: AssetArg): Indicator;
|
|
|
1586
1668
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
1587
1669
|
*/
|
|
1588
1670
|
export declare function PositionMaxDrawup(asset: AssetArg): Indicator;
|
|
1671
|
+
/**
|
|
1672
|
+
* Exchange trading minutes since the current holding's last new high. Closed-market minutes do not count. Added shares preserve the holding's observation path.
|
|
1673
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1674
|
+
*/
|
|
1675
|
+
export declare function PositionMinutesSinceHigh(asset: AssetArg): Indicator;
|
|
1676
|
+
/**
|
|
1677
|
+
* Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
|
|
1678
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1679
|
+
*/
|
|
1680
|
+
export declare function PositionPeakPrice(asset: AssetArg): Indicator;
|
|
1589
1681
|
/**
|
|
1590
1682
|
* PositionPercentChange indicator.
|
|
1591
1683
|
* @param assets Ticker name (ex. SPY, BTC)
|
|
@@ -1802,7 +1894,7 @@ export interface BacktestConfig {
|
|
|
1802
1894
|
baselineSymbol?: string;
|
|
1803
1895
|
/** Typed buy-and-hold benchmark for comparisonValue. Use {type:'Cryptocurrency',symbol:'BTC-USD',name:'BTC-USD'} for BTC or {type:'Stock',symbol:'SPY',name:'SPY'} for a stock/ETF. Symbol text never determines asset type. Omit baseline_symbol when using this field. */
|
|
1804
1896
|
baselineAsset?: Record<string, unknown>;
|
|
1805
|
-
/** Time interval: Day or Minute (default Day). Minute is a daytrade tape. 730 days of minute data (selected range plus warmup) is the HARD CAP; 90 days is only the DEFAULT when you name no dates. Name the dates you actually want — certifying a candidate on a full year or two is a normal second backtest, not an escalation. */
|
|
1897
|
+
/** Time interval: Day or Minute (default Day). Day uses fixed OHLC decision/fill snapshots and overrides the portfolio deployment frequency, openDelayMinutes, closeLeadMinutes and intervalSeconds. Use Minute when the authored intraday schedule matters. Minute is a daytrade tape. 730 days of minute data (selected range plus warmup) is the HARD CAP; 90 days is only the DEFAULT when you name no dates. Name the dates you actually want — certifying a candidate on a full year or two is a normal second backtest, not an escalation. */
|
|
1806
1898
|
interval?: "Day" | "Minute";
|
|
1807
1899
|
/** Starting portfolio value (default 10000) Range 1..inf. */
|
|
1808
1900
|
initialValue?: number;
|
|
@@ -1812,7 +1904,7 @@ export interface BacktestConfig {
|
|
|
1812
1904
|
forceNewRun?: boolean;
|
|
1813
1905
|
/** 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. OptionSlippageFraction is supported: 0 fills at quote mid, 1 at ask for buys/bid for sells; omitted uses the engine default 0.5. Fills require a current executable quote; this does not enable last-trade fallback pricing. */
|
|
1814
1906
|
feeConfig?: FeeConfig;
|
|
1815
|
-
/** Overrides the portfolio's dividend policy for this run only. Omit to use the portfolio's own setting (cash unless it was set to reinvest). "reinvest" buys more of the paying stock on each pay date
|
|
1907
|
+
/** Overrides the portfolio's dividend policy for this run only. Omit to use the portfolio's own setting (cash unless it was set to reinvest). "reinvest" buys more of the paying stock on each pay date while that stock is still held. A fully exited position receives its locked dividend entitlement as cash without reopening the position. Reinvest is what a buy-and-hold comparison against the SPY total-return baseline needs. */
|
|
1816
1908
|
dividendPolicy?: "cash" | "reinvest";
|
|
1817
1909
|
}
|
|
1818
1910
|
export interface WalkForwardConfig {
|
|
@@ -1963,6 +2055,8 @@ export declare const geneRankSignal: (strategyIndex: number, values: {
|
|
|
1963
2055
|
export declare const geneBuyingPowerPct: (strategyIndex: number, values: number[]) => Gene;
|
|
1964
2056
|
/** Sweep AllocationPct (Action scope) over a value set. */
|
|
1965
2057
|
export declare const geneAllocationPct: (strategyIndex: number, values: number[]) => Gene;
|
|
2058
|
+
/** Sweep AllocationDollars (Action scope) over a value set. */
|
|
2059
|
+
export declare const geneAllocationDollars: (strategyIndex: number, values: number[]) => Gene;
|
|
1966
2060
|
/** Sweep TotalBudgetPct (Action scope) over a value set. */
|
|
1967
2061
|
export declare const geneTotalBudgetPct: (strategyIndex: number, values: number[]) => Gene;
|
|
1968
2062
|
/** Sweep DeploymentPct (Action scope) over a value set. */
|
|
@@ -1997,10 +2091,15 @@ export declare const geneDteBracket: (strategyIndex: number, legIndex: number, v
|
|
|
1997
2091
|
/** Sweep MaxSpreadPct (OptionLeg scope) over a value set. */
|
|
1998
2092
|
export declare const geneMaxSpreadPct: (strategyIndex: number, legIndex: number, values: number[]) => Gene;
|
|
1999
2093
|
/** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
|
|
2000
|
-
export declare const geneSelectTopLimit: (strategyIndex: number,
|
|
2094
|
+
export declare const geneSelectTopLimit: (strategyIndex: number, values: number[], sleeveName?: string) => Gene;
|
|
2001
2095
|
/** Sweep UniversePipelineFilter (UniversePipeline scope) over a value set. */
|
|
2002
2096
|
export declare const geneUniversePipelineFilter: (strategyIndex: number, stageIndex: number, values: {
|
|
2003
2097
|
label: string;
|
|
2004
2098
|
condition: Condition;
|
|
2005
2099
|
}[]) => Gene;
|
|
2100
|
+
/** Sweep UniversePipelineFilter (UniversePipeline scope) by adding a Filter stage to a pipeline that has none to replace. The stage goes ahead of the first SelectTop/SelectPercentile, so it narrows the universe before ranking. */
|
|
2101
|
+
export declare const geneAppendUniversePipelineFilter: (strategyIndex: number, values: {
|
|
2102
|
+
label: string;
|
|
2103
|
+
condition: Condition;
|
|
2104
|
+
}[], sleeveName?: string) => Gene;
|
|
2006
2105
|
export {};
|
|
@@ -107,6 +107,7 @@ function compact(obj) {
|
|
|
107
107
|
}
|
|
108
108
|
function compare(lhs, rhs, comparison) {
|
|
109
109
|
const right = typeof rhs === "number" ? Value(rhs) : rhs;
|
|
110
|
+
// Wire nodes carry no brand at runtime; nodeKind exists only in the types.
|
|
110
111
|
return { type: "Base", lhs, comparison, rhs: right };
|
|
111
112
|
}
|
|
112
113
|
export const gt = (l, r) => compare(l, r, "greaterThan");
|
|
@@ -127,24 +128,11 @@ export const fewerThan = (count, ...conditions) => ({ type: "Multi", comparison:
|
|
|
127
128
|
export const exactly = (count, ...conditions) => ({ type: "Multi", comparison: "equal", value: count, conditions });
|
|
128
129
|
/** Multi with an explicit Comparator (same wire shape as YAML Multi). */
|
|
129
130
|
export const multi = (count, comparison, ...conditions) => ({ type: "Multi", comparison, value: count, conditions });
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
* transition, so with three or more steps each one must occur within the window
|
|
136
|
-
* of the step before it. Nesting is legal and means something different:
|
|
137
|
-
* `andThen(W, andThen(W, A, B), C)` is not `andThen(W, A, B, C)`.
|
|
138
|
-
*
|
|
139
|
-
* `interval` is REQUIRED and has no default. An omitted interval would fall
|
|
140
|
-
* back to Day and silently kill an intraday setup.
|
|
141
|
-
*
|
|
142
|
-
* Named `andThen` rather than `then`: a module namespace with a callable
|
|
143
|
-
* `then` export is assimilated as a thenable, so `await import("nexustrade")`
|
|
144
|
-
* would call it with resolve/reject and never settle. Emits wire type "Then",
|
|
145
|
-
* the same way atLeast/atMost/exactly emit "Multi".
|
|
146
|
-
*/
|
|
147
|
-
export const andThen = (length, interval, ...conditions) => ({ type: "Then", conditions, window: { length, interval } });
|
|
131
|
+
export function andThen(timing, first, ...rest) {
|
|
132
|
+
return (typeof timing === "number"
|
|
133
|
+
? { type: "Then", conditions: rest, window: { length: timing, interval: first } }
|
|
134
|
+
: { type: "Then", ...timing, conditions: [first, ...rest] });
|
|
135
|
+
}
|
|
148
136
|
/** Always-true gate for strategies whose cadence lives in the pipeline. */
|
|
149
137
|
export const always = () => compare(Value(1), Value(0), "greaterThan");
|
|
150
138
|
export const meanVarianceAllocation = (config = {}) => ({
|
|
@@ -203,8 +191,11 @@ export function universe(source, assets) {
|
|
|
203
191
|
/** The latest revision of the list an updateWatchlist producer in this portfolio maintains. */
|
|
204
192
|
export const watchlistUniverse = (watchlistKey) => ({ source: "WATCHLIST", watchlistKey });
|
|
205
193
|
// ---- equity + cash actions ----
|
|
206
|
-
export const buy = (target, amount, type = "percent of portfolio") => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount } });
|
|
207
|
-
export const sell = (target, amount, type = "percent of portfolio") => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount } });
|
|
194
|
+
export const buy = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
195
|
+
export const sell = (target, amount, type = "percent of portfolio", options = {}) => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount }, ...options });
|
|
196
|
+
/** Sell only actual holdings that pass a candidate-bound condition. */
|
|
197
|
+
export const sellHoldings = (condition, amount = 100, type = "percent of current positions", options = {}) => ({ type: "Sell", targetAsset: stockAsset("__PLACEHOLDER__"),
|
|
198
|
+
holdingCondition: condition, amount: { type, amount }, ...options });
|
|
208
199
|
export const alert = (message) => ({ type: "Alert", message });
|
|
209
200
|
export const launchAgent = (config) => compact({ type: "LaunchAgent", ...config });
|
|
210
201
|
export const updateWatchlist = (config) => ({
|
|
@@ -526,7 +517,7 @@ export function ConsecutiveIncrease(indicator, period, lookback) {
|
|
|
526
517
|
return d;
|
|
527
518
|
}
|
|
528
519
|
/**
|
|
529
|
-
*
|
|
520
|
+
* Report whether the ordinary condition has stayed true for the elapsed window. This is elapsed time, not a count of checks.
|
|
530
521
|
* @param condition Condition evaluated over the window.
|
|
531
522
|
* @param length Length of time
|
|
532
523
|
* @param interval Unit of time
|
|
@@ -550,14 +541,17 @@ export function Correlation(operands, length = 60, interval = "Day") {
|
|
|
550
541
|
return d;
|
|
551
542
|
}
|
|
552
543
|
/**
|
|
553
|
-
*
|
|
554
|
-
* @param condition
|
|
555
|
-
* @param length
|
|
556
|
-
* @param interval
|
|
544
|
+
* Count matching intervals inside a time lookback. The ordinary condition owns comparisons/events. countInterval contributes at most one match per interval; omitted means one unit of the lookback interval. TradingDay skips closed exchange dates.
|
|
545
|
+
* @param condition Ordinary condition whose matching intervals are counted.
|
|
546
|
+
* @param length Lookback length.
|
|
547
|
+
* @param interval Lookback time unit; TradingDay uses observed exchange sessions.
|
|
548
|
+
* @param countInterval Count at most once per this interval. Omit for one unit of the lookback interval.
|
|
557
549
|
*/
|
|
558
|
-
export function CountTrue(condition, length = 1, interval = "Day") {
|
|
550
|
+
export function CountTrue(condition, length = 1, interval = "Day", countInterval) {
|
|
559
551
|
const d = { type: "CountTrue" };
|
|
560
552
|
d.condition = condition;
|
|
553
|
+
if (countInterval !== undefined)
|
|
554
|
+
d["countInterval"] = countInterval;
|
|
561
555
|
d.window = { length: length, interval: interval };
|
|
562
556
|
return d;
|
|
563
557
|
}
|
|
@@ -598,6 +592,21 @@ export function CurrentTimeSeconds() {
|
|
|
598
592
|
const d = { type: "CurrentTimeSeconds" };
|
|
599
593
|
return d;
|
|
600
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Evaluation time in Unix seconds, including fractions. Use with ChartBar endTime for ordinary freshness comparisons; backtests use their simulated clock.
|
|
597
|
+
*/
|
|
598
|
+
export function CurrentTimestamp() {
|
|
599
|
+
const d = { type: "CurrentTimestamp" };
|
|
600
|
+
return d;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Inside a CountTrue historical condition, bind this operand at its value now while other operands use their historical observations. Elsewhere return the operand normally. Wrap a complete stateful operand, not an expression inside its recurrence.
|
|
604
|
+
*/
|
|
605
|
+
export function CurrentValue(operand) {
|
|
606
|
+
const d = { type: "CurrentValue" };
|
|
607
|
+
d.indicators = [operand];
|
|
608
|
+
return d;
|
|
609
|
+
}
|
|
601
610
|
/**
|
|
602
611
|
* CustomIndicator indicator.
|
|
603
612
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
|
|
@@ -856,17 +865,34 @@ export function Index(metric = "VIX") {
|
|
|
856
865
|
d["metric"] = metric;
|
|
857
866
|
return d;
|
|
858
867
|
}
|
|
868
|
+
/**
|
|
869
|
+
* Retain the operand from matching observations: First, Latest, Maximum, or Minimum. Ordinary conditions decide when to capture. An optional window expires observations; TradingDay skips closed exchange dates. Use this to freeze a qualified setup before entry or ratchet a numeric level, not IndicatorAtEntry when no fill exists yet.
|
|
870
|
+
* @param condition Condition evaluated over the window.
|
|
871
|
+
*/
|
|
872
|
+
export function IndicatorAtCondition(operand, condition, selection = "First", clock = "Calendar", initialValue, length, interval) {
|
|
873
|
+
const d = { type: "IndicatorAtCondition" };
|
|
874
|
+
d.condition = condition;
|
|
875
|
+
d["selection"] = selection;
|
|
876
|
+
d["clock"] = clock;
|
|
877
|
+
if (initialValue !== undefined)
|
|
878
|
+
d["initialValue"] = initialValue;
|
|
879
|
+
d.indicators = [operand];
|
|
880
|
+
if (length !== undefined || interval !== undefined)
|
|
881
|
+
d.window = { length: length, interval: interval };
|
|
882
|
+
return d;
|
|
883
|
+
}
|
|
859
884
|
/**
|
|
860
885
|
* IndicatorAtEntry indicator.
|
|
861
886
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
862
887
|
* @param side The side of the fill the value is anchored to
|
|
863
888
|
* @param orderStatus Matches order events with this status
|
|
864
889
|
*/
|
|
865
|
-
export function IndicatorAtEntry(operand, asset, side, orderStatus = "Filled") {
|
|
890
|
+
export function IndicatorAtEntry(operand, asset, side, orderStatus = "Filled", anchor = "LatestFill") {
|
|
866
891
|
const d = { type: "IndicatorAtEntry" };
|
|
867
892
|
setAsset(d, "targetAsset", asset);
|
|
868
893
|
d["side"] = side;
|
|
869
894
|
d["orderStatus"] = orderStatus;
|
|
895
|
+
d["anchor"] = anchor;
|
|
870
896
|
d.indicators = [operand];
|
|
871
897
|
return d;
|
|
872
898
|
}
|
|
@@ -891,6 +917,17 @@ export function IndicatorExponentialMovingAverage(operand, length = 30, interval
|
|
|
891
917
|
d.window = { length: length, interval: interval };
|
|
892
918
|
return d;
|
|
893
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* Rolling maximum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
|
|
922
|
+
* @param length Length of time
|
|
923
|
+
* @param interval Unit of time
|
|
924
|
+
*/
|
|
925
|
+
export function IndicatorMaximum(operand, length = 30, interval = "Day") {
|
|
926
|
+
const d = { type: "IndicatorMaximum" };
|
|
927
|
+
d.indicators = [operand];
|
|
928
|
+
d.window = { length: length, interval: interval };
|
|
929
|
+
return d;
|
|
930
|
+
}
|
|
894
931
|
/**
|
|
895
932
|
* IndicatorMeanAbsoluteDeviation indicator.
|
|
896
933
|
* @param length Length of time
|
|
@@ -902,6 +939,17 @@ export function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval =
|
|
|
902
939
|
d.window = { length: length, interval: interval };
|
|
903
940
|
return d;
|
|
904
941
|
}
|
|
942
|
+
/**
|
|
943
|
+
* Rolling minimum of one numeric operand over a time window. ChartBar observations keep their completed candle end time; repeated reads do not extend their age. Available history is used, so express full-history coverage separately.
|
|
944
|
+
* @param length Length of time
|
|
945
|
+
* @param interval Unit of time
|
|
946
|
+
*/
|
|
947
|
+
export function IndicatorMinimum(operand, length = 30, interval = "Day") {
|
|
948
|
+
const d = { type: "IndicatorMinimum" };
|
|
949
|
+
d.indicators = [operand];
|
|
950
|
+
d.window = { length: length, interval: interval };
|
|
951
|
+
return d;
|
|
952
|
+
}
|
|
905
953
|
/**
|
|
906
954
|
* IndicatorRateOfChange indicator.
|
|
907
955
|
* @param length Length of time
|
|
@@ -936,20 +984,22 @@ export function IndicatorStandardDeviation(operand, length = 30, interval = "Day
|
|
|
936
984
|
return d;
|
|
937
985
|
}
|
|
938
986
|
/**
|
|
939
|
-
*
|
|
987
|
+
* Value at an elapsed time in the past. TradingDay instead reads the confirmed closing value of the reference exchange session, including early closes. Missing session evidence returns no value; initialValue applies before enough history exists.
|
|
940
988
|
* @param length Length of time
|
|
941
989
|
* @param interval Unit of time
|
|
942
990
|
*/
|
|
943
|
-
export function IndicatorWindowAgo(operand, length, interval) {
|
|
991
|
+
export function IndicatorWindowAgo(operand, length, interval, initialValue) {
|
|
944
992
|
const d = { type: "IndicatorWindowAgo" };
|
|
993
|
+
if (initialValue !== undefined)
|
|
994
|
+
d["initialValue"] = initialValue;
|
|
945
995
|
d.indicators = [operand];
|
|
946
996
|
d.window = { length: length, interval: interval };
|
|
947
997
|
return d;
|
|
948
998
|
}
|
|
949
999
|
/**
|
|
950
|
-
* News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines.
|
|
1000
|
+
* News sentiment about an industry over its last lookbackDays daily news snapshots (default 1, the latest). industry is one of the canonical industry tags (the same list IsIndustry uses). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that mentions the industry: whether it is really about the industry, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the industry had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the industry count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. The value is the same for every asset: it takes no target asset.
|
|
951
1001
|
* @param industry Canonical industry tag whose news to read, as IsIndustry lists it. Legacy aliases are separate news series and are rejected, never mapped.
|
|
952
|
-
* @param measure Median: middle score from -1 to 1 (the average of the two middle scores for an even count), with no value when no qualifying headline. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying headline. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value
|
|
1002
|
+
* @param measure Median: middle score from -1 to 1 (the average of the two middle scores for an even count), with no value when no qualifying headline. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying headline. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value across missing snapshots or when the due snapshot is unpublished. Before coverage begins on 2019-09-23 the window holds the sessions available.
|
|
953
1003
|
* @param lookbackDays Whole trading sessions of daily 09:15 New York news snapshots; 1 is the latest and about 20 is the usual window. The same value for every asset.
|
|
954
1004
|
*/
|
|
955
1005
|
export function IndustryNewsSentiment(industry, measure = "Mean", lookbackDays = 1) {
|
|
@@ -1291,12 +1341,15 @@ export function MinutesSinceOptionOrder(underlying, optionType, direction, sprea
|
|
|
1291
1341
|
* MinutesSinceOrder indicator.
|
|
1292
1342
|
* @param assets Ticker(s) whose orders are counted. One string or an array.
|
|
1293
1343
|
* @param side Buy or Sell
|
|
1344
|
+
* @param clock Optional elapsed-time clock; omitted retains calendar minutes.
|
|
1294
1345
|
*/
|
|
1295
|
-
export function MinutesSinceOrder(assets, side, orderStatus = "Filled") {
|
|
1346
|
+
export function MinutesSinceOrder(assets, side, orderStatus = "Filled", clock) {
|
|
1296
1347
|
const d = { type: "MinutesSinceOrder" };
|
|
1297
1348
|
setAssets(d, "targetAssets", assets);
|
|
1298
1349
|
d["side"] = side;
|
|
1299
1350
|
d["orderStatus"] = orderStatus;
|
|
1351
|
+
if (clock !== undefined)
|
|
1352
|
+
d["clock"] = clock;
|
|
1300
1353
|
return d;
|
|
1301
1354
|
}
|
|
1302
1355
|
/**
|
|
@@ -1402,9 +1455,9 @@ export function NewPoliticalDisclosure(memberId, instrument, disclosureAction) {
|
|
|
1402
1455
|
return d;
|
|
1403
1456
|
}
|
|
1404
1457
|
/**
|
|
1405
|
-
* News sentiment about the asset over its last lookbackDays daily news snapshots (default 1, the latest). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that names the company: whether it is really about the company, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the asset had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the company count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines.
|
|
1458
|
+
* News sentiment about the asset over its last lookbackDays daily news snapshots (default 1, the latest). Headlines come from the GDELT global news feed, and a fine-tuned model scores every headline that names the company: whether it is really about the company, and whether it is positive, neutral or negative news for it (a headline it calls neutral scores 0; others score from -1.0 to 1.0). Each trading day has one snapshot at 09:15 New York, and a headline counts toward the first session whose 09:15 cutoff is at or after the time GDELT published it. Backtests and live trading read the same rows. lookbackDays counts trading sessions whether or not the asset had news in them; a single session is noisy, and about 20 sessions is the usual window for a sentiment rule. Only headlines the model judges to be about the company count, and copies of one story within 7 days count once per session. measure (default Mean): Mean is the average sentiment from -1.0 to 1.0, Median is the middle score (the average of the two middle scores for an even count), NetCount is positive minus negative headlines, ArticleCount is the number of qualifying headlines. Coverage begins on 2019-09-23: a window reaching earlier is measured over the sessions since then, and the backtest warns that it held less history than configured. Every measure has no value across sessions with no published snapshot, or when the latest snapshot due has not been published. Mean and Median also have no value when the window holds no qualifying headline; the counts are then 0. Headlines are matched to the issuer, so every listed share class reads the same news and META reads Facebook-era headlines.
|
|
1406
1459
|
* @param asset Pass CANDIDATE in a dynamic rebalance pipeline.
|
|
1407
|
-
* @param measure Median: middle score from -1 to 1, with no value when no qualifying news. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying news. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value
|
|
1460
|
+
* @param measure Median: middle score from -1 to 1, with no value when no qualifying news. Mean: average sentiment from -1 to 1, with no value when the window has no qualifying news. NetCount: positive minus negative headlines. ArticleCount: qualifying headlines. Every measure has no value across missing snapshots or when the due snapshot is unpublished. Before coverage begins on 2019-09-23 the window holds the sessions available.
|
|
1408
1461
|
* @param lookbackDays Whole trading sessions of daily 09:15 New York news snapshots; 1 is the latest. A row is visible from the snapshot the lake assigned it, the same time in backtests and live trading.
|
|
1409
1462
|
*/
|
|
1410
1463
|
export function NewsSentiment(asset, measure = "Mean", lookbackDays = 1) {
|
|
@@ -1700,6 +1753,15 @@ export function PortfolioValue() {
|
|
|
1700
1753
|
const d = { type: "PortfolioValue" };
|
|
1701
1754
|
return d;
|
|
1702
1755
|
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Original filled entry price for the current holding. Added shares preserve this original anchor; closing the holding resets it.
|
|
1758
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1759
|
+
*/
|
|
1760
|
+
export function PositionEntryPrice(asset) {
|
|
1761
|
+
const d = { type: "PositionEntryPrice" };
|
|
1762
|
+
setAsset(d, "targetAsset", asset);
|
|
1763
|
+
return d;
|
|
1764
|
+
}
|
|
1703
1765
|
/**
|
|
1704
1766
|
* PositionMaxDrawdown indicator.
|
|
1705
1767
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
@@ -1718,6 +1780,24 @@ export function PositionMaxDrawup(asset) {
|
|
|
1718
1780
|
setAsset(d, "targetAsset", asset);
|
|
1719
1781
|
return d;
|
|
1720
1782
|
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Exchange trading minutes since the current holding's last new high. Closed-market minutes do not count. Added shares preserve the holding's observation path.
|
|
1785
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1786
|
+
*/
|
|
1787
|
+
export function PositionMinutesSinceHigh(asset) {
|
|
1788
|
+
const d = { type: "PositionMinutesSinceHigh" };
|
|
1789
|
+
setAsset(d, "targetAsset", asset);
|
|
1790
|
+
return d;
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Highest observed price since the current holding's original entry. Added shares preserve the peak path; closing resets it.
|
|
1794
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1795
|
+
*/
|
|
1796
|
+
export function PositionPeakPrice(asset) {
|
|
1797
|
+
const d = { type: "PositionPeakPrice" };
|
|
1798
|
+
setAsset(d, "targetAsset", asset);
|
|
1799
|
+
return d;
|
|
1800
|
+
}
|
|
1721
1801
|
/**
|
|
1722
1802
|
* PositionPercentChange indicator.
|
|
1723
1803
|
* @param assets Ticker name (ex. SPY, BTC)
|
|
@@ -2158,6 +2238,13 @@ export const geneAllocationPct = (strategyIndex, values) => ({
|
|
|
2158
2238
|
target: { scope: "Action", field: "AllocationPct", strategyIndex },
|
|
2159
2239
|
values: values,
|
|
2160
2240
|
});
|
|
2241
|
+
/** Sweep AllocationDollars (Action scope) over a value set. */
|
|
2242
|
+
export const geneAllocationDollars = (strategyIndex, values) => ({
|
|
2243
|
+
field: "AllocationDollars",
|
|
2244
|
+
scope: "Action",
|
|
2245
|
+
target: { scope: "Action", field: "AllocationDollars", strategyIndex },
|
|
2246
|
+
values: values,
|
|
2247
|
+
});
|
|
2161
2248
|
/** Sweep TotalBudgetPct (Action scope) over a value set. */
|
|
2162
2249
|
export const geneTotalBudgetPct = (strategyIndex, values) => ({
|
|
2163
2250
|
field: "TotalBudgetPct",
|
|
@@ -2243,10 +2330,10 @@ export const geneMaxSpreadPct = (strategyIndex, legIndex, values) => ({
|
|
|
2243
2330
|
values: values,
|
|
2244
2331
|
});
|
|
2245
2332
|
/** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
|
|
2246
|
-
export const geneSelectTopLimit = (strategyIndex,
|
|
2333
|
+
export const geneSelectTopLimit = (strategyIndex, values, sleeveName) => ({
|
|
2247
2334
|
field: "SelectTopLimit",
|
|
2248
2335
|
scope: "UniversePipeline",
|
|
2249
|
-
target: { scope: "UniversePipeline", field: "SelectTopLimit", strategyIndex,
|
|
2336
|
+
target: { scope: "UniversePipeline", field: "SelectTopLimit", strategyIndex, ...(sleeveName === undefined ? {} : { sleeveName }) },
|
|
2250
2337
|
values: values,
|
|
2251
2338
|
});
|
|
2252
2339
|
/** Sweep UniversePipelineFilter (UniversePipeline scope) over a value set. */
|
|
@@ -2256,3 +2343,10 @@ export const geneUniversePipelineFilter = (strategyIndex, stageIndex, values) =>
|
|
|
2256
2343
|
target: { scope: "UniversePipeline", field: "UniversePipelineFilter", strategyIndex, stageIndex },
|
|
2257
2344
|
values: values,
|
|
2258
2345
|
});
|
|
2346
|
+
/** Sweep UniversePipelineFilter (UniversePipeline scope) by adding a Filter stage to a pipeline that has none to replace. The stage goes ahead of the first SelectTop/SelectPercentile, so it narrows the universe before ranking. */
|
|
2347
|
+
export const geneAppendUniversePipelineFilter = (strategyIndex, values, sleeveName) => ({
|
|
2348
|
+
field: "UniversePipelineFilter",
|
|
2349
|
+
scope: "UniversePipeline",
|
|
2350
|
+
target: { scope: "UniversePipeline", field: "UniversePipelineFilter", strategyIndex, ...(sleeveName === undefined ? {} : { sleeveName }), append: true },
|
|
2351
|
+
values: values,
|
|
2352
|
+
});
|