nexustrade 1.59.1 → 1.60.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -236,6 +236,11 @@ price target. Live option strategies must choose an explicit Limit policy.
|
|
|
236
236
|
|
|
237
237
|
### Option selection and execution limits
|
|
238
238
|
|
|
239
|
+
`strategy(..., { pendingOrderPolicy: "CancelConflictingBuys" })` enables backtest-only
|
|
240
|
+
exit priority over conflicting pending buys. Omission preserves waiting. Paper
|
|
241
|
+
and live deployment reject this opt-in because broker cancellation acknowledgements
|
|
242
|
+
are not implemented. The setting also accepts explicit `"Wait"`.
|
|
243
|
+
|
|
239
244
|
Builders describe drafts. Typechecking does not prove that the engine can
|
|
240
245
|
execute every requested rule; the API validates complete portfolios and their
|
|
241
246
|
conditions.
|
|
@@ -336,6 +341,15 @@ const finished = await client.waitForBacktest(operation.id as string);
|
|
|
336
341
|
A timeout throws `operation_timeout` and does **not** cancel the job — call the
|
|
337
342
|
waiter again with the same id rather than resubmitting.
|
|
338
343
|
|
|
344
|
+
Transient network and HTTP 408/429/5xx polling failures retry the same operation
|
|
345
|
+
at most twice consecutively, within the wait deadline. Persistent failures keep
|
|
346
|
+
their original error code and operation ID; no new job is submitted.
|
|
347
|
+
|
|
348
|
+
Durable lake exports use a 900-second server budget by default (registered API
|
|
349
|
+
keys may request up to 1800 seconds). `waitForLakeQuery` defaults to 1200 seconds
|
|
350
|
+
to include queue time. Compute token budgets remain 90 seconds by default and
|
|
351
|
+
180 seconds maximum. A client wait timeout does not extend the server budget.
|
|
352
|
+
|
|
339
353
|
**Batches.** `createBacktests` submits many in one request and returns one
|
|
340
354
|
operation each; `waitForBacktests(operations)` waits on all of them. Prefer it
|
|
341
355
|
over a loop: one request, one idempotency key, one rate-limit slot.
|
package/dist/cjs/client.js
CHANGED
|
@@ -747,8 +747,27 @@ async function waitForOperation(fetch, operationId, options = {}) {
|
|
|
747
747
|
}
|
|
748
748
|
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
749
749
|
let interval = Math.min(pollIntervalSeconds, maxPollIntervalSeconds);
|
|
750
|
+
let consecutiveErrors = 0;
|
|
750
751
|
for (;;) {
|
|
751
|
-
|
|
752
|
+
let operation;
|
|
753
|
+
try {
|
|
754
|
+
operation = await fetch(operationId);
|
|
755
|
+
}
|
|
756
|
+
catch (error) {
|
|
757
|
+
if (!(error instanceof NexusTradeApiError))
|
|
758
|
+
throw error;
|
|
759
|
+
consecutiveErrors += 1;
|
|
760
|
+
const transient = error.code === "transport_error" ||
|
|
761
|
+
error.status === 408 || error.status === 429 || error.status >= 500;
|
|
762
|
+
const remainingMs = deadline - Date.now();
|
|
763
|
+
if (!transient || consecutiveErrors >= 3 || remainingMs <= 0) {
|
|
764
|
+
throw new NexusTradeApiError(error.status, error.code, error.message, operationId);
|
|
765
|
+
}
|
|
766
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(Math.max(1, interval) * 1000, remainingMs)));
|
|
767
|
+
interval = Math.min(Math.max(1, interval) * exports.POLL_BACKOFF_FACTOR, Math.max(1, maxPollIntervalSeconds));
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
consecutiveErrors = 0;
|
|
752
771
|
const status = String(operation.status ?? "");
|
|
753
772
|
if (TERMINAL_STATUSES.includes(status)) {
|
|
754
773
|
if (raiseOnFailure && status !== "completed") {
|
|
@@ -1483,7 +1502,7 @@ class NexusTradeClient {
|
|
|
1483
1502
|
}
|
|
1484
1503
|
/** Resolve once a lake query is terminal. See `waitForOperation`. */
|
|
1485
1504
|
async waitForLakeQuery(queryId, options = {}) {
|
|
1486
|
-
return waitForOperation((id) => this.getLakeQuery(id), queryId, options);
|
|
1505
|
+
return waitForOperation((id) => this.getLakeQuery(id), queryId, { ...options, timeoutSeconds: options.timeoutSeconds ?? 1200 });
|
|
1487
1506
|
}
|
|
1488
1507
|
/** Resolve once a backtest is terminal. See `waitForOperation`. */
|
|
1489
1508
|
async waitForBacktest(backtestId, options = {}) {
|
|
@@ -59,6 +59,7 @@ exports.IndicatorRateOfChange = IndicatorRateOfChange;
|
|
|
59
59
|
exports.IndicatorSimpleMovingAverage = IndicatorSimpleMovingAverage;
|
|
60
60
|
exports.IndicatorStandardDeviation = IndicatorStandardDeviation;
|
|
61
61
|
exports.IndicatorWindowAgo = IndicatorWindowAgo;
|
|
62
|
+
exports.IndustryNewsSentiment = IndustryNewsSentiment;
|
|
62
63
|
exports.InitialValue = InitialValue;
|
|
63
64
|
exports.InsiderTrades = InsiderTrades;
|
|
64
65
|
exports.InstitutionalHoldings = InstitutionalHoldings;
|
|
@@ -1167,6 +1168,19 @@ function IndicatorWindowAgo(operand, length, interval) {
|
|
|
1167
1168
|
d.window = { length: length, interval: interval };
|
|
1168
1169
|
return d;
|
|
1169
1170
|
}
|
|
1171
|
+
/**
|
|
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. Every measure has no value when the window cannot be read in full: before coverage begins on 2019-09-23, 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
|
+
* @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 before coverage begins on 2019-09-23, across missing snapshots, or when the due snapshot is unpublished.
|
|
1175
|
+
* @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
|
+
*/
|
|
1177
|
+
function IndustryNewsSentiment(industry, measure = "Mean", lookbackDays = 1) {
|
|
1178
|
+
const d = { type: "IndustryNewsSentiment" };
|
|
1179
|
+
d["industry"] = industry;
|
|
1180
|
+
d["measure"] = measure;
|
|
1181
|
+
d["lookbackDays"] = lookbackDays;
|
|
1182
|
+
return d;
|
|
1183
|
+
}
|
|
1170
1184
|
/**
|
|
1171
1185
|
* InitialValue indicator.
|
|
1172
1186
|
*/
|
|
@@ -1610,9 +1624,9 @@ function NewPoliticalDisclosure(memberId, instrument, disclosureAction) {
|
|
|
1610
1624
|
return d;
|
|
1611
1625
|
}
|
|
1612
1626
|
/**
|
|
1613
|
-
*
|
|
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. Every measure has no value when the window cannot be read in full: before coverage begins on 2019-09-23, 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.
|
|
1614
1628
|
* @param asset Pass CANDIDATE in a dynamic rebalance pipeline.
|
|
1615
|
-
* @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
|
|
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 before coverage begins on 2019-09-23, across missing snapshots, or when the due snapshot is unpublished.
|
|
1616
1630
|
* @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.
|
|
1617
1631
|
*/
|
|
1618
1632
|
function NewsSentiment(asset, measure = "Mean", lookbackDays = 1) {
|
|
@@ -2226,6 +2240,7 @@ const backtest = (portfolio, config) => ({
|
|
|
2226
2240
|
"interval": config.interval,
|
|
2227
2241
|
"initial_value": config.initialValue,
|
|
2228
2242
|
"generate_events": config.generateEvents,
|
|
2243
|
+
"force_new_run": config.forceNewRun,
|
|
2229
2244
|
"fee_config": config.feeConfig,
|
|
2230
2245
|
"dividend_policy": config.dividendPolicy,
|
|
2231
2246
|
}),
|
package/dist/esm/client.js
CHANGED
|
@@ -737,8 +737,27 @@ export async function waitForOperation(fetch, operationId, options = {}) {
|
|
|
737
737
|
}
|
|
738
738
|
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
739
739
|
let interval = Math.min(pollIntervalSeconds, maxPollIntervalSeconds);
|
|
740
|
+
let consecutiveErrors = 0;
|
|
740
741
|
for (;;) {
|
|
741
|
-
|
|
742
|
+
let operation;
|
|
743
|
+
try {
|
|
744
|
+
operation = await fetch(operationId);
|
|
745
|
+
}
|
|
746
|
+
catch (error) {
|
|
747
|
+
if (!(error instanceof NexusTradeApiError))
|
|
748
|
+
throw error;
|
|
749
|
+
consecutiveErrors += 1;
|
|
750
|
+
const transient = error.code === "transport_error" ||
|
|
751
|
+
error.status === 408 || error.status === 429 || error.status >= 500;
|
|
752
|
+
const remainingMs = deadline - Date.now();
|
|
753
|
+
if (!transient || consecutiveErrors >= 3 || remainingMs <= 0) {
|
|
754
|
+
throw new NexusTradeApiError(error.status, error.code, error.message, operationId);
|
|
755
|
+
}
|
|
756
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(Math.max(1, interval) * 1000, remainingMs)));
|
|
757
|
+
interval = Math.min(Math.max(1, interval) * POLL_BACKOFF_FACTOR, Math.max(1, maxPollIntervalSeconds));
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
consecutiveErrors = 0;
|
|
742
761
|
const status = String(operation.status ?? "");
|
|
743
762
|
if (TERMINAL_STATUSES.includes(status)) {
|
|
744
763
|
if (raiseOnFailure && status !== "completed") {
|
|
@@ -1473,7 +1492,7 @@ export class NexusTradeClient {
|
|
|
1473
1492
|
}
|
|
1474
1493
|
/** Resolve once a lake query is terminal. See `waitForOperation`. */
|
|
1475
1494
|
async waitForLakeQuery(queryId, options = {}) {
|
|
1476
|
-
return waitForOperation((id) => this.getLakeQuery(id), queryId, options);
|
|
1495
|
+
return waitForOperation((id) => this.getLakeQuery(id), queryId, { ...options, timeoutSeconds: options.timeoutSeconds ?? 1200 });
|
|
1477
1496
|
}
|
|
1478
1497
|
/** Resolve once a backtest is terminal. See `waitForOperation`. */
|
|
1479
1498
|
async waitForBacktest(backtestId, options = {}) {
|
|
@@ -523,6 +523,8 @@ export interface Strategy {
|
|
|
523
523
|
active?: boolean;
|
|
524
524
|
/** Omitted means Market. Limit always requires an explicit price policy. */
|
|
525
525
|
orderExecution?: StrategyOrderExecutionPolicy;
|
|
526
|
+
/** Backtest-only exit priority. CancelConflictingBuys cannot deploy to paper/live trading. */
|
|
527
|
+
pendingOrderPolicy?: "Wait" | "CancelConflictingBuys";
|
|
526
528
|
}
|
|
527
529
|
export interface AuthoredIndustryFilter {
|
|
528
530
|
mode: "ALL" | "INCLUDE_ONLY";
|
|
@@ -593,6 +595,7 @@ export type Period = "Year" | "Quarter" | "Month";
|
|
|
593
595
|
export type PositionEffect = "open" | "close";
|
|
594
596
|
export type OrderStatus = "Pending" | "Accepted" | "Pending User Approval" | "Canceled" | "Filled" | "Partially Filled";
|
|
595
597
|
export type Side = "Buy" | "Sell";
|
|
598
|
+
export type Measure = "Mean" | "Median" | "NetCount" | "ArticleCount";
|
|
596
599
|
export type Role = "Any" | "Officer" | "Director" | "TenPercentOwner" | "OfficerOrDirector";
|
|
597
600
|
export type Instrument = "Equity" | "Call" | "Put";
|
|
598
601
|
export type Instrument2 = "Equity" | "Option";
|
|
@@ -820,6 +823,7 @@ export declare const goodForMinutes: (minutes: number) => StrategyLimitWorkingTi
|
|
|
820
823
|
export declare const strategy: (name: string, condition: StrategyCondition, action: Action, options?: {
|
|
821
824
|
active?: boolean;
|
|
822
825
|
orderExecution?: StrategyOrderExecutionPolicy;
|
|
826
|
+
pendingOrderPolicy?: Strategy["pendingOrderPolicy"];
|
|
823
827
|
}) => Strategy;
|
|
824
828
|
/**
|
|
825
829
|
* Session / clock flatten — condition carries the gate (MinutesAfterOpen, Day, …).
|
|
@@ -1169,6 +1173,13 @@ export declare function IndicatorStandardDeviation(operand: Indicator, length?:
|
|
|
1169
1173
|
* @param interval Unit of time
|
|
1170
1174
|
*/
|
|
1171
1175
|
export declare function IndicatorWindowAgo(operand: Indicator, length: number, interval: Interval): Indicator;
|
|
1176
|
+
/**
|
|
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. Every measure has no value when the window cannot be read in full: before coverage begins on 2019-09-23, 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
|
+
* @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 before coverage begins on 2019-09-23, across missing snapshots, or when the due snapshot is unpublished.
|
|
1180
|
+
* @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
|
+
*/
|
|
1182
|
+
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;
|
|
1172
1183
|
/**
|
|
1173
1184
|
* InitialValue indicator.
|
|
1174
1185
|
*/
|
|
@@ -1407,12 +1418,12 @@ export declare function NewInstitutionalFiling(manager: string): Indicator;
|
|
|
1407
1418
|
*/
|
|
1408
1419
|
export declare function NewPoliticalDisclosure(memberId: string, instrument: Instrument2, disclosureAction: "Any" | "Purchase" | "Sale"): Indicator;
|
|
1409
1420
|
/**
|
|
1410
|
-
*
|
|
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. Every measure has no value when the window cannot be read in full: before coverage begins on 2019-09-23, 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.
|
|
1411
1422
|
* @param asset Pass CANDIDATE in a dynamic rebalance pipeline.
|
|
1412
|
-
* @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
|
|
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 before coverage begins on 2019-09-23, across missing snapshots, or when the due snapshot is unpublished.
|
|
1413
1424
|
* @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.
|
|
1414
1425
|
*/
|
|
1415
|
-
export declare function NewsSentiment(asset: AssetArg, measure?:
|
|
1426
|
+
export declare function NewsSentiment(asset: AssetArg, measure?: Measure, lookbackDays?: number): Indicator;
|
|
1416
1427
|
/**
|
|
1417
1428
|
* NewTradingWeek indicator.
|
|
1418
1429
|
*/
|
|
@@ -1797,6 +1808,8 @@ export interface BacktestConfig {
|
|
|
1797
1808
|
initialValue?: number;
|
|
1798
1809
|
/** Generate detailed event data (signals, orders, audits) during backtest. Costs 5x research tokens. Events are Mongo hot-store traces retained for 3 days. Use query_backtest_events to explore them while retained. */
|
|
1799
1810
|
generateEvents?: boolean;
|
|
1811
|
+
/** Create and execute a fresh backtest instead of reusing a prior identical result. Defaults to false. Requires portfolio_id. Use for an explicitly requested rerun or warm-cache timing; this reruns the simulation and incurs the normal backtest cost. */
|
|
1812
|
+
forceNewRun?: boolean;
|
|
1800
1813
|
/** 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. */
|
|
1801
1814
|
feeConfig?: FeeConfig;
|
|
1802
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, which is what a buy-and-hold comparison against the SPY total-return baseline needs. */
|
|
@@ -946,6 +946,19 @@ export function IndicatorWindowAgo(operand, length, interval) {
|
|
|
946
946
|
d.window = { length: length, interval: interval };
|
|
947
947
|
return d;
|
|
948
948
|
}
|
|
949
|
+
/**
|
|
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. Every measure has no value when the window cannot be read in full: before coverage begins on 2019-09-23, 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
|
+
* @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 before coverage begins on 2019-09-23, across missing snapshots, or when the due snapshot is unpublished.
|
|
953
|
+
* @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
|
+
*/
|
|
955
|
+
export function IndustryNewsSentiment(industry, measure = "Mean", lookbackDays = 1) {
|
|
956
|
+
const d = { type: "IndustryNewsSentiment" };
|
|
957
|
+
d["industry"] = industry;
|
|
958
|
+
d["measure"] = measure;
|
|
959
|
+
d["lookbackDays"] = lookbackDays;
|
|
960
|
+
return d;
|
|
961
|
+
}
|
|
949
962
|
/**
|
|
950
963
|
* InitialValue indicator.
|
|
951
964
|
*/
|
|
@@ -1389,9 +1402,9 @@ export function NewPoliticalDisclosure(memberId, instrument, disclosureAction) {
|
|
|
1389
1402
|
return d;
|
|
1390
1403
|
}
|
|
1391
1404
|
/**
|
|
1392
|
-
*
|
|
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. Every measure has no value when the window cannot be read in full: before coverage begins on 2019-09-23, 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.
|
|
1393
1406
|
* @param asset Pass CANDIDATE in a dynamic rebalance pipeline.
|
|
1394
|
-
* @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
|
|
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 before coverage begins on 2019-09-23, across missing snapshots, or when the due snapshot is unpublished.
|
|
1395
1408
|
* @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.
|
|
1396
1409
|
*/
|
|
1397
1410
|
export function NewsSentiment(asset, measure = "Mean", lookbackDays = 1) {
|
|
@@ -2005,6 +2018,7 @@ export const backtest = (portfolio, config) => ({
|
|
|
2005
2018
|
"interval": config.interval,
|
|
2006
2019
|
"initial_value": config.initialValue,
|
|
2007
2020
|
"generate_events": config.generateEvents,
|
|
2021
|
+
"force_new_run": config.forceNewRun,
|
|
2008
2022
|
"fee_config": config.feeConfig,
|
|
2009
2023
|
"dividend_policy": config.dividendPolicy,
|
|
2010
2024
|
}),
|