@marcfargas/skills 0.3.0 → 0.4.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/package.json +6 -1
- package/sheet-model/SKILL.md +420 -0
- package/sheet-model/lib/sheet-model.mjs +510 -0
- package/sheet-model/package-lock.json +1035 -0
- package/sheet-model/package.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcfargas/skills",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Reusable AI agent skills for pi, Claude Code, Cursor, and any Agent Skills compatible agent",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Fargas <marc@marcfargas.com>",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"agent-skills",
|
|
14
14
|
"ai-agent",
|
|
15
15
|
"skills",
|
|
16
|
+
"azcli",
|
|
16
17
|
"gcloud",
|
|
17
18
|
"pm2",
|
|
18
19
|
"pre-release",
|
|
@@ -21,10 +22,12 @@
|
|
|
21
22
|
],
|
|
22
23
|
"pi": {
|
|
23
24
|
"skills": [
|
|
25
|
+
"azure",
|
|
24
26
|
"google-cloud",
|
|
25
27
|
"process",
|
|
26
28
|
"release",
|
|
27
29
|
"search",
|
|
30
|
+
"sheet-model",
|
|
28
31
|
"terminal"
|
|
29
32
|
]
|
|
30
33
|
},
|
|
@@ -38,10 +41,12 @@
|
|
|
38
41
|
"@changesets/cli": "^2.29.8"
|
|
39
42
|
},
|
|
40
43
|
"files": [
|
|
44
|
+
"azure/",
|
|
41
45
|
"google-cloud/",
|
|
42
46
|
"process/",
|
|
43
47
|
"release/",
|
|
44
48
|
"search/",
|
|
49
|
+
"sheet-model/",
|
|
45
50
|
"terminal/",
|
|
46
51
|
"README.md",
|
|
47
52
|
"LICENSE",
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sheet-model
|
|
3
|
+
description: "Headless spreadsheet engine for financial modeling, data analysis, and scenario comparison. Use when: building financial models with ratios and what-if scenarios, computing derived values from tabular data with formulas, producing .xlsx files with live formulas (not static values) for human review, any task where the agent would otherwise write imperative code to manipulate numbers that a spreadsheet does naturally. Triggers: financial model, scenario analysis, ratio computation, balance sheet, P&L, what-if, sensitivity analysis, banking ratios, spreadsheet model, build a model, projection, forecast. Do NOT use for: simple CSV/Excel read/write (use the xlsx skill), chart-only tasks, or data volumes exceeding ~5000 rows."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Sheet Model — Headless Spreadsheet for Agents
|
|
7
|
+
|
|
8
|
+
Build spreadsheet models programmatically using HyperFormula (headless computation engine) + ExcelJS (xlsx export). The spreadsheet IS both the computation and the deliverable.
|
|
9
|
+
|
|
10
|
+
## When to Use This vs the `xlsx` Skill
|
|
11
|
+
|
|
12
|
+
| Task | Use |
|
|
13
|
+
|------|-----|
|
|
14
|
+
| Read/write/edit existing .xlsx files | `xlsx` skill |
|
|
15
|
+
| Clean messy CSV data into a spreadsheet | `xlsx` skill |
|
|
16
|
+
| Build a financial model with formulas and scenarios | **this skill** |
|
|
17
|
+
| Produce a .xlsx where formulas are live and editable | **this skill** |
|
|
18
|
+
| Compute ratios, projections, what-if analysis | **this skill** |
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
Install dependencies (run once):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
cd {baseDir}
|
|
26
|
+
npm install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Architecture
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
Agent code (declarative) SheetModel wrapper Output
|
|
33
|
+
──────────────────────── ────────────────────────── ──────────────
|
|
34
|
+
addRow('Revenue', 701384) → HyperFormula (compute) → Console table
|
|
35
|
+
addRow('EBITDA', formula) → Named ranges auto-tracked → .xlsx with live
|
|
36
|
+
addScenarioSheet(config) → {Name} refs resolved → formulas +
|
|
37
|
+
getValue('EBITDA') → Dependency graph updates → styling +
|
|
38
|
+
exportXlsx('model.xlsx') → ExcelJS (export) → cond. format
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Core API
|
|
42
|
+
|
|
43
|
+
All code is ESM (`.mjs`). Import the wrapper:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
import { SheetModel } from '{baseDir}/lib/sheet-model.mjs';
|
|
47
|
+
const M = new SheetModel();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Creating Sheets and Adding Data
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
M.addSheet('Data');
|
|
54
|
+
|
|
55
|
+
// Section headers (bold, no value)
|
|
56
|
+
M.addSection('Data', 'BALANCE SHEET');
|
|
57
|
+
M.addBlank('Data');
|
|
58
|
+
|
|
59
|
+
// Data rows — addRow returns the A1 row number (use it in SUM ranges)
|
|
60
|
+
const r_first = M.addRow('Data', ' Revenue', 701384, { name: 'Revenue' });
|
|
61
|
+
const r_costs = M.addRow('Data', ' Costs', -450000, { name: 'Costs' });
|
|
62
|
+
const r_other = M.addRow('Data', ' Other', 5000);
|
|
63
|
+
|
|
64
|
+
// Formula rows — use returned row numbers for SUM ranges
|
|
65
|
+
M.addRow('Data', ' EBITDA', `=SUM(B${r_first}:B${r_other})`, { name: 'EBITDA' });
|
|
66
|
+
|
|
67
|
+
// Formula rows using named references (auto-resolved by HyperFormula)
|
|
68
|
+
M.addRow('Data', ' Margin', '=EBITDA/Revenue', { name: 'Margin' });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
> **Build top-to-bottom**: Names must be defined before any formula that references them. Define data rows first, then formulas.
|
|
72
|
+
|
|
73
|
+
> `addBlank()` and `addSection()` also return the A1 row number (useful for SUM range boundaries).
|
|
74
|
+
|
|
75
|
+
**When to use which formula style:**
|
|
76
|
+
|
|
77
|
+
| Need | Use | Why |
|
|
78
|
+
|------|-----|-----|
|
|
79
|
+
| `SUM`, `AVERAGE` over a range of rows | Row numbers: `` `=SUM(B${r_first}:B${r_last})` `` | Ranges need cell references; named expressions resolve to single cells |
|
|
80
|
+
| Arithmetic between specific cells | Named expressions: `'=EBITDA/Revenue'` | Cleaner, self-documenting |
|
|
81
|
+
| Mixed | Both: `` `=SUM(B${r1}:B${r5}) + Revenue` `` | Combine as needed |
|
|
82
|
+
|
|
83
|
+
**Never use named expressions as range endpoints**: `=SUM(Revenue:OtherIncome)` is undefined behavior.
|
|
84
|
+
|
|
85
|
+
### Named References
|
|
86
|
+
|
|
87
|
+
The `{ name: 'Revenue' }` option on `addRow`:
|
|
88
|
+
1. Registers a HyperFormula named expression (usable in any formula as `Revenue`)
|
|
89
|
+
2. Tracks the A1 row for internal cross-referencing
|
|
90
|
+
3. Exports as a proper Excel named range in .xlsx (via `cell.names`)
|
|
91
|
+
|
|
92
|
+
> ⚠️ **Names are global** across all sheets. Using `{ name: 'Revenue' }` in two different sheets overwrites the first. Use unique, prefixed names for multi-sheet models: `{ name: 'Rev2024' }`, `{ name: 'Rev2025' }`.
|
|
93
|
+
|
|
94
|
+
Name validation rules:
|
|
95
|
+
- Must be valid Excel names: start with a letter or underscore, no spaces
|
|
96
|
+
- **Cannot collide with Excel cell references**: names like `AC`, `PC`, `R1C1`, `A1` are rejected with a clear error
|
|
97
|
+
- Use descriptive names: `AdjPC`, `TotalAC`, `CurrentAssets` (not `AC`, `PC`, `CA`)
|
|
98
|
+
|
|
99
|
+
#### Cross-Sheet References (Data Sheets Only)
|
|
100
|
+
|
|
101
|
+
In `addRow` formulas, reference named cells on other data sheets with dot notation:
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
M.addRow('CashFlow', ' From Operations', '={PnL.NetIncome} + {PnL.Depreciation}');
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
> This `{Sheet.Name}` syntax only works in `addRow` formulas, NOT in scenario output formulas. For scenarios, use named expressions (bare names) — they are global across sheets.
|
|
108
|
+
|
|
109
|
+
### Scenario Sheets
|
|
110
|
+
|
|
111
|
+
The core feature — define inputs, scenarios, and output formulas declaratively:
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
M.addScenarioSheet('Scenarios', {
|
|
115
|
+
inputs: [
|
|
116
|
+
{ name: 'GrowthRate', label: 'Revenue Growth %' },
|
|
117
|
+
{ name: 'CostCut', label: 'Cost Reduction' },
|
|
118
|
+
],
|
|
119
|
+
|
|
120
|
+
scenarios: [
|
|
121
|
+
{ label: 'Base Case', values: {} }, // all inputs = 0
|
|
122
|
+
{ label: 'Optimistic', values: { GrowthRate: 0.10, CostCut: 50000 } },
|
|
123
|
+
{ label: 'Conservative', values: { GrowthRate: 0.03, CostCut: 20000 } },
|
|
124
|
+
],
|
|
125
|
+
|
|
126
|
+
outputs: [
|
|
127
|
+
// {InputName} → column-relative (B2, C2, D2...)
|
|
128
|
+
// DataSheetName → named expression from Data sheet (fixed)
|
|
129
|
+
// {PriorOutput} → column-relative ref to earlier output in this sheet
|
|
130
|
+
{ name: 'AdjRev', label: 'Adj. Revenue', format: 'number',
|
|
131
|
+
formula: 'Revenue * (1 + {GrowthRate})' },
|
|
132
|
+
{ name: 'AdjCost', label: 'Adj. Costs', format: 'number',
|
|
133
|
+
formula: 'Costs + {CostCut}' },
|
|
134
|
+
{ name: 'AdjEBITDA', label: 'EBITDA', format: 'number',
|
|
135
|
+
formula: '{AdjRev} + {AdjCost}' },
|
|
136
|
+
|
|
137
|
+
// Section separator
|
|
138
|
+
{ section: true, label: 'RATIOS' },
|
|
139
|
+
|
|
140
|
+
// Ratio with conditional formatting thresholds
|
|
141
|
+
{ name: 'EBITDAm', label: 'EBITDA Margin', format: 'percent',
|
|
142
|
+
formula: '{AdjEBITDA} / {AdjRev}',
|
|
143
|
+
thresholds: { good: 0.15, bad: 0.08 } },
|
|
144
|
+
|
|
145
|
+
// Inverted threshold (lower = better)
|
|
146
|
+
{ name: 'DebtEBITDA', label: 'Debt/EBITDA', format: 'ratio',
|
|
147
|
+
formula: 'TotalDebt / {AdjEBITDA}',
|
|
148
|
+
thresholds: { good: 2.5, bad: 4.0, invert: true } },
|
|
149
|
+
],
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
> **Do NOT call `addSheet()` before `addScenarioSheet()`** — it creates the sheet internally. Only use `addSheet()` for data sheets.
|
|
154
|
+
|
|
155
|
+
> **`addScenarioSheet` is a one-shot call.** You cannot add rows to a scenario sheet after creation. Include all inputs, outputs, and sections in the config object.
|
|
156
|
+
|
|
157
|
+
> **Every output you want to reference later MUST have a `name` property.** Without it, `{ThatOutput}` in a subsequent formula will throw an error.
|
|
158
|
+
|
|
159
|
+
#### Formula Reference Resolution in Scenarios
|
|
160
|
+
|
|
161
|
+
Inside `outputs[].formula`, references are resolved as follows:
|
|
162
|
+
|
|
163
|
+
| Syntax | Resolves to | Example |
|
|
164
|
+
|--------|-------------|---------|
|
|
165
|
+
| `{InputName}` | Column-relative cell ref to scenario input row | `{GrowthRate}` → `B2`, `C2`, `D2`... |
|
|
166
|
+
| `{OutputName}` | Column-relative cell ref to prior output in same sheet | `{AdjRev}` → `B7`, `C7`, `D7`... |
|
|
167
|
+
| `NamedExpr` | HyperFormula named expression (global, from any sheet) | `Revenue` → the named cell (fixed) |
|
|
168
|
+
|
|
169
|
+
**Important**: Bare names (no `{}`) are HyperFormula named expressions — they resolve to a **fixed** cell. `{Wrapped}` names resolve to **column-relative** cells within the Scenarios sheet.
|
|
170
|
+
|
|
171
|
+
> ⚠️ **Name collision rule**: If a scenario output `{name}` matches a Data sheet named expression, `{OutputName}` will resolve to the **Data sheet's fixed cell**, not the scenario output's column-relative cell. Always use **unique names** for scenario outputs. Example: Data sheet has `{ name: 'EBITDA' }`, scenario should use `{ name: 'AdjEBITDA' }` — never both `EBITDA`.
|
|
172
|
+
|
|
173
|
+
#### Output Formats
|
|
174
|
+
|
|
175
|
+
| Format | Excel numFmt | Display |
|
|
176
|
+
|--------|-------------|---------|
|
|
177
|
+
| `'number'` | `#,##0` | `1,234` |
|
|
178
|
+
| `'percent'` | `0.0%` | `12.5%` |
|
|
179
|
+
| `'ratio'` | `0.00"x"` | `3.14x` |
|
|
180
|
+
| `'decimal'` | `#,##0.00` | `1,234.56` |
|
|
181
|
+
|
|
182
|
+
#### Thresholds (Conditional Formatting)
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
thresholds: { good: 0.15, bad: 0.08 } // Higher is better (green >= 0.15, red < 0.08)
|
|
186
|
+
thresholds: { good: 2.5, bad: 4.0, invert: true } // Lower is better (green <= 2.5, red > 4.0)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Colors: green (#E2EFDA), amber (#FFF2CC), red (#FCE4EC).
|
|
190
|
+
|
|
191
|
+
### Reading Computed Values
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
// From Data sheet (by named ref)
|
|
195
|
+
const ebitda = M.getValue('Data', 'EBITDA');
|
|
196
|
+
|
|
197
|
+
// From Scenarios (by scenario index, 0-based)
|
|
198
|
+
const baseEBITDA = M.getScenarioValue('Scenarios', 0, 'AdjEBITDA');
|
|
199
|
+
const optEBITDA = M.getScenarioValue('Scenarios', 1, 'AdjEBITDA');
|
|
200
|
+
|
|
201
|
+
// Raw cell access (sheet, col 0-indexed, a1Row 1-indexed)
|
|
202
|
+
const val = M.getCellValue('Data', 1, 5); // col B, row 5
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
> Use `getValue()` for data sheets, `getScenarioValue()` for scenario sheets. `getValue()` on a scenario sheet returns the first scenario's value (column B).
|
|
206
|
+
|
|
207
|
+
### Error Handling
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
// Formula errors (division by zero, etc.) return CellError objects, not exceptions
|
|
211
|
+
const val = M.getValue('Data', 'Margin');
|
|
212
|
+
if (typeof val !== 'number' || !isFinite(val)) {
|
|
213
|
+
console.error('Formula error:', val);
|
|
214
|
+
// val might be: { type: 'DIV_BY_ZERO' }, { type: 'REF' }, { type: 'NAME' }, etc.
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// To prevent #DIV/0! in formulas, guard with IF:
|
|
218
|
+
M.addRow('Data', ' Margin', '=IF(Revenue=0, 0, EBITDA/Revenue)', { name: 'Margin' });
|
|
219
|
+
|
|
220
|
+
// Reference errors throw immediately during addRow/addScenarioSheet
|
|
221
|
+
// → Always define named rows BEFORE formulas that reference them
|
|
222
|
+
// → Error messages include the row label and cell reference for easy debugging
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Common causes of formula errors:
|
|
226
|
+
- Division by zero in ratios → guard with `IF(denominator=0, 0, numerator/denominator)`
|
|
227
|
+
- Misspelled named expression → throws immediately with clear error message
|
|
228
|
+
- Circular reference → throws immediately with row context
|
|
229
|
+
|
|
230
|
+
### Console Output
|
|
231
|
+
|
|
232
|
+
```javascript
|
|
233
|
+
M.printScenarios('Scenarios');
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Prints a formatted table with emoji flags for threshold-based RAG status (🟢🟡🔴).
|
|
237
|
+
|
|
238
|
+
### Export to .xlsx
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
await M.exportXlsx('output.xlsx', {
|
|
242
|
+
creator: 'Agent Name',
|
|
243
|
+
headerColor: '1B3A5C', // Dark blue header background (ARGB hex, no #)
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The exported file contains:
|
|
248
|
+
- **Live formulas** (not static values) — user can change inputs and see results update
|
|
249
|
+
- **Named ranges** on all named cells (visible in Excel's Name Manager)
|
|
250
|
+
- **Conditional formatting** on cells with thresholds (green/amber/red)
|
|
251
|
+
- **Frozen panes** — first column frozen on all sheets; header row also frozen on scenario sheets
|
|
252
|
+
- **Input cells** highlighted in light blue (#DAEEF3)
|
|
253
|
+
- **Section headers** in bold
|
|
254
|
+
|
|
255
|
+
> **Named ranges on scenario sheets** point to the **first scenario column** (column B). They exist for cross-sheet references in Excel, not for selecting all scenarios.
|
|
256
|
+
|
|
257
|
+
### Advanced Styling
|
|
258
|
+
|
|
259
|
+
For styling beyond what SheetModel provides, modify the file after export with ExcelJS:
|
|
260
|
+
|
|
261
|
+
```javascript
|
|
262
|
+
import { createRequire } from 'module';
|
|
263
|
+
const require = createRequire(import.meta.url);
|
|
264
|
+
const ExcelJS = require('exceljs');
|
|
265
|
+
|
|
266
|
+
await M.exportXlsx('model.xlsx');
|
|
267
|
+
|
|
268
|
+
const wb = new ExcelJS.Workbook();
|
|
269
|
+
await wb.xlsx.readFile('model.xlsx');
|
|
270
|
+
const ws = wb.getWorksheet('Data');
|
|
271
|
+
// Custom column widths, borders, fills, page setup, etc.
|
|
272
|
+
ws.pageSetup = { orientation: 'landscape', fitToPage: true, fitToWidth: 1 };
|
|
273
|
+
ws.getColumn(2).numFmt = '$#,##0';
|
|
274
|
+
await wb.xlsx.writeFile('model.xlsx');
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Complete Example: Financial Model with Scenarios
|
|
278
|
+
|
|
279
|
+
```javascript
|
|
280
|
+
import { SheetModel } from '{baseDir}/lib/sheet-model.mjs';
|
|
281
|
+
|
|
282
|
+
const M = new SheetModel();
|
|
283
|
+
M.addSheet('Data');
|
|
284
|
+
|
|
285
|
+
// ── Balance Sheet ──
|
|
286
|
+
M.addSection('Data', 'BALANCE SHEET');
|
|
287
|
+
M.addBlank('Data');
|
|
288
|
+
const r1 = M.addRow('Data', ' Cash', 50000, { name: 'Cash' });
|
|
289
|
+
const r2 = M.addRow('Data', ' Receivables', 120000, { name: 'Receivables' });
|
|
290
|
+
const r3 = M.addRow('Data', ' Inventory', 30000);
|
|
291
|
+
M.addRow('Data', ' Current Assets', `=SUM(B${r1}:B${r3})`, { name: 'CurrentAssets' });
|
|
292
|
+
|
|
293
|
+
M.addBlank('Data');
|
|
294
|
+
const r4 = M.addRow('Data', ' Payables', 80000, { name: 'Payables' });
|
|
295
|
+
const r5 = M.addRow('Data', ' Short-term Debt', 40000, { name: 'STDebt' });
|
|
296
|
+
M.addRow('Data', ' Current Liabilities', `=SUM(B${r4}:B${r5})`, { name: 'CurrentLiab' });
|
|
297
|
+
|
|
298
|
+
M.addBlank('Data');
|
|
299
|
+
M.addRow('Data', ' Equity', 200000, { name: 'Equity' });
|
|
300
|
+
M.addRow('Data', ' Long-term Debt', 150000, { name: 'LTDebt' });
|
|
301
|
+
|
|
302
|
+
// ── P&L ──
|
|
303
|
+
M.addBlank('Data');
|
|
304
|
+
M.addSection('Data', 'INCOME STATEMENT');
|
|
305
|
+
M.addBlank('Data');
|
|
306
|
+
const p1 = M.addRow('Data', ' Revenue', 500000, { name: 'Revenue' });
|
|
307
|
+
const p2 = M.addRow('Data', ' COGS', -200000);
|
|
308
|
+
const p3 = M.addRow('Data', ' Operating Exp', -150000);
|
|
309
|
+
const p4 = M.addRow('Data', ' Depreciation', -30000, { name: 'Depreciation' });
|
|
310
|
+
M.addRow('Data', ' Operating Income', `=SUM(B${p1}:B${p4})`, { name: 'OpIncome' });
|
|
311
|
+
M.addRow('Data', ' Interest Expense', -15000, { name: 'IntExp' });
|
|
312
|
+
M.addRow('Data', ' Net Income', '=OpIncome+IntExp', { name: 'NetIncome' });
|
|
313
|
+
|
|
314
|
+
// ── Scenarios ──
|
|
315
|
+
M.addScenarioSheet('Analysis', {
|
|
316
|
+
inputs: [
|
|
317
|
+
{ name: 'RevGrowth', label: 'Revenue Growth' },
|
|
318
|
+
{ name: 'DebtPaydown', label: 'Debt Paydown' },
|
|
319
|
+
],
|
|
320
|
+
scenarios: [
|
|
321
|
+
{ label: 'As-Is', values: {} },
|
|
322
|
+
{ label: 'Growth 10%', values: { RevGrowth: 0.10 } },
|
|
323
|
+
{ label: 'Deleverage', values: { RevGrowth: 0.05, DebtPaydown: 50000 } },
|
|
324
|
+
],
|
|
325
|
+
outputs: [
|
|
326
|
+
{ name: 'AdjRev', label: 'Adj. Revenue', format: 'number',
|
|
327
|
+
formula: 'Revenue * (1 + {RevGrowth})' },
|
|
328
|
+
{ name: 'AdjEBITDA', label: 'EBITDA', format: 'number',
|
|
329
|
+
formula: '{AdjRev} + (Revenue - OpIncome + Depreciation) / Revenue * {AdjRev} * -1 + ABS(Depreciation)' },
|
|
330
|
+
{ name: 'TotalDebt', label: 'Total Debt', format: 'number',
|
|
331
|
+
formula: 'LTDebt + STDebt - {DebtPaydown}' },
|
|
332
|
+
{ name: 'NetDebt', label: 'Net Debt', format: 'number',
|
|
333
|
+
formula: '{TotalDebt} - Cash' },
|
|
334
|
+
|
|
335
|
+
{ section: true, label: 'KEY RATIOS' },
|
|
336
|
+
{ name: 'CurrRatio', label: 'Current Ratio', format: 'ratio',
|
|
337
|
+
formula: 'CurrentAssets / CurrentLiab',
|
|
338
|
+
thresholds: { good: 1.5, bad: 1.0 } },
|
|
339
|
+
{ name: 'DebtEBITDA', label: 'Debt/EBITDA', format: 'ratio',
|
|
340
|
+
formula: '{TotalDebt} / {AdjEBITDA}',
|
|
341
|
+
thresholds: { good: 2.5, bad: 4.0, invert: true } },
|
|
342
|
+
{ name: 'ICR', label: 'Interest Coverage', format: 'ratio',
|
|
343
|
+
formula: '{AdjEBITDA} / ABS(IntExp)',
|
|
344
|
+
thresholds: { good: 3.0, bad: 1.5 } },
|
|
345
|
+
{ name: 'EBITDAm', label: 'EBITDA Margin', format: 'percent',
|
|
346
|
+
formula: '{AdjEBITDA} / {AdjRev}',
|
|
347
|
+
thresholds: { good: 0.20, bad: 0.10 } },
|
|
348
|
+
{ name: 'ROE', label: 'Return on Equity', format: 'percent',
|
|
349
|
+
formula: 'NetIncome / Equity',
|
|
350
|
+
thresholds: { good: 0.12, bad: 0.05 } },
|
|
351
|
+
],
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Use
|
|
355
|
+
M.printScenarios('Analysis');
|
|
356
|
+
console.log('EBITDA (Growth):', M.getScenarioValue('Analysis', 1, 'AdjEBITDA'));
|
|
357
|
+
await M.exportXlsx('financial-model.xlsx');
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Recipe: Loan Amortization
|
|
361
|
+
|
|
362
|
+
```javascript
|
|
363
|
+
const M = new SheetModel();
|
|
364
|
+
M.addSheet('Loan');
|
|
365
|
+
|
|
366
|
+
M.addSection('Loan', 'LOAN PARAMETERS');
|
|
367
|
+
M.addBlank('Loan');
|
|
368
|
+
M.addRow('Loan', 'Principal', 500000, { name: 'Principal' });
|
|
369
|
+
M.addRow('Loan', 'Annual Rate', 0.05, { name: 'AnnualRate' });
|
|
370
|
+
M.addRow('Loan', 'Years', 20, { name: 'Years' });
|
|
371
|
+
M.addRow('Loan', 'Monthly Rate', '=AnnualRate/12', { name: 'MonthlyRate' });
|
|
372
|
+
M.addRow('Loan', 'Periods', '=Years*12', { name: 'Periods' });
|
|
373
|
+
M.addBlank('Loan');
|
|
374
|
+
// PMT returns negative (cash outflow) — negate for display
|
|
375
|
+
M.addRow('Loan', 'Monthly Payment', '=-PMT(MonthlyRate, Periods, Principal)', { name: 'Payment' });
|
|
376
|
+
M.addRow('Loan', 'Total Interest', '=Payment*Periods - Principal', { name: 'TotalInterest' });
|
|
377
|
+
|
|
378
|
+
await M.exportXlsx('loan-model.xlsx');
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Available Formulas
|
|
382
|
+
|
|
383
|
+
HyperFormula supports **395 built-in functions** including:
|
|
384
|
+
|
|
385
|
+
- **Math**: SUM, AVERAGE, MIN, MAX, ABS, ROUND, CEILING, FLOOR, MOD, POWER, SQRT, LOG
|
|
386
|
+
- **Financial**: PMT, FV, NPER, PV, RATE, NPV, XNPV
|
|
387
|
+
- **Logical**: IF, IFS, AND, OR, NOT, SWITCH, IFERROR
|
|
388
|
+
- **Lookup**: VLOOKUP, HLOOKUP, INDEX, MATCH
|
|
389
|
+
- **Statistical**: COUNT, COUNTA, COUNTIF, SUMIF, SUMIFS, AVERAGEIF
|
|
390
|
+
- **Text**: CONCATENATE, LEFT, RIGHT, MID, LEN, TRIM, UPPER, LOWER, TEXT
|
|
391
|
+
- **Date**: DATE, YEAR, MONTH, DAY, TODAY, DATEDIF, EOMONTH
|
|
392
|
+
|
|
393
|
+
Full list: https://hyperformula.handsontable.com/guide/built-in-functions.html
|
|
394
|
+
|
|
395
|
+
## ExcelJS Gotchas (Critical)
|
|
396
|
+
|
|
397
|
+
These bugs were discovered empirically and MUST be followed:
|
|
398
|
+
|
|
399
|
+
1. **Named ranges**: Use `cell.names = ['Name']`, NEVER `definedNames.add()` or `addEx()`.
|
|
400
|
+
- `add()` tries to parse the name as a cell ref → crashes on names like `InvFinCP`
|
|
401
|
+
- `addEx()` silently doesn't persist to the .xlsx file
|
|
402
|
+
- SheetModel handles this automatically — don't use ExcelJS definedNames directly
|
|
403
|
+
|
|
404
|
+
2. **Formula prefix**: HyperFormula `getCellFormula()` returns `"=SUM(...)"` with leading `=`.
|
|
405
|
+
ExcelJS expects `{ formula: 'SUM(...)' }` without `=`. Double `=` causes `#NAME?` errors.
|
|
406
|
+
SheetModel handles this automatically.
|
|
407
|
+
|
|
408
|
+
3. **Formula language**: .xlsx always stores formulas in English (`SUM`, `ABS`, `IF`).
|
|
409
|
+
Excel translates to locale on display. Always write English function names.
|
|
410
|
+
|
|
411
|
+
## Limitations
|
|
412
|
+
|
|
413
|
+
- **Row limit**: Practical limit ~5,000 rows. For larger datasets, use pandas/openpyxl via the `xlsx` skill.
|
|
414
|
+
- **Single value column on data sheets**: `addRow` writes to columns A (label) and B (value) only. For multi-period models (Year 1, Year 2, Year 3), use a scenario sheet where each "scenario" is a period, or use direct HyperFormula API (`M.hf.setCellContents(...)`) for additional columns.
|
|
415
|
+
- **Data sheet formatting**: All values in data sheets are formatted as integers (`#,##0`). For percentages, ratios, or decimals, compute them in a scenario sheet output with the appropriate `format` option, or post-process with ExcelJS (see Advanced Styling).
|
|
416
|
+
- **No charts**: HyperFormula/ExcelJS can't create Excel charts. Add charts manually or use a separate tool.
|
|
417
|
+
- **No pivot tables**: Use pandas for pivot-style analysis.
|
|
418
|
+
- **Scenario columns**: Maximum **25** scenarios per sheet (columns B–Z). For readability, keep to 10 or fewer.
|
|
419
|
+
- **Named range naming**: Names that match Excel cell/column references (e.g., `AC`, `R1C1`, `A1`) are rejected automatically. Use descriptive names.
|
|
420
|
+
- **Data sheet formulas in .xlsx**: The exported Excel formula is the original text, not extracted from HyperFormula. Stick to bare named expressions (e.g., `Revenue`, `OpIncome`) and A1 refs via template literals (e.g., `` `=SUM(B${r1}:B${r3})` ``).
|