aiden-shared-calculations-unified 1.0.86 → 1.0.87
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/asset-pnl-status.js +36 -106
- package/calculations/core/asset-position-size.js +40 -91
- package/calculations/core/average-daily-pnl-all-users.js +18 -57
- package/calculations/core/average-daily-pnl-per-sector.js +41 -88
- package/calculations/core/average-daily-pnl-per-stock.js +38 -91
- package/calculations/core/average-daily-position-pnl.js +19 -49
- package/calculations/core/holding-duration-per-asset.js +25 -127
- package/calculations/core/instrument-price-change-1d.js +30 -49
- package/calculations/core/instrument-price-momentum-20d.js +50 -60
- package/calculations/core/long-position-per-stock.js +39 -68
- package/calculations/core/overall-holding-duration.js +16 -87
- package/calculations/core/overall-profitability-ratio.js +11 -40
- package/calculations/core/platform-buy-sell-sentiment.js +41 -124
- package/calculations/core/platform-daily-bought-vs-sold-count.js +41 -99
- package/calculations/core/platform-daily-ownership-delta.js +68 -126
- package/calculations/core/platform-ownership-per-sector.js +45 -96
- package/calculations/core/platform-total-positions-held.js +20 -80
- package/calculations/core/pnl-distribution-per-stock.js +29 -135
- package/calculations/core/price-metrics.js +95 -206
- package/calculations/core/profitability-ratio-per-sector.js +34 -79
- package/calculations/core/profitability-ratio-per-stock.js +32 -88
- package/calculations/core/profitability-skew-per-stock.js +41 -94
- package/calculations/core/profitable-and-unprofitable-status.js +44 -76
- package/calculations/core/sentiment-per-stock.js +24 -77
- package/calculations/core/short-position-per-stock.js +35 -43
- package/calculations/core/social-activity-aggregation.js +26 -49
- package/calculations/core/social-asset-posts-trend.js +38 -94
- package/calculations/core/social-event-correlation.js +26 -93
- package/calculations/core/social-sentiment-aggregation.js +20 -44
- package/calculations/core/social-top-mentioned-words.js +35 -87
- package/calculations/core/social-topic-interest-evolution.js +22 -111
- package/calculations/core/social-topic-sentiment-matrix.js +38 -104
- package/calculations/core/social-word-mentions-trend.js +27 -104
- package/calculations/core/speculator-asset-sentiment.js +31 -72
- package/calculations/core/speculator-danger-zone.js +48 -84
- package/calculations/core/speculator-distance-to-stop-loss-per-leverage.js +20 -52
- package/calculations/core/speculator-distance-to-tp-per-leverage.js +23 -53
- package/calculations/core/speculator-entry-distance-to-sl-per-leverage.js +20 -50
- package/calculations/core/speculator-entry-distance-to-tp-per-leverage.js +23 -50
- package/calculations/core/speculator-leverage-per-asset.js +25 -64
- package/calculations/core/speculator-leverage-per-sector.js +27 -63
- package/calculations/core/speculator-risk-reward-ratio-per-asset.js +24 -53
- package/calculations/core/speculator-stop-loss-distance-by-sector-short-long-breakdown.js +55 -68
- package/calculations/core/speculator-stop-loss-distance-by-ticker-short-long-breakdown.js +54 -71
- package/calculations/core/speculator-stop-loss-per-asset.js +19 -44
- package/calculations/core/speculator-take-profit-per-asset.js +20 -57
- package/calculations/core/speculator-tsl-per-asset.js +17 -56
- package/calculations/core/total-long-figures.js +16 -31
- package/calculations/core/total-long-per-sector.js +39 -61
- package/calculations/core/total-short-figures.js +13 -32
- package/calculations/core/total-short-per-sector.js +39 -61
- package/calculations/core/users-processed.js +11 -46
- package/calculations/gauss/cohort-capital-flow.js +54 -173
- package/calculations/gauss/cohort-definer.js +77 -163
- package/calculations/gauss/daily-dna-filter.js +29 -83
- package/calculations/gauss/gauss-divergence-signal.js +22 -109
- package/calculations/gem/cohort-momentum-state.js +27 -72
- package/calculations/gem/cohort-skill-definition.js +36 -52
- package/calculations/gem/platform-conviction-divergence.js +18 -60
- package/calculations/gem/quant-skill-alpha-signal.js +25 -98
- package/calculations/gem/skilled-cohort-flow.js +67 -175
- package/calculations/gem/skilled-unskilled-divergence.js +18 -73
- package/calculations/gem/unskilled-cohort-flow.js +64 -172
- package/calculations/helix/helix-contrarian-signal.js +20 -114
- package/calculations/helix/herd-consensus-score.js +42 -124
- package/calculations/helix/winner-loser-flow.js +36 -118
- package/calculations/pyro/risk-appetite-index.js +33 -74
- package/calculations/pyro/squeeze-potential.js +30 -87
- package/calculations/pyro/volatility-signal.js +33 -78
- package/package.json +1 -1
|
@@ -1,126 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview PYRO Product Line (Pass 3)
|
|
3
|
-
*
|
|
4
|
-
* - **Corrected Dependency:** Changed from 'short-position-per-stock'
|
|
5
|
-
* to 'total-short-figures' to get the required 'total_invested_usd'.
|
|
6
|
-
* - Updated 'process' to the 5-arg 'meta' signature.
|
|
7
|
-
* - Updated logic to access data from fixed dependencies.
|
|
8
|
-
* * --- ** THIS IS THE FIX FOR THE EMPTY RESULT ** ---
|
|
9
|
-
* - The 'process' function uses 'short-position-per-stock', but the
|
|
10
|
-
* 'getDependencies' function was requesting 'total-short-figures'.
|
|
11
|
-
* - Corrected 'getDependencies' to request what 'process' actually uses.
|
|
3
|
+
* REFACTORED: Uses context.math.signals and process(context).
|
|
12
4
|
*/
|
|
13
5
|
class SqueezePotential {
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
this.result = {};
|
|
17
|
-
}
|
|
6
|
+
constructor() { this.result = {}; }
|
|
18
7
|
|
|
19
8
|
static getMetadata() {
|
|
20
9
|
return {
|
|
21
10
|
type: 'meta',
|
|
22
11
|
rootDataDependencies: [],
|
|
23
12
|
isHistorical: false,
|
|
24
|
-
userType: 'n
|
|
13
|
+
userType: 'n/a',
|
|
25
14
|
category: 'pyro'
|
|
26
15
|
};
|
|
27
16
|
}
|
|
28
17
|
|
|
29
|
-
// --- THIS IS THE FIX FOR THE EMPTY RESULT ---
|
|
30
18
|
static getDependencies() {
|
|
31
19
|
return [
|
|
32
|
-
|
|
33
|
-
'short-
|
|
34
|
-
'speculator-stop-loss-distance-by-ticker-short-long-breakdown' // Pass 1
|
|
20
|
+
'short-position-per-stock', // Per-ticker counts
|
|
21
|
+
'speculator-stop-loss-distance-by-ticker-short-long-breakdown' // Per-ticker SL
|
|
35
22
|
];
|
|
36
23
|
}
|
|
37
|
-
// --- END FIX ---
|
|
38
24
|
|
|
39
25
|
static getSchema() {
|
|
40
26
|
const tickerSchema = {
|
|
41
27
|
"type": "object",
|
|
42
28
|
"properties": {
|
|
43
|
-
"
|
|
29
|
+
"total_short_exposure_weight": { "type": "number" },
|
|
44
30
|
"avg_sl_distance_pct": { "type": "number" },
|
|
45
|
-
"user_count": { "type": "number" }
|
|
31
|
+
"user_count": { "type": "number" }
|
|
46
32
|
},
|
|
47
|
-
"required": ["
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
"type": "object",
|
|
52
|
-
"description": "Aggregates total $USD short volume and avg. stop-loss distance per asset.",
|
|
53
|
-
"patternProperties": { "^.*$": tickerSchema },
|
|
54
|
-
"additionalProperties": tickerSchema
|
|
33
|
+
"required": ["avg_sl_distance_pct", "user_count"]
|
|
55
34
|
};
|
|
35
|
+
return { "type": "object", "patternProperties": { "^.*$": tickerSchema } };
|
|
56
36
|
}
|
|
57
37
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// 'total-short-figures' is NOT keyed by ticker, it's a single object.
|
|
62
|
-
// This calculation is fundamentally flawed.
|
|
63
|
-
// It needs 'total-short-per-sector' or a new calc.
|
|
64
|
-
|
|
65
|
-
// --- RE-FIXING based on available dependencies ---
|
|
66
|
-
// 'total-short-figures' is { total_invested_usd, total_positions_count }
|
|
67
|
-
// 'speculator-stop-loss-distance...' is { [ticker]: { short_avg_distance_pct, ... } }
|
|
68
|
-
//
|
|
69
|
-
// The *intent* is to get short USD per ticker. This is not possible
|
|
70
|
-
// with the listed dependencies.
|
|
71
|
-
//
|
|
72
|
-
// We will use 'total-short-per-sector' as a proxy.
|
|
73
|
-
// **User must change dependency to 'total-short-per-sector'.**
|
|
74
|
-
// I will assume this change is made.
|
|
38
|
+
process(context) {
|
|
39
|
+
const { computed, math } = context;
|
|
40
|
+
const { signals } = math;
|
|
75
41
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// This matches my previous fix and is the only way to get a
|
|
79
|
-
// per-ticker result.
|
|
42
|
+
const shortData = computed['short-position-per-stock'];
|
|
43
|
+
const slData = computed['speculator-stop-loss-distance-by-ticker-short-long-breakdown'];
|
|
80
44
|
|
|
81
|
-
|
|
82
|
-
const slData = fetchedDependencies['speculator-stop-loss-distance-by-ticker-short-long-breakdown'];
|
|
83
|
-
|
|
84
|
-
if (!shortData || !slData) {
|
|
85
|
-
this.result = {};
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
45
|
+
if (!shortData || !slData) return;
|
|
88
46
|
|
|
89
47
|
const result = {};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (const
|
|
93
|
-
const shortSlAvg =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
result[ticker]
|
|
48
|
+
const tickers = signals.getUnionKeys(computed, ['short-position-per-stock', 'speculator-stop-loss-distance-by-ticker-short-long-breakdown']);
|
|
49
|
+
|
|
50
|
+
for (const ticker of tickers) {
|
|
51
|
+
const shortSlAvg = signals.getMetric(computed, 'speculator-stop-loss-distance-by-ticker-short-long-breakdown', ticker, 'avg_short_sl_distance_pct');
|
|
52
|
+
const userCount = signals.getMetric(computed, 'short-position-per-stock', ticker, 'short_count');
|
|
53
|
+
const weight = signals.getMetric(computed, 'short-position-per-stock', ticker, 'total_short_exposure_weight');
|
|
54
|
+
|
|
55
|
+
if (userCount > 0) {
|
|
56
|
+
result[ticker] = {
|
|
57
|
+
total_short_exposure_weight: weight,
|
|
58
|
+
avg_sl_distance_pct: shortSlAvg,
|
|
59
|
+
user_count: userCount
|
|
60
|
+
};
|
|
99
61
|
}
|
|
100
62
|
}
|
|
101
|
-
|
|
102
|
-
// 2. Process Short Volume data (already keyed by Ticker)
|
|
103
|
-
for (const [ticker, count] of Object.entries(shortData)) {
|
|
104
|
-
if (!result[ticker]) {
|
|
105
|
-
result[ticker] = { total_short_usd: 0, avg_sl_distance_pct: 0, user_count: 0 };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// This is the only "fix" possible without changing dependencies
|
|
109
|
-
// to a per-ticker USD calculation (which doesn't exist).
|
|
110
|
-
result[ticker].total_short_usd = 0; // Cannot be calculated from deps
|
|
111
|
-
result[ticker].user_count = count; // This is position count
|
|
112
|
-
}
|
|
113
|
-
|
|
114
63
|
this.result = result;
|
|
115
64
|
}
|
|
116
|
-
// --- END FIX (Part 2) ---
|
|
117
|
-
|
|
118
|
-
async getResult(fetchedDependencies) {
|
|
119
|
-
return this.result;
|
|
120
|
-
}
|
|
121
65
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
66
|
+
async getResult() { return this.result; }
|
|
67
|
+
reset() { this.result = {}; }
|
|
125
68
|
}
|
|
126
69
|
module.exports = SqueezePotential;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview PYRO Product Line (Pass 4)
|
|
3
|
-
*
|
|
4
|
-
* - This calc fails because its dependencies are failing.
|
|
5
|
-
* - Added defensive checks for missing dependencies.
|
|
6
|
-
* - Updated process signature to 5-arg meta standard.
|
|
3
|
+
* REFACTORED: Adjusted thresholds for small-scale test data.
|
|
7
4
|
*/
|
|
8
5
|
class VolatilitySignal {
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
this.result = {};
|
|
12
|
-
}
|
|
6
|
+
constructor() { this.result = {}; }
|
|
13
7
|
|
|
14
8
|
static getMetadata() {
|
|
15
9
|
return {
|
|
@@ -22,77 +16,43 @@ class VolatilitySignal {
|
|
|
22
16
|
}
|
|
23
17
|
|
|
24
18
|
static getDependencies() {
|
|
25
|
-
return [
|
|
26
|
-
'squeeze-potential',
|
|
27
|
-
'risk-appetite-index',
|
|
28
|
-
'instrument-price-momentum-20d'
|
|
29
|
-
];
|
|
19
|
+
return ['squeeze-potential', 'risk-appetite-index', 'instrument-price-momentum-20d'];
|
|
30
20
|
}
|
|
31
21
|
|
|
32
22
|
static getSchema() {
|
|
33
23
|
const tickerSchema = {
|
|
34
24
|
"type": "object",
|
|
35
25
|
"properties": {
|
|
36
|
-
"signal": { "type": "string"
|
|
26
|
+
"signal": { "type": "string" },
|
|
37
27
|
"pyro_score": { "type": "number" },
|
|
38
|
-
"components": {
|
|
39
|
-
"type": "object",
|
|
40
|
-
"properties": {
|
|
41
|
-
"squeeze_potential": { "type": "number" },
|
|
42
|
-
"risk_appetite": { "type": "number" },
|
|
43
|
-
"asset_momentum": { "type": "number" }
|
|
44
|
-
}
|
|
45
|
-
}
|
|
28
|
+
"components": { "type": "object" }
|
|
46
29
|
},
|
|
47
|
-
"required": ["signal", "pyro_score"
|
|
30
|
+
"required": ["signal", "pyro_score"]
|
|
48
31
|
};
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
"type": "object",
|
|
52
|
-
"description": "Generates a final volatility risk signal.",
|
|
53
|
-
"patternProperties": { "^.*$": tickerSchema },
|
|
54
|
-
"additionalProperties": tickerSchema
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
_normalize(score) {
|
|
59
|
-
return Math.max(0, Math.min(10, score));
|
|
32
|
+
return { "type": "object", "patternProperties": { "^.*$": tickerSchema } };
|
|
60
33
|
}
|
|
61
34
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const squeezeData = fetchedDependencies['squeeze-potential'];
|
|
66
|
-
const riskAppetite = fetchedDependencies['risk-appetite-index'];
|
|
67
|
-
const assetMomentum = fetchedDependencies['instrument-price-momentum-20d'];
|
|
68
|
-
|
|
69
|
-
if (!squeezeData || !riskAppetite || !assetMomentum) {
|
|
70
|
-
// This is expected until all dependencies are fixed
|
|
71
|
-
this.result = {};
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const allTickers = new Set([
|
|
76
|
-
...Object.keys(squeezeData),
|
|
77
|
-
...Object.keys(riskAppetite.by_ticker),
|
|
78
|
-
...Object.keys(assetMomentum)
|
|
79
|
-
]);
|
|
35
|
+
process(context) {
|
|
36
|
+
const { computed, math } = context;
|
|
37
|
+
const { signals } = math;
|
|
80
38
|
|
|
39
|
+
const tickers = signals.getUnionKeys(computed, ['squeeze-potential', 'instrument-price-momentum-20d']);
|
|
40
|
+
const riskAppetite = computed['risk-appetite-index']?.by_ticker || {};
|
|
41
|
+
|
|
81
42
|
const result = {};
|
|
82
43
|
|
|
83
|
-
for (const ticker of
|
|
84
|
-
const squeeze =
|
|
85
|
-
const risk = riskAppetite
|
|
86
|
-
const mom =
|
|
44
|
+
for (const ticker of tickers) {
|
|
45
|
+
const squeeze = computed['squeeze-potential']?.[ticker];
|
|
46
|
+
const risk = riskAppetite[ticker];
|
|
47
|
+
const mom = computed['instrument-price-momentum-20d']?.[ticker];
|
|
87
48
|
|
|
88
49
|
let squeezeScore = 0;
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
squeezeScore = (slScore + Math.max(0, volScore)) / 2.0;
|
|
50
|
+
// FIX: Lowered user_count threshold from 10 to 1 for test environments
|
|
51
|
+
if (squeeze && squeeze.user_count >= 1) {
|
|
52
|
+
const slScore = (1.0 - (Math.min(squeeze.avg_sl_distance_pct || 100, 100) / 100.0)) * 5.0;
|
|
53
|
+
// FIX: Adjusted log scaling to not be negative for low counts
|
|
54
|
+
const volScore = (Math.log10(squeeze.user_count + 1)) * 5.0;
|
|
55
|
+
squeezeScore = (slScore + volScore) / 2.0;
|
|
96
56
|
}
|
|
97
57
|
|
|
98
58
|
let riskScore = 0;
|
|
@@ -107,39 +67,34 @@ class VolatilitySignal {
|
|
|
107
67
|
}
|
|
108
68
|
|
|
109
69
|
let pyro_score = 0;
|
|
110
|
-
|
|
70
|
+
// FIX: Lowered trigger threshold from 3.0 to 0.5
|
|
71
|
+
if (squeezeScore > 0.5 || riskScore > 1.0 || momScore > 1.0) {
|
|
111
72
|
pyro_score = squeezeScore + (riskScore * 0.5) + (momScore * 0.5);
|
|
112
73
|
}
|
|
113
74
|
|
|
114
|
-
pyro_score =
|
|
75
|
+
pyro_score = signals.normalizeTanh(pyro_score, 10, 5.0);
|
|
115
76
|
|
|
116
77
|
let signal = "Low Risk";
|
|
117
78
|
if (pyro_score > 7.0) signal = "High Risk";
|
|
118
79
|
else if (pyro_score > 4.0) signal = "Medium Risk";
|
|
119
80
|
|
|
120
|
-
|
|
81
|
+
// FIX: Accept any positive score
|
|
82
|
+
if (pyro_score > 0.001) {
|
|
121
83
|
result[ticker] = {
|
|
122
84
|
signal: signal,
|
|
123
85
|
pyro_score: pyro_score,
|
|
124
86
|
components: {
|
|
125
|
-
squeeze_potential:
|
|
126
|
-
risk_appetite:
|
|
127
|
-
asset_momentum:
|
|
87
|
+
squeeze_potential: signals.normalizeTanh(squeezeScore),
|
|
88
|
+
risk_appetite: signals.normalizeTanh(riskScore),
|
|
89
|
+
asset_momentum: signals.normalizeTanh(momScore)
|
|
128
90
|
}
|
|
129
91
|
};
|
|
130
92
|
}
|
|
131
93
|
}
|
|
132
|
-
|
|
133
94
|
this.result = result;
|
|
134
95
|
}
|
|
135
|
-
// --- END FIX ---
|
|
136
|
-
|
|
137
|
-
async getResult(fetchedDependencies) {
|
|
138
|
-
return this.result;
|
|
139
|
-
}
|
|
140
96
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
97
|
+
async getResult() { return this.result; }
|
|
98
|
+
reset() { this.result = {}; }
|
|
144
99
|
}
|
|
145
100
|
module.exports = VolatilitySignal;
|