fix: backfill symbol_demand for sidebar-added symbols + analyst ratings schema fix
- Add await ctx.cache.subscribe() to addSymbol mutation so symbols added via the sidebar get registered in symbol_demand and yfinance jobs are queued immediately - Backfill PEP, WYNN, STZ, CELH into symbol_demand + adapter_queue - Upgrade yahoo-finance2 3.15.3 -> 3.15.4 and pass validateResult:false to quoteSummary() to handle Yahoo schema drift - Add error detail logging for analyst ratings schema failures - Update .gitignore with common ignores
This commit is contained in:
1 parent
5ef2b2f060
commit
e262187c3c
204 files changed
+25014
-2934
No files matched your search
@@ -0,0 +1,106 @@
|
||||
// Tests for Derisking Engine (Slice 23)
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
DERISKING_STRATEGIES,
|
||||
suggestDerisking,
|
||||
type DeriskingInput,
|
||||
} from '../derisking/DeriskingEngine.ts';
|
||||
|
||||
describe('DeriskingEngine', () => {
|
||||
it('DERISKING_STRATEGIES: has exactly 6 strategies', () => {
|
||||
assert.equal(DERISKING_STRATEGIES.length, 6);
|
||||
});
|
||||
|
||||
it('DERISKING_STRATEGIES: all have Alfred framing', () => {
|
||||
for (const s of DERISKING_STRATEGIES) {
|
||||
assert.ok(s.alfredFraming.length > 0, `${s.id} missing Alfred framing`);
|
||||
}
|
||||
});
|
||||
|
||||
it('DERISKING_STRATEGIES: option collar requires options sleeve', () => {
|
||||
const collar = DERISKING_STRATEGIES.find((s) => s.id === 'option_protected_collar');
|
||||
assert.ok(collar?.requiresOptionsSleeve);
|
||||
});
|
||||
|
||||
it('suggestDerisking: scale_out triggers when hitting profit target', () => {
|
||||
const input: DeriskingInput = {
|
||||
symbol: 'AAPL',
|
||||
currentPrice: 120,
|
||||
avgCost: 100,
|
||||
shares: 100,
|
||||
profitTargets: [115, 130],
|
||||
};
|
||||
const suggestions = suggestDerisking(input);
|
||||
const scaleOut = suggestions.find((s) => s.strategy.id === 'scale_out_at_targets');
|
||||
assert.ok(scaleOut, 'scale_out should be suggested');
|
||||
assert.ok(scaleOut.applicable);
|
||||
});
|
||||
|
||||
it('suggestDerisking: stop_trail triggers when in profit with EMA', () => {
|
||||
const input: DeriskingInput = {
|
||||
symbol: 'AAPL',
|
||||
currentPrice: 120,
|
||||
avgCost: 100,
|
||||
shares: 100,
|
||||
ema21: 115,
|
||||
};
|
||||
const suggestions = suggestDerisking(input);
|
||||
const stopTrail = suggestions.find((s) => s.strategy.id === 'stop_trail_ema21_50');
|
||||
assert.ok(stopTrail?.applicable);
|
||||
});
|
||||
|
||||
it('suggestDerisking: thesis_based_partial triggers on weakening', () => {
|
||||
const input: DeriskingInput = {
|
||||
symbol: 'AAPL',
|
||||
currentPrice: 100,
|
||||
avgCost: 90,
|
||||
shares: 100,
|
||||
thesisStatus: 'weakening',
|
||||
};
|
||||
const suggestions = suggestDerisking(input);
|
||||
const partial = suggestions.find((s) => s.strategy.id === 'thesis_based_partial');
|
||||
assert.ok(partial?.applicable);
|
||||
});
|
||||
|
||||
it('suggestDerisking: option_protected_collar gated by options unlock', () => {
|
||||
const inputLow: DeriskingInput = {
|
||||
symbol: 'AAPL', currentPrice: 120, avgCost: 100, shares: 100,
|
||||
optionsUnlockState: 0,
|
||||
};
|
||||
assert.equal(suggestDerisking(inputLow).find((s) => s.strategy.id === 'option_protected_collar'), undefined);
|
||||
|
||||
const inputHigh: DeriskingInput = {
|
||||
symbol: 'AAPL', currentPrice: 120, avgCost: 100, shares: 100,
|
||||
optionsUnlockState: 3,
|
||||
};
|
||||
const suggestions = suggestDerisking(inputHigh);
|
||||
assert.ok(suggestions.find((s) => s.strategy.id === 'option_protected_collar')?.applicable);
|
||||
});
|
||||
|
||||
it('suggestDerisking: regime_cut triggers on trending-down', () => {
|
||||
const input: DeriskingInput = {
|
||||
symbol: 'AAPL', currentPrice: 100, avgCost: 90, shares: 100,
|
||||
currentRegime: 'trending-down',
|
||||
};
|
||||
const suggestions = suggestDerisking(input);
|
||||
assert.ok(suggestions.find((s) => s.strategy.id === 'regime_cut')?.applicable);
|
||||
});
|
||||
|
||||
it('suggestDerisking: correlation_driven triggers on high correlation', () => {
|
||||
const input: DeriskingInput = {
|
||||
symbol: 'AAPL', currentPrice: 100, avgCost: 90, shares: 100,
|
||||
portfolioCorrelation: 0.85,
|
||||
};
|
||||
const suggestions = suggestDerisking(input);
|
||||
assert.ok(suggestions.find((s) => s.strategy.id === 'correlation_driven')?.applicable);
|
||||
});
|
||||
|
||||
it('suggestDerisking: no suggestions when nothing applies', () => {
|
||||
const input: DeriskingInput = {
|
||||
symbol: 'AAPL', currentPrice: 90, avgCost: 100, shares: 100,
|
||||
};
|
||||
const suggestions = suggestDerisking(input);
|
||||
assert.equal(suggestions.length, 0);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user