↓Skip to main content
  1. Projects/

SG HYSA Calculator

··1238 words·6 mins

SG HYSA Calculator home page
SG HYSA Calculator: enter a profile and compare every account

The SG HYSA Calculator is a browser-based tool for comparing Singapore high-yield savings accounts (HYSAs). You enter a profile — savings, salary, age, card spending, GIRO transactions, insurance, investments, loan instalments and NTUC membership — and it calculates the yearly interest and effective interest rate (EIR) for every supported account.

The headline number is only part of the answer. Most of these accounts are tiered and conditional: the advertised rate depends on salary credit, card spend, a minimum balance or a product purchase, and the rate applies only up to a cap. The calculator models those conditions instead of comparing marketing rates, so a 2.4% account can beat a 4% account once the requirements and caps are counted.

What it does

  • Current rates table — yearly interest, EIR, remarks and the last-updated date for 19 accounts across 13 banks, with links to each bank’s official page.
  • Interest vs savings chart — projected yearly interest from $0 to $200,000, with a reference line at your current savings.
  • Rate history (/history) — compare banks over time, in dollars or EIR, with forward-filled snapshots and per-bank detail pages.
  • Optimize (/optimize) — start from your profile, find the best account, then list one candidate change per account with the new EIR, the extra yearly interest, the annual cost and the net.
  • Walkthrough (/walkthrough) — three narrated tours of the main flows, generated from the app itself.

Tech stack

LayerTechnology
UIReact 19, TypeScript, Material UI 9
ChartsMUI X Charts
BuildVite 8
RoutingReact Router
TestsVitest, Testing Library
WalkthroughsRemotion, Playwright, Edge TTS
Package managerBun

How it is put together

The data model lives in src/banks. Each bank is a class with its accounts, and each account has an info.ts, a history.ts with dated rate snapshots, an interest.ts with the actual interest function, and tests. A BankRegistry composition root in src/banks/index.ts fixes the order used by the rate table, the charts, the optimizer and the sitemap.

That makes the interest function the single source of truth. The table and the optimizer both call it, and the history page reads the same rate snapshots; none of them keep a second copy of the bank’s rules. Adding a rate change means adding a snapshot, not editing a comparison table in three places.

What was technically interesting

An optimizer that probes the calculator instead of copying it

The easy version of the Optimize page is a handwritten table of thresholds: “UOB One needs $500 of card spend”, “OCBC 360 needs a $500 average daily balance increase”, and so on. That table would be a second copy of rules that already exist in the interest functions, and the copy nobody recalculates is the one that goes stale.

Instead, the optimizer probes the real interest functions. It builds a probe grid from a geometric sweep of plausible values plus every non-negative integer literal found by scanning src/logic/*.ts, so a threshold in the code is not missed by the grid. The probes run offline and are committed as optimizeTables.json (about 16KB). At runtime the page looks up breakpoints rather than evaluating 545 values across 14 fields.

The search is pruned in a few deliberate ways:

  • Only breakpoints above the current value are candidates, and the scan stops at the first value that raises the account’s rate. A demo profile that would otherwise need 7,630 profiles becomes 53 candidates, and filtering leaves 3 rows.
  • The savings minimum is found by bisection, because inside a single savings bracket “does this balance qualify?” is monotonic. The demo bracket takes about 14 tests instead of walking 15,000 balances; the widest bracket takes 21 instead of 1,200,000.
  • bestBank() and the candidate list are memoised on a canonical profile key, and duplicates are collapsed before sorting.

The result is a page that lists, for each account, the next requirement that account cares about, the change needed to reach it, and what that change does to your EIR and yearly interest.

A cost model that refuses changes that cost more than they earn

A higher rate is not automatically a better outcome. Moving a large balance into a high-rate, low-cap account can lift the headline percentage while lowering the dollars you actually receive. The optimizer therefore requires the EIR to improve without lowering the yearly interest before a candidate is shown:

best.eir > eir0 && best.yearly >= yearly0

It also prices the commitment behind each condition instead of treating every dollar the same:

KindExampleCounts as annual cost
Spend$500 more card spend per monthYes, times 12
PremiumAn insurance premiumYes
CapitalAn investment or a one-time loanNo, it is committed, not spent
TransferMoving savings into the accountNo

Net is the yearly interest gained minus the annual running cost. That is why a row can show a 4.30% EIR and still be labelled as costing more than it earns. The page is a comparison tool, not financial advice, and the rows say so.

Walkthrough tours generated from the app

The walkthrough page is not a screen recording. Each tour is defined as data in src/walkthrough/flows.ts: an id, a route, a fixed demo profile, the “what you’ll learn” bullets, and a list of steps. A step contains the caption, the narration, the Playwright actions to replay, the selector to spotlight, and optionally text the highlighted element must contain.

One definition feeds three consumers:

  1. npm run walkthrough:capture starts Vite and Chromium, seeds the demo profile, replays the actions, captures a screenshot and cursor position, synthesises narration, and writes a YAML timeline plus the media.
  2. The Remotion player on /walkthrough renders that timeline with a chapter rail and the written steps underneath.
  3. npm run docs:check verifies that the generated docs, timelines, screenshots, audio and sitemap agree with the encoded flows in CI.

The narration has a fallback chain: Edge neural TTS (en-SG-LunaNeural), then macOS say, then espeak-ng, then a silent track of the estimated length. No API key is required, and a Linux CI machine can still produce a watchable timeline.

The capture doubles as an end-to-end test: it drives the real app through the three main flows and fails when a selector or expected string moves. That is a check the jsdom tests cannot make. The cost is committed media (about 4.6MB) and a manual capture step, and the check cannot prove the screenshots still match the UI unless someone re-runs the capture.

Caveats

  • The numbers are only as current as the rate snapshots. If a bank changes its terms without a new snapshot, the calculator is confidently wrong.
  • The optimizer shows one step and one candidate per account. It is not a multi-step planner, and four of its shortcuts (only forwards, first hit, one row per account, the $1,000 block) can miss the global best.
  • It models savings accounts only. It can answer “which HYSA”, not “should this money be in a HYSA at all”.
↑