@cranberry-money/shared-utils 1.0.1 → 3.0.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/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@
3
3
  */
4
4
  export * from './formatters';
5
5
  export * from './helpers';
6
+ export * from './portfolio';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -3,3 +3,4 @@
3
3
  */
4
4
  export * from './formatters';
5
5
  export * from './helpers';
6
+ export * from './portfolio';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Portfolio utility functions
3
+ * Calculations and processing for portfolio data
4
+ */
5
+ import type { PortfolioServices } from '@cranberry-money/shared-services';
6
+ /**
7
+ * Calculate the actual percentage allocations based on holdings
8
+ * Returns a map of instrument UUID to percentage
9
+ */
10
+ export declare const calculateHoldingAllocations: (holdings: PortfolioServices.AssetHolding[]) => Record<string, number>;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/portfolio/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,iBAAiB,CAAC,YAAY,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAwB7G,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Portfolio utility functions
3
+ * Calculations and processing for portfolio data
4
+ */
5
+ /**
6
+ * Calculate the actual percentage allocations based on holdings
7
+ * Returns a map of instrument UUID to percentage
8
+ */
9
+ export const calculateHoldingAllocations = (holdings) => {
10
+ // Calculate total portfolio value
11
+ const totalValue = holdings.reduce((sum, holding) => {
12
+ const price = parseFloat(holding.instrument.currentPrice || '0');
13
+ const value = holding.quantity * price;
14
+ return sum + value;
15
+ }, 0);
16
+ // If no value, return empty allocations
17
+ if (totalValue === 0) {
18
+ return {};
19
+ }
20
+ // Calculate percentage for each holding
21
+ const allocations = {};
22
+ holdings.forEach((holding) => {
23
+ const price = parseFloat(holding.instrument.currentPrice || '0');
24
+ const value = holding.quantity * price;
25
+ const percentage = (value / totalValue) * 100;
26
+ allocations[holding.instrument.uuid] = percentage;
27
+ });
28
+ return allocations;
29
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cranberry-money/shared-utils",
3
- "version": "1.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Shared utility functions for MyPortfolio platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,8 @@
21
21
  "dev": "tsc --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@cranberry-money/shared-constants": "^1.0.1"
24
+ "@cranberry-money/shared-constants": "^3.0.0",
25
+ "@cranberry-money/shared-services": "^3.0.0"
25
26
  },
26
27
  "devDependencies": {
27
28
  "typescript": "^5.0.0"