tradeblocks-mcp 3.8.0 → 3.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tradeblocks-mcp",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "MCP server for options trade analysis",
5
5
  "author": "David Romeo <davidmromeo@gmail.com>",
6
6
  "type": "module",
@@ -6,7 +6,7 @@ import {
6
6
  isTatFormat,
7
7
  quoteParquetCanonicalProjection,
8
8
  readParquetGlobSql
9
- } from "./chunk-HC2NGC34.js";
9
+ } from "./chunk-LNAAA74R.js";
10
10
  import {
11
11
  PlBasis
12
12
  } from "./chunk-N2RXXORM.js";
@@ -3543,7 +3543,7 @@ async function openReadWriteConnection(dbPath, threads, memoryLimit) {
3543
3543
  await createMarketParquetViews(connection, dataRoot);
3544
3544
  await ensureMarketDataTables(connection);
3545
3545
  try {
3546
- const blocksDir = (await import("./sync-P4DLN5YE.js")).getBlocksDir(dataRoot);
3546
+ const blocksDir = (await import("./sync-FNVNZR6P.js")).getBlocksDir(dataRoot);
3547
3547
  await migrateMetadataToJson(connection, dataRoot, blocksDir);
3548
3548
  } catch (err) {
3549
3549
  console.warn(
@@ -5196,4 +5196,4 @@ export {
5196
5196
  loadReportingLog,
5197
5197
  importCsv
5198
5198
  };
5199
- //# sourceMappingURL=chunk-LUMKSOEC.js.map
5199
+ //# sourceMappingURL=chunk-BFXJCMA2.js.map
@@ -22436,6 +22436,7 @@ function worstCaseInjectionCount(simulationLength, worstCasePercentage) {
22436
22436
  const requested = Math.ceil(simulationLength * worstCasePercentage / 100);
22437
22437
  return Math.min(simulationLength, Math.max(1, requested));
22438
22438
  }
22439
+ var ABSOLUTE_SIZING_PERCENTAGE_ERROR = "Historical-dollar loss sizing is not available with percentage returns: a fixed dollar amount has no stable meaning in a scale-free return stream. Use a dollar sampling method ('trades' or 'daily') for historical-dollar stress tests, or 'relative' sizing to scale each loss to account capital.";
22439
22440
  function normalizeRuinThresholdPct(ruinThresholdPct) {
22440
22441
  return ruinThresholdPct !== void 0 && ruinThresholdPct > 0 ? ruinThresholdPct : void 0;
22441
22442
  }
@@ -22805,6 +22806,10 @@ function runMonteCarloSimulation(trades, params) {
22805
22806
  `Insufficient trades for Monte Carlo simulation. Found ${trades.length} trades, need at least 10.`
22806
22807
  );
22807
22808
  }
22809
+ const worstCaseRequested = params.worstCaseEnabled === true && params.worstCasePercentage !== void 0 && params.worstCasePercentage > 0;
22810
+ if (worstCaseRequested && params.resampleMethod === "percentage" && params.worstCaseSizing === "absolute") {
22811
+ throw new Error(ABSOLUTE_SIZING_PERCENTAGE_ERROR);
22812
+ }
22808
22813
  const timestamp = /* @__PURE__ */ new Date();
22809
22814
  let resamplePool;
22810
22815
  let actualResamplePoolSize;
@@ -22846,7 +22851,7 @@ function runMonteCarloSimulation(trades, params) {
22846
22851
  );
22847
22852
  }
22848
22853
  let worstCaseTrades = [];
22849
- if (params.worstCaseEnabled && params.worstCasePercentage && params.worstCasePercentage > 0) {
22854
+ if (worstCaseRequested && params.worstCasePercentage) {
22850
22855
  const syntheticTrades = createSyntheticMaxLossTrades(
22851
22856
  trades,
22852
22857
  params.worstCasePercentage,
@@ -22860,15 +22865,11 @@ function runMonteCarloSimulation(trades, params) {
22860
22865
  const capitalBasis = capitalBasisRaw > 0 ? capitalBasisRaw : 1;
22861
22866
  if (params.resampleMethod === "percentage") {
22862
22867
  worstCaseTrades = syntheticTrades.map((t) => {
22863
- if (lossSizing === "relative") {
22864
- const ratio = t.syntheticCapitalRatio;
22865
- if (ratio && ratio > 0) {
22866
- return -Math.abs(ratio);
22867
- }
22868
- return t.pl / capitalBasis;
22868
+ const ratio = t.syntheticCapitalRatio;
22869
+ if (ratio && ratio > 0) {
22870
+ return -Math.abs(ratio);
22869
22871
  }
22870
- const pl = params.normalizeTo1Lot ? scaleTradeToOneLot(t) : t.pl;
22871
- return pl / capitalBasis;
22872
+ return t.pl / capitalBasis;
22872
22873
  });
22873
22874
  } else {
22874
22875
  worstCaseTrades = syntheticTrades.map((t) => {
@@ -22882,13 +22883,12 @@ function runMonteCarloSimulation(trades, params) {
22882
22883
  return params.normalizeTo1Lot ? scaleTradeToOneLot(t) : t.pl;
22883
22884
  });
22884
22885
  }
22885
- if (params.worstCaseMode === "pool") {
22886
- resamplePool = [...resamplePool, ...worstCaseTrades];
22887
- }
22888
22886
  }
22887
+ const worstCaseMode = params.worstCaseMode === "guarantee" ? "guarantee" : "probabilistic";
22888
+ const replacementProbability = worstCaseMode === "probabilistic" && worstCaseTrades.length > 0 ? Math.min(1, (params.worstCasePercentage ?? 0) / 100) : 0;
22889
22889
  const useStationaryBlocks = (params.resampleMode ?? "stationary-block") === "stationary-block";
22890
22890
  const meanBlockLength = params.meanBlockLength ?? defaultMeanBlockLength(resamplePool.length);
22891
- const enforcedGuaranteeTrades = params.worstCaseEnabled && params.worstCaseMode === "guarantee" && params.simulationLength > 0 ? worstCaseTrades.slice(0, Math.min(worstCaseTrades.length, params.simulationLength)) : [];
22891
+ const enforcedGuaranteeTrades = worstCaseMode === "guarantee" && params.simulationLength > 0 ? worstCaseTrades.slice(0, Math.min(worstCaseTrades.length, params.simulationLength)) : [];
22892
22892
  const ruinThresholdPct = normalizeRuinThresholdPct(params.ruinThresholdPct);
22893
22893
  const simulations = [];
22894
22894
  for (let i = 0; i < params.numSimulations; i++) {
@@ -22907,6 +22907,13 @@ function runMonteCarloSimulation(trades, params) {
22907
22907
  combined.length = params.simulationLength;
22908
22908
  }
22909
22909
  resampledPLs = combined;
22910
+ } else if (replacementProbability > 0) {
22911
+ const rng = seed !== void 0 ? createSeededRandom(seed + 999999) : Math.random;
22912
+ for (let position = 0; position < resampledPLs.length; position++) {
22913
+ if (rng() < replacementProbability) {
22914
+ resampledPLs[position] = worstCaseTrades[Math.floor(rng() * worstCaseTrades.length)];
22915
+ }
22916
+ }
22910
22917
  }
22911
22918
  const simulation = runSingleSimulation(
22912
22919
  resampledPLs,
@@ -22926,7 +22933,8 @@ function runMonteCarloSimulation(trades, params) {
22926
22933
  parameters: params,
22927
22934
  timestamp,
22928
22935
  actualResamplePoolSize,
22929
- effectiveMeanBlockLength: useStationaryBlocks ? meanBlockLength : null
22936
+ effectiveMeanBlockLength: useStationaryBlocks ? meanBlockLength : null,
22937
+ effectiveWorstCaseReplacementProbability: replacementProbability > 0 ? replacementProbability : null
22930
22938
  };
22931
22939
  }
22932
22940
  function calculatePercentiles(simulations) {
@@ -26341,6 +26349,7 @@ export {
26341
26349
  WalkForwardAnalyzer,
26342
26350
  assessResults,
26343
26351
  getRecommendedParameters,
26352
+ ABSOLUTE_SIZING_PERCENTAGE_ERROR,
26344
26353
  runMonteCarloSimulation,
26345
26354
  calculateDailyExposure,
26346
26355
  REPORT_FIELDS,
@@ -26384,4 +26393,4 @@ decimal.js/decimal.mjs:
26384
26393
  * MIT Licence
26385
26394
  *)
26386
26395
  */
26387
- //# sourceMappingURL=chunk-HC2NGC34.js.map
26396
+ //# sourceMappingURL=chunk-LNAAA74R.js.map