@sachfolio/cas-reader 0.0.0-stage → 0.2.0-beta.1
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/CHANGELOG.md +19 -0
- package/LICENSE +71 -0
- package/NOTICE +41 -0
- package/README.md +198 -2
- package/dist/analytics/contract.d.ts +110 -0
- package/dist/analytics/contract.js +79 -0
- package/dist/analytics/eligibility.d.ts +66 -0
- package/dist/analytics/eligibility.js +93 -0
- package/dist/analytics/gains-schema.d.ts +898 -0
- package/dist/analytics/gains-schema.js +170 -0
- package/dist/analytics/gains.d.ts +319 -0
- package/dist/analytics/gains.js +649 -0
- package/dist/analytics/modules.d.ts +33 -0
- package/dist/analytics/modules.js +74 -0
- package/dist/analytics/returns-schema.d.ts +931 -0
- package/dist/analytics/returns-schema.js +152 -0
- package/dist/analytics/returns.d.ts +126 -0
- package/dist/analytics/returns.js +453 -0
- package/dist/analytics/schedule112a.d.ts +77 -0
- package/dist/analytics/schedule112a.js +134 -0
- package/dist/analytics/xirr.d.ts +75 -0
- package/dist/analytics/xirr.js +314 -0
- package/dist/bin/cas.d.ts +2 -0
- package/dist/bin/cas.js +137 -0
- package/dist/checks.d.ts +49 -0
- package/dist/checks.js +227 -0
- package/dist/compat/casparser.d.ts +121 -0
- package/dist/compat/casparser.js +193 -0
- package/dist/detect.d.ts +10 -0
- package/dist/detect.js +69 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +95 -0
- package/dist/export/csv.d.ts +21 -0
- package/dist/export/csv.js +49 -0
- package/dist/extract/browser.d.ts +17 -0
- package/dist/extract/browser.js +34 -0
- package/dist/extract/budget.d.ts +46 -0
- package/dist/extract/budget.js +88 -0
- package/dist/extract/node.d.ts +11 -0
- package/dist/extract/node.js +31 -0
- package/dist/extract/pdfjs.d.ts +71 -0
- package/dist/extract/pdfjs.js +244 -0
- package/dist/extract/types.d.ts +106 -0
- package/dist/extract/types.js +11 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/layout/lines.d.ts +51 -0
- package/dist/layout/lines.js +115 -0
- package/dist/licence/app-licence.d.ts +53 -0
- package/dist/licence/app-licence.js +139 -0
- package/dist/licence/ed25519.d.ts +2 -0
- package/dist/licence/ed25519.js +103 -0
- package/dist/model.d.ts +148 -0
- package/dist/model.js +1 -0
- package/dist/num.d.ts +19 -0
- package/dist/num.js +27 -0
- package/dist/parse.d.ts +4 -0
- package/dist/parse.js +13 -0
- package/dist/parsers/cams/classify.d.ts +25 -0
- package/dist/parsers/cams/classify.js +103 -0
- package/dist/parsers/cams/detailed.d.ts +15 -0
- package/dist/parsers/cams/detailed.js +343 -0
- package/dist/parsers/cams/header.d.ts +47 -0
- package/dist/parsers/cams/header.js +170 -0
- package/dist/parsers/cams/investor.d.ts +28 -0
- package/dist/parsers/cams/investor.js +139 -0
- package/dist/parsers/cams/summary.d.ts +29 -0
- package/dist/parsers/cams/summary.js +413 -0
- package/dist/parsers/cams/table.d.ts +55 -0
- package/dist/parsers/cams/table.js +144 -0
- package/dist/parsers/cams/total.d.ts +17 -0
- package/dist/parsers/cams/total.js +105 -0
- package/dist/parsers/depository/mf.d.ts +22 -0
- package/dist/parsers/depository/mf.js +438 -0
- package/dist/privacy.d.ts +243 -0
- package/dist/privacy.js +256 -0
- package/dist/schema.d.ts +779 -0
- package/dist/schema.js +214 -0
- package/examples/nextjs/app/page.jsx +34 -0
- package/examples/node/server.mjs +45 -0
- package/examples/python/read_cas.py +67 -0
- package/examples/vite/index.html +14 -0
- package/examples/vite/main.js +22 -0
- package/package.json +54 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { big } from "../num.js";
|
|
2
|
+
import { checkWhy } from "./contract.js";
|
|
3
|
+
import { moduleReports } from "./modules.js";
|
|
4
|
+
import { returns, schemeReturnsEligibility } from "./returns.js";
|
|
5
|
+
/** "2": adds `modules` (the analysis contract) and `returns` (xirr@1). Everything in "1" is unchanged. */
|
|
6
|
+
export const ANALYTICS_VERSION = "2";
|
|
7
|
+
const OUTFLOW_TYPES = new Set(["REDEMPTION", "SWP", "SWITCH_OUT", "PLEDGE_INVOKED"]);
|
|
8
|
+
const statusOf = (s, id) => s.checks.find((c) => c.id === id)?.status ?? "missing";
|
|
9
|
+
const why = checkWhy;
|
|
10
|
+
export function holdingsEligibility(s, variant) {
|
|
11
|
+
const reasons = [];
|
|
12
|
+
const valuation = statusOf(s, "valuation.units_x_nav");
|
|
13
|
+
if (valuation !== "pass")
|
|
14
|
+
reasons.push(why("valuation.units_x_nav", valuation));
|
|
15
|
+
// A summary or depository statement prints no ledger; its valuation identity is the check (docs/SPEC-metrics.md).
|
|
16
|
+
if (variant === "DETAILED") {
|
|
17
|
+
const ledger = statusOf(s, "ledger.units");
|
|
18
|
+
if (ledger !== "pass")
|
|
19
|
+
reasons.push(why("ledger.units", ledger));
|
|
20
|
+
}
|
|
21
|
+
return { eligible: reasons.length === 0, reasons };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Scheme XIRR eligibility in the M2 shape. Since M4 it is xirr@1's own
|
|
25
|
+
* eligibility (analytics/returns.ts), so the two can never disagree: the
|
|
26
|
+
* checks it requires, kinds of rows it can't model (pledged units, unknown
|
|
27
|
+
* wording, gifts out, transfers out, mergers out), and cash rows whose
|
|
28
|
+
* meaning the statement's figures don't settle.
|
|
29
|
+
*/
|
|
30
|
+
export function schemeXirrEligibility(s, variant, folio) {
|
|
31
|
+
const f = folio ?? { folio: "", amc: "", pan: null, kyc: null, panKyc: null, holderName: null, schemes: [s] };
|
|
32
|
+
const e = schemeReturnsEligibility(f, s, variant);
|
|
33
|
+
return { eligible: e.state === "eligible", reasons: e.reasons.map((r) => r.text) };
|
|
34
|
+
}
|
|
35
|
+
export function outflowBreakdowns(s) {
|
|
36
|
+
const sumOn = (date, type) => s.transactions.filter((t) => t.date === date && t.type === type && t.amount).reduce((acc, t) => acc.plus(big(t.amount).abs()), big(0));
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const t of s.transactions) {
|
|
39
|
+
if (!OUTFLOW_TYPES.has(t.type) || !t.amount || !t.units || !t.price || t.price.raw === "derived")
|
|
40
|
+
continue;
|
|
41
|
+
const gross = big(t.units).abs().times(big(t.price));
|
|
42
|
+
const net = big(t.amount).abs();
|
|
43
|
+
const deducted = gross.minus(net);
|
|
44
|
+
const stt = sumOn(t.date, "STT_TAX");
|
|
45
|
+
const tds = sumOn(t.date, "TDS_TAX");
|
|
46
|
+
out.push({
|
|
47
|
+
order: t.order, date: t.date, type: t.type, source: t.source,
|
|
48
|
+
gross: gross.toFixed(2), net: net.toFixed(2), deducted: deducted.toFixed(2),
|
|
49
|
+
stt: stt.toFixed(2), tds: tds.toFixed(2), unexplained: deducted.minus(stt).minus(tds).toFixed(2),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
export function analyze(cas) {
|
|
55
|
+
const variant = cas.source.variant;
|
|
56
|
+
const xirr = returns(cas);
|
|
57
|
+
const schemes = cas.folios.flatMap((f) => f.schemes.map((s) => ({
|
|
58
|
+
folio: f.folio, rtaCode: s.rtaCode, name: s.name,
|
|
59
|
+
holdings: holdingsEligibility(s, variant),
|
|
60
|
+
schemeXirr: { eligible: false, reasons: [] },
|
|
61
|
+
outflows: outflowBreakdowns(s),
|
|
62
|
+
})));
|
|
63
|
+
// xirr@1 lists schemes in the same document order.
|
|
64
|
+
schemes.forEach((s, i) => {
|
|
65
|
+
const e = xirr.schemes[i].eligibility;
|
|
66
|
+
s.schemeXirr = { eligible: e.state === "eligible", reasons: e.reasons.map((r) => r.text) };
|
|
67
|
+
});
|
|
68
|
+
const all = cas.folios.flatMap((f) => f.schemes);
|
|
69
|
+
const dates = new Map();
|
|
70
|
+
for (const s of all)
|
|
71
|
+
if (s.valuation)
|
|
72
|
+
dates.set(s.valuation.date, (dates.get(s.valuation.date) ?? 0) + 1);
|
|
73
|
+
const valuationDate = [...dates].sort((a, b) => b[1] - a[1] || b[0].localeCompare(a[0]))[0]?.[0] ?? null;
|
|
74
|
+
const offDateSchemes = all.filter((s) => s.valuation && s.valuation.date !== valuationDate).length;
|
|
75
|
+
const included = schemes.filter((s) => s.holdings.eligible).length;
|
|
76
|
+
const excluded = schemes.length - included;
|
|
77
|
+
const holdingReasons = [];
|
|
78
|
+
if (included === 0)
|
|
79
|
+
holdingReasons.push("No scheme's value could be checked");
|
|
80
|
+
if (excluded > 0 && included > 0)
|
|
81
|
+
holdingReasons.push(`${excluded} scheme(s) couldn't be checked and are left out of totals`);
|
|
82
|
+
if (offDateSchemes)
|
|
83
|
+
holdingReasons.push(`${offDateSchemes} scheme(s) are valued on a different date`);
|
|
84
|
+
const pe = xirr.portfolio.eligibility;
|
|
85
|
+
const portfolioXirr = { eligible: pe.state === "eligible", reasons: pe.reasons.map((r) => r.text) };
|
|
86
|
+
return {
|
|
87
|
+
analyticsVersion: ANALYTICS_VERSION,
|
|
88
|
+
schemes,
|
|
89
|
+
portfolio: { holdings: { eligible: included > 0, reasons: holdingReasons, included, excluded }, portfolioXirr, valuationDate, offDateSchemes },
|
|
90
|
+
modules: moduleReports(cas),
|
|
91
|
+
returns: xirr,
|
|
92
|
+
};
|
|
93
|
+
}
|