aiden-shared-calculations-unified 1.0.147 → 1.0.148
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,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Aggregate Sector Ranking by AUM.
|
|
3
|
-
* Returns the ranked order of sectors invested in each day across all users (based on AUM).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
class AggregateSectorRanking {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.results = {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getMetadata() {
|
|
12
|
-
return {
|
|
13
|
-
type: 'meta',
|
|
14
|
-
category: 'popular_investor',
|
|
15
|
-
userType: 'POPULAR_INVESTOR',
|
|
16
|
-
// [FIX] Enforce strict availability check.
|
|
17
|
-
rootDataDependencies: ['portfolio']
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static getDependencies() { return ['UserAUMPerAsset']; }
|
|
22
|
-
|
|
23
|
-
static getSchema() {
|
|
24
|
-
return {
|
|
25
|
-
type: 'array',
|
|
26
|
-
items: {
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
sector: { type: 'string' },
|
|
30
|
-
aum: { type: 'number' },
|
|
31
|
-
rank: { type: 'number' }
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
description: 'Ranked list of sectors by total AUM invested'
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
process(context) {
|
|
39
|
-
const aumPerAssetData = context.computed['UserAUMPerAsset'];
|
|
40
|
-
const mappings = context.mappings;
|
|
41
|
-
|
|
42
|
-
if (!aumPerAssetData || !mappings?.instrumentToSector) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Aggregate AUM per sector across all users
|
|
47
|
-
const sectorAUM = new Map();
|
|
48
|
-
|
|
49
|
-
for (const [userId, userAssets] of Object.entries(aumPerAssetData)) {
|
|
50
|
-
if (!userAssets || typeof userAssets !== 'object') continue;
|
|
51
|
-
|
|
52
|
-
for (const [instrumentIdStr, aum] of Object.entries(userAssets)) {
|
|
53
|
-
const instrumentId = Number(instrumentIdStr);
|
|
54
|
-
|
|
55
|
-
// Validate inputs
|
|
56
|
-
if (isNaN(instrumentId) || typeof aum !== 'number') continue;
|
|
57
|
-
|
|
58
|
-
// Map instrument to sector using system mappings
|
|
59
|
-
const sector = mappings.instrumentToSector[instrumentId] || 'Unknown';
|
|
60
|
-
|
|
61
|
-
// Add AUM to sector total
|
|
62
|
-
const current = sectorAUM.get(sector) || 0;
|
|
63
|
-
sectorAUM.set(sector, current + aum);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Convert to array, sort by AUM descending, and assign rank
|
|
68
|
-
const ranked = Array.from(sectorAUM.entries())
|
|
69
|
-
.map(([sector, aum]) => ({
|
|
70
|
-
sector,
|
|
71
|
-
aum: Number(aum.toFixed(2))
|
|
72
|
-
}))
|
|
73
|
-
.sort((a, b) => b.aum - a.aum)
|
|
74
|
-
.map((item, index) => ({
|
|
75
|
-
...item,
|
|
76
|
-
rank: index + 1
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
return ranked;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async getResult() {
|
|
83
|
-
return this.results;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.exports = AggregateSectorRanking;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Aggregate Stock Ranking by AUM.
|
|
3
|
-
* Returns the ranked order of most invested in stocks each day across all users (based on AUM).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
class AggregateStockRanking {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.results = {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getMetadata() {
|
|
12
|
-
return {
|
|
13
|
-
type: 'meta',
|
|
14
|
-
category: 'popular_investor',
|
|
15
|
-
userType: 'POPULAR_INVESTOR',
|
|
16
|
-
// [FIX] Enforce strict availability check.
|
|
17
|
-
rootDataDependencies: ['portfolio']
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static getDependencies() { return ['UserAUMPerAsset']; }
|
|
22
|
-
|
|
23
|
-
static getSchema() {
|
|
24
|
-
return {
|
|
25
|
-
type: 'array',
|
|
26
|
-
items: {
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
instrumentId: { type: 'number' },
|
|
30
|
-
ticker: { type: 'string' },
|
|
31
|
-
aum: { type: 'number' },
|
|
32
|
-
rank: { type: 'number' }
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
description: 'Ranked list of stocks by total AUM invested'
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
process(context) {
|
|
40
|
-
const aumPerAssetData = context.computed['UserAUMPerAsset'];
|
|
41
|
-
const mappings = context.mappings;
|
|
42
|
-
|
|
43
|
-
if (!aumPerAssetData) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Aggregate AUM per instrument across all users
|
|
48
|
-
const instrumentAUM = new Map();
|
|
49
|
-
|
|
50
|
-
for (const [userId, userAssets] of Object.entries(aumPerAssetData)) {
|
|
51
|
-
if (!userAssets || typeof userAssets !== 'object') continue;
|
|
52
|
-
|
|
53
|
-
for (const [instrumentIdStr, aum] of Object.entries(userAssets)) {
|
|
54
|
-
const instrumentId = Number(instrumentIdStr);
|
|
55
|
-
|
|
56
|
-
// Validate inputs
|
|
57
|
-
if (isNaN(instrumentId) || typeof aum !== 'number') continue;
|
|
58
|
-
|
|
59
|
-
const current = instrumentAUM.get(instrumentId) || 0;
|
|
60
|
-
instrumentAUM.set(instrumentId, current + aum);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Convert to array, add ticker, sort, and rank
|
|
65
|
-
const ranked = Array.from(instrumentAUM.entries())
|
|
66
|
-
.map(([instrumentId, aum]) => {
|
|
67
|
-
const ticker = mappings?.instrumentToTicker?.[instrumentId] || `ID${instrumentId}`;
|
|
68
|
-
return {
|
|
69
|
-
instrumentId,
|
|
70
|
-
ticker,
|
|
71
|
-
aum: Number(aum.toFixed(2))
|
|
72
|
-
};
|
|
73
|
-
})
|
|
74
|
-
.sort((a, b) => b.aum - a.aum)
|
|
75
|
-
.map((item, index) => ({
|
|
76
|
-
...item,
|
|
77
|
-
rank: index + 1
|
|
78
|
-
}));
|
|
79
|
-
|
|
80
|
-
return ranked;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async getResult() {
|
|
84
|
-
return this.results;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = AggregateStockRanking;
|