aiden-shared-calculations-unified 1.0.97 → 1.0.98
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/calculations/core/insights-daily-bought-vs-sold-count.js +8 -50
- package/calculations/core/insights-daily-ownership-delta.js +7 -46
- package/calculations/core/insights-sentimet-per-stock.js +7 -45
- package/calculations/core/insights-total-positions-held.js +5 -35
- package/calculations/predicative-alpha/mimetic-latency.js +9 -13
- package/package.json +1 -1
- /package/calculations/core/{Insights-total-long-per-stock → Insights-total-long-per-stock.js} +0 -0
- /package/calculations/core/{insights-total-long-per-sector → insights-total-long-per-sector.js} +0 -0
|
@@ -1,74 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculation (Pass 1) for daily bought vs. sold count.
|
|
3
|
-
* REFACTORED: Uses INSIGHTS DATA as Single Source of Truth.
|
|
4
|
-
* TYPE: META (Runs once against global data)
|
|
5
|
-
*/
|
|
6
1
|
class InsightsDailyBoughtVsSoldCount {
|
|
7
|
-
constructor() {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getMetadata() {
|
|
12
|
-
return {
|
|
13
|
-
type: 'meta',
|
|
14
|
-
rootDataDependencies: ['insights'], // explicit dependency on insights
|
|
15
|
-
isHistorical: true,
|
|
16
|
-
category: 'core_metrics'
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
2
|
+
constructor() { this.results = {}; }
|
|
3
|
+
static getMetadata() { return { type: 'meta', rootDataDependencies: ['insights'], isHistorical: true, category: 'core_metrics' }; }
|
|
20
4
|
static getDependencies() { return []; }
|
|
21
|
-
|
|
22
5
|
static getSchema() {
|
|
23
|
-
const tickerSchema = {
|
|
24
|
-
"type": "object",
|
|
25
|
-
"properties": {
|
|
26
|
-
"positions_bought": { "type": "number" },
|
|
27
|
-
"positions_sold": { "type": "number" },
|
|
28
|
-
"net_change": { "type": "number" }
|
|
29
|
-
},
|
|
30
|
-
"required": ["positions_bought", "positions_sold", "net_change"]
|
|
31
|
-
};
|
|
6
|
+
const tickerSchema = { "type": "object", "properties": { "positions_bought": { "type": "number" }, "positions_sold": { "type": "number" }, "net_change": { "type": "number" } }, "required": ["positions_bought", "positions_sold", "net_change"] };
|
|
32
7
|
return { "type": "object", "patternProperties": { "^.*$": tickerSchema } };
|
|
33
8
|
}
|
|
34
|
-
|
|
35
9
|
process(context) {
|
|
36
|
-
const { insights: insightsHelper } = context.math;
|
|
10
|
+
const { insights: insightsHelper } = context.math;
|
|
37
11
|
const insights = insightsHelper.getInsights(context);
|
|
38
12
|
const { mappings } = context;
|
|
39
13
|
const tickerMap = mappings.instrumentToTicker || {};
|
|
40
14
|
|
|
41
|
-
if (!insights || !Array.isArray(insights)) return;
|
|
15
|
+
if (!insights || !Array.isArray(insights)) return; // FIX: Strict array check
|
|
42
16
|
|
|
43
17
|
for (const insight of insights) {
|
|
44
18
|
const instId = insight.instrumentId;
|
|
45
19
|
const ticker = tickerMap[instId] || `id_${instId}`;
|
|
46
|
-
|
|
47
20
|
const netChange = insightsHelper.getNetOwnershipChange(insight);
|
|
48
|
-
|
|
49
|
-
// Insights schema only provides Net Growth.
|
|
50
|
-
// We cannot strictly separate Bought vs Sold.
|
|
51
|
-
// Logic: If Net Positive -> Bought = Net, Sold = 0.
|
|
52
|
-
// If Net Negative -> Bought = 0, Sold = Abs(Net).
|
|
53
21
|
const bought = netChange > 0 ? netChange : 0;
|
|
54
22
|
const sold = netChange < 0 ? Math.abs(netChange) : 0;
|
|
55
23
|
|
|
56
24
|
if (bought > 0 || sold > 0) {
|
|
57
|
-
this.results[ticker] = {
|
|
58
|
-
positions_bought: bought,
|
|
59
|
-
positions_sold: sold,
|
|
60
|
-
net_change: netChange
|
|
61
|
-
};
|
|
25
|
+
this.results[ticker] = { positions_bought: bought, positions_sold: sold, net_change: netChange };
|
|
62
26
|
}
|
|
63
27
|
}
|
|
64
28
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return this.results;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
reset() {
|
|
71
|
-
this.results = {};
|
|
72
|
-
}
|
|
29
|
+
async getResult() { return this.results; }
|
|
30
|
+
reset() { this.results = {}; }
|
|
73
31
|
}
|
|
74
32
|
module.exports = InsightsDailyBoughtVsSoldCount;
|
|
@@ -1,70 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculation (Pass 1) for ownership delta (users added/lost per asset).
|
|
3
|
-
* REFACTORED: Uses INSIGHTS DATA.
|
|
4
|
-
* TYPE: META
|
|
5
|
-
*/
|
|
6
1
|
class InsightsDailyOwnershipDelta {
|
|
7
|
-
constructor() {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getMetadata() {
|
|
12
|
-
return {
|
|
13
|
-
type: 'meta',
|
|
14
|
-
rootDataDependencies: ['insights'],
|
|
15
|
-
isHistorical: true,
|
|
16
|
-
category: 'core_metrics'
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
2
|
+
constructor() { this.results = {}; }
|
|
3
|
+
static getMetadata() { return { type: 'meta', rootDataDependencies: ['insights'], isHistorical: true, category: 'core_metrics' }; }
|
|
20
4
|
static getDependencies() { return []; }
|
|
21
|
-
|
|
22
5
|
static getSchema() {
|
|
23
|
-
const tickerSchema = {
|
|
24
|
-
"type": "object",
|
|
25
|
-
"properties": {
|
|
26
|
-
"owners_added": { "type": "number" },
|
|
27
|
-
"owners_removed": { "type": "number" },
|
|
28
|
-
"net_ownership_change": { "type": "number" }
|
|
29
|
-
},
|
|
30
|
-
"required": ["owners_added", "owners_removed", "net_ownership_change"]
|
|
31
|
-
};
|
|
6
|
+
const tickerSchema = { "type": "object", "properties": { "owners_added": { "type": "number" }, "owners_removed": { "type": "number" }, "net_ownership_change": { "type": "number" } }, "required": ["owners_added", "owners_removed", "net_ownership_change"] };
|
|
32
7
|
return { "type": "object", "patternProperties": { "^.*$": tickerSchema } };
|
|
33
8
|
}
|
|
34
|
-
|
|
35
9
|
process(context) {
|
|
36
10
|
const { insights: insightsHelper } = context.math;
|
|
37
11
|
const insights = insightsHelper.getInsights(context);
|
|
38
12
|
const { mappings } = context;
|
|
39
13
|
const tickerMap = mappings.instrumentToTicker || {};
|
|
40
14
|
|
|
41
|
-
if (!insights) return;
|
|
15
|
+
if (!insights || !Array.isArray(insights)) return; // FIX: Strict array check
|
|
42
16
|
|
|
43
17
|
for (const insight of insights) {
|
|
44
18
|
const netChange = insightsHelper.getNetOwnershipChange(insight);
|
|
45
19
|
if (netChange === 0) continue;
|
|
46
|
-
|
|
47
20
|
const instId = insight.instrumentId;
|
|
48
21
|
const ticker = tickerMap[instId] || `id_${instId}`;
|
|
49
|
-
|
|
50
|
-
// Approximate added/removed based on Net Change logic
|
|
51
22
|
const added = netChange > 0 ? netChange : 0;
|
|
52
23
|
const removed = netChange < 0 ? Math.abs(netChange) : 0;
|
|
53
24
|
|
|
54
|
-
this.results[ticker] = {
|
|
55
|
-
owners_added: added,
|
|
56
|
-
owners_removed: removed,
|
|
57
|
-
net_ownership_change: netChange
|
|
58
|
-
};
|
|
25
|
+
this.results[ticker] = { owners_added: added, owners_removed: removed, net_ownership_change: netChange };
|
|
59
26
|
}
|
|
60
27
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return this.results;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
reset() {
|
|
67
|
-
this.results = {};
|
|
68
|
-
}
|
|
28
|
+
async getResult() { return this.results; }
|
|
29
|
+
reset() { this.results = {}; }
|
|
69
30
|
}
|
|
70
31
|
module.exports = InsightsDailyOwnershipDelta;
|
|
@@ -1,68 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculation (Pass 1) for sentiment per stock.
|
|
3
|
-
* REFACTORED: Uses INSIGHTS DATA.
|
|
4
|
-
* TYPE: META
|
|
5
|
-
*/
|
|
6
1
|
class InsightsSentimentPerStock {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.results = {};
|
|
9
|
-
}
|
|
10
|
-
|
|
2
|
+
constructor() { this.results = {}; }
|
|
11
3
|
static getSchema() {
|
|
12
|
-
const tickerSchema = {
|
|
13
|
-
"type": "object",
|
|
14
|
-
"properties": {
|
|
15
|
-
"long_count": { "type": "number" },
|
|
16
|
-
"short_count": { "type": "number" },
|
|
17
|
-
"sentiment_ratio": { "type": ["number", "null"] }
|
|
18
|
-
},
|
|
19
|
-
"required": ["long_count", "short_count", "sentiment_ratio"]
|
|
20
|
-
};
|
|
4
|
+
const tickerSchema = { "type": "object", "properties": { "long_count": { "type": "number" }, "short_count": { "type": "number" }, "sentiment_ratio": { "type": ["number", "null"] } }, "required": ["long_count", "short_count", "sentiment_ratio"] };
|
|
21
5
|
return { "type": "object", "patternProperties": { "^.*$": tickerSchema } };
|
|
22
6
|
}
|
|
23
|
-
|
|
24
|
-
static getMetadata() {
|
|
25
|
-
return {
|
|
26
|
-
type: 'meta',
|
|
27
|
-
rootDataDependencies: ['insights'],
|
|
28
|
-
isHistorical: false,
|
|
29
|
-
category: 'core_sentiment'
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
7
|
+
static getMetadata() { return { type: 'meta', rootDataDependencies: ['insights'], isHistorical: false, category: 'core_sentiment' }; }
|
|
33
8
|
static getDependencies() { return []; }
|
|
34
|
-
|
|
35
9
|
process(context) {
|
|
36
10
|
const { insights: insightsHelper } = context.math;
|
|
37
11
|
const insights = insightsHelper.getInsights(context);
|
|
38
12
|
const { mappings } = context;
|
|
39
13
|
const tickerMap = mappings.instrumentToTicker || {};
|
|
40
14
|
|
|
41
|
-
if (!insights) return;
|
|
15
|
+
if (!insights || !Array.isArray(insights)) return; // FIX: Strict array check
|
|
42
16
|
|
|
43
17
|
for (const insight of insights) {
|
|
44
18
|
const longCount = insightsHelper.getLongCount(insight);
|
|
45
19
|
const shortCount = insightsHelper.getShortCount(insight);
|
|
46
|
-
|
|
47
20
|
if (longCount === 0 && shortCount === 0) continue;
|
|
48
|
-
|
|
49
21
|
const instId = insight.instrumentId;
|
|
50
22
|
const ticker = tickerMap[instId] || `id_${instId}`;
|
|
51
23
|
|
|
52
|
-
this.results[ticker] = {
|
|
53
|
-
long_count: longCount,
|
|
54
|
-
short_count: shortCount,
|
|
55
|
-
sentiment_ratio: (shortCount > 0) ? (longCount / shortCount) : null
|
|
56
|
-
};
|
|
24
|
+
this.results[ticker] = { long_count: longCount, short_count: shortCount, sentiment_ratio: (shortCount > 0) ? (longCount / shortCount) : null };
|
|
57
25
|
}
|
|
58
26
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return this.results;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
reset() {
|
|
65
|
-
this.results = {};
|
|
66
|
-
}
|
|
27
|
+
async getResult() { return this.results; }
|
|
28
|
+
reset() { this.results = {}; }
|
|
67
29
|
}
|
|
68
30
|
module.exports = InsightsSentimentPerStock;
|
|
@@ -1,49 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculation (Pass 1) for total positions count.
|
|
3
|
-
* REFACTORED: Uses INSIGHTS DATA.
|
|
4
|
-
* TYPE: META
|
|
5
|
-
*/
|
|
6
1
|
class InsightsTotalPositionsHeld {
|
|
7
|
-
constructor() {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getMetadata() {
|
|
12
|
-
return {
|
|
13
|
-
type: 'meta',
|
|
14
|
-
rootDataDependencies: ['insights'],
|
|
15
|
-
isHistorical: false,
|
|
16
|
-
category: 'Global-Platform-Metrics'
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
2
|
+
constructor() { this.totalPositions = 0; }
|
|
3
|
+
static getMetadata() { return { type: 'meta', rootDataDependencies: ['insights'], isHistorical: false, category: 'Global-Platform-Metrics' }; }
|
|
20
4
|
static getDependencies() { return []; }
|
|
21
|
-
|
|
22
|
-
static getSchema() {
|
|
23
|
-
return {
|
|
24
|
-
"type": "object",
|
|
25
|
-
"properties": {
|
|
26
|
-
"total_positions_count": { "type": "number" }
|
|
27
|
-
},
|
|
28
|
-
"required": ["total_positions_count"]
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
5
|
+
static getSchema() { return { "type": "object", "properties": { "total_positions_count": { "type": "number" } }, "required": ["total_positions_count"] }; }
|
|
32
6
|
process(context) {
|
|
33
7
|
const { insights: insightsHelper } = context.math;
|
|
34
8
|
const insights = insightsHelper.getInsights(context);
|
|
35
9
|
|
|
36
|
-
if (!insights) return;
|
|
10
|
+
if (!insights || !Array.isArray(insights)) return; // FIX: Strict array check
|
|
37
11
|
|
|
38
12
|
for (const insight of insights) {
|
|
39
13
|
this.totalPositions += insightsHelper.getTotalOwners(insight);
|
|
40
14
|
}
|
|
41
15
|
}
|
|
42
|
-
|
|
43
|
-
getResult() {
|
|
44
|
-
return { total_positions_count: this.totalPositions };
|
|
45
|
-
}
|
|
46
|
-
|
|
16
|
+
getResult() { return { total_positions_count: this.totalPositions }; }
|
|
47
17
|
reset() { this.totalPositions = 0; }
|
|
48
18
|
}
|
|
49
19
|
module.exports = InsightsTotalPositionsHeld;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Mimetic Latency Oscillator (MLO) v2.
|
|
3
|
-
*
|
|
4
|
-
* Self-healing state: Warms up over 15-30 days automatically.
|
|
2
|
+
* @fileoverview Mimetic Latency Oscillator (MLO) v2.3
|
|
3
|
+
* FIXED: Safe state access to prevent 'undefined' property errors.
|
|
5
4
|
*/
|
|
6
5
|
class MimeticLatencyOscillator {
|
|
7
6
|
constructor() {
|
|
@@ -47,25 +46,24 @@ class MimeticLatencyOscillator {
|
|
|
47
46
|
const rawFlow = SignalPrimitives.getMetric(computed, 'skilled-cohort-flow', ticker, 'net_flow_pct', 0);
|
|
48
47
|
const rawHerd = SignalPrimitives.getMetric(computed, 'herd-consensus-score', ticker, 'herd_conviction_score', 0);
|
|
49
48
|
|
|
50
|
-
// 2. Restore State (
|
|
49
|
+
// 2. Restore State (FIX: Safe Access)
|
|
51
50
|
const prevResult = SignalPrimitives.getPreviousState(previousComputed, 'mimetic-latency', ticker);
|
|
52
|
-
const prevState = prevResult ? prevResult._state :
|
|
51
|
+
const prevState = prevResult ? prevResult._state : null;
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
const
|
|
53
|
+
// FIX: Check if prevState exists before accessing properties
|
|
54
|
+
const prevFlow = (prevState && prevState.last_flow !== undefined) ? prevState.last_flow : 0;
|
|
55
|
+
const prevHerd = (prevState && prevState.last_herd !== undefined) ? prevState.last_herd : 0;
|
|
56
|
+
const flowBuffer = (prevState && Array.isArray(prevState.flow_buffer)) ? [...prevState.flow_buffer] : [];
|
|
57
|
+
const herdBuffer = (prevState && Array.isArray(prevState.herd_buffer)) ? [...prevState.herd_buffer] : [];
|
|
56
58
|
|
|
57
59
|
// 3. Calculate Detrended Delta
|
|
58
60
|
const flowDelta = rawFlow - prevFlow;
|
|
59
61
|
const herdDelta = rawHerd - prevHerd;
|
|
60
62
|
|
|
61
63
|
// 4. Update Buffers
|
|
62
|
-
let flowBuffer = [...(prevState.flow_buffer || [])];
|
|
63
|
-
let herdBuffer = [...(prevState.herd_buffer || [])];
|
|
64
|
-
|
|
65
64
|
flowBuffer.push(flowDelta);
|
|
66
65
|
herdBuffer.push(herdDelta);
|
|
67
66
|
|
|
68
|
-
// Cap memory usage
|
|
69
67
|
if (flowBuffer.length > this.windowSize) flowBuffer.shift();
|
|
70
68
|
if (herdBuffer.length > this.windowSize) herdBuffer.shift();
|
|
71
69
|
|
|
@@ -74,7 +72,6 @@ class MimeticLatencyOscillator {
|
|
|
74
72
|
let bestLag = 0;
|
|
75
73
|
let regime = "WARM_UP";
|
|
76
74
|
|
|
77
|
-
// Only compute if we have statistical significance (>= 15 samples)
|
|
78
75
|
if (flowBuffer.length >= 15) {
|
|
79
76
|
for (let k = 0; k <= this.maxLag; k++) {
|
|
80
77
|
const len = flowBuffer.length;
|
|
@@ -91,7 +88,6 @@ class MimeticLatencyOscillator {
|
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
// 6. Regime Classification
|
|
95
91
|
if (maxCorr > 0.3) {
|
|
96
92
|
if (bestLag >= 3) regime = "EARLY_ALPHA";
|
|
97
93
|
else if (bestLag >= 1) regime = "MARKUP";
|
package/package.json
CHANGED
/package/calculations/core/{Insights-total-long-per-stock → Insights-total-long-per-stock.js}
RENAMED
|
File without changes
|
/package/calculations/core/{insights-total-long-per-sector → insights-total-long-per-sector.js}
RENAMED
|
File without changes
|