Multi-portfolio investment tracker with per-currency holdings, dividend tracking, and time-series P&L charts. Live at sailor.toondeboer.com.
An Nx monorepo: Angular 21 + NgRx frontend, Python AWS Lambda + DynamoDB backend, Cognito auth.
| Doc | What's in it |
|---|---|
| ARCHITECTURE.md | Project layout, data flow, auth, infra decisions |
| ROADMAP.md | Planned work: mobile-first UI/UX, iOS/Android apps |
| docs/OPERATIONS.md | Deploy, secrets, quotas, Stripe & test-user runbooks |
| Tool | Version | Install |
|---|---|---|
| Node.js | 22+ | brew install node |
| Yarn | 1.x classic | npm i -g yarn |
| Python | 3.13 | brew install [email protected] |
| Docker | any | docker.com |
| AWS SAM CLI | any | brew install aws-sam-cli |
Three processes run together. Use a separate terminal for each.
yarn install # frontend + Nx toolchain
python3.13 -m venv .venv # one-time Python venv
source .venv/bin/activate
pip install -r services/requirements-dev.txtActivate the venv in every new terminal before running backend commands:
source .venv/bin/activatedocker-compose upFirst run only โ create the table:
python services/init_dynamodb.pyFirst copy the secrets template (one-time): cp env.json.example env.json and paste your keys
(at least OPENAI_API_KEY). env.json is gitignored.
./scripts/start-backend.shThis runs sam build then sam local start-api with dummy AWS credentials and --env-vars env.json, serving the Lambdas on http://localhost:3000. Re-run it after any Lambda change
(it rebuilds each time).
The dummy credentials let the Lambdas talk to DynamoDB Local without an AWS session, and
env.jsonsuppliesOPENAI_API_KEY(and optionally the Stripe keys) as env vars โ without it the key lookup falls through to SSM, which the dummy credentials reject (โ 502). Production keys live in SSM SecureStrings; see docs/OPERATIONS.md.
nx serve frontendOpen http://localhost:4200. The dev server proxies /microservice, /yahoo_finance and
/captain to the SAM APIs on :3000.
Test accounts for the dev Cognito pool (admin / paid / free) are seeded with
scripts/seed-test-users.sh โ see
docs/OPERATIONS.md.
| Command | Purpose |
|---|---|
nx serve frontend |
Dev server with hot reload |
nx run-many -t test |
Run all unit tests |
nx test util |
Test a single project |
nx lint <project> |
Lint a project |
nx build frontend |
Production build |
nx affected -t lint test build |
What CI runs on a PR |
sam build |
Package Python Lambdas |
All calculations live in libs/shared/util/src/lib/ and run entirely in the browser.
The reducer stores only raw inputs; every derived figure is computed in memoized NgRx selectors.
Current market value of a position, expressed in the user's base currency:
V(t) = shares(t) ร price(t) ร FX_market(t)
Missing prices (weekends, holidays) are forward-filled from the last known value. FX rates use the per-date spot rate so today's value tracks today's currency moves.
P&L(t) = V(t) โ cost_basis โ commission
cost_basis and commission use spot-at-purchase FX rates (locked at the rate on each
transaction's own date), so the cost side is never distorted by subsequent FX moves.
cost_basis = ฮฃ ( buy_qty_i ร price_i ร FX_spot_at_purchase_i )
gross_invested = ฮฃ ( buy_value_i ) โ never reduced by sells
gross_invested is the denominator for all percentage returns. Using gross (rather than net)
prevents the denominator from collapsing to zero when a position is fully exited, keeping the
return percentage meaningful throughout the position's life.
absolute = V(t) โ net_invested + cumulative_dividends
percentage = absolute / gross_invested ร 100
Dividends are counted as return; commission is not.
avg_share_price = net_invested / shares_held(t)
Computed only when shares_held โ 0.
Instead of the iterative XIRR, sailor uses the closed-form Modified Dietz method, which is robust on partial years and when positions open and close within the same period:
gain = EMV โ BMV โ net_flows
avg_capital = BMV + ฮฃ ( w_i ร flow_i )
w_i = ( year_end โ flow_date_i ) / ( year_end โ year_start )
R_year = gain / avg_capital
| Symbol | Meaning |
|---|---|
| EMV | Ending market value (year-end or today for the current year) |
| BMV | Beginning market value (prior year-end; 0 for the first year) |
| net_flows | Cash into the portfolio (buys +, sells โ, dividends โ) |
| w_i | Time-weight: fraction of the year the cash was invested |
When avg_capital โค 0 (position opened and closed in the same year) the return is recorded
as 0 rather than dividing by zero.
Computed from a dedicated 30-day daily window regardless of the chart's granularity (so the chips remain accurate even when the main chart is in weekly or monthly mode):
R_absolute(n days) = profit[today] โ profit[today โ n]
R_percentage(n days) = R_absolute / gross_invested ร 100
Per-share dividend value
D_value = dividend_per_share(ex_date) ร shares_held(ex_date)
Share count is snapshotted at the most recent date on or before the ex-date.
Trailing twelve months (TTM) per quarter
TTM[i] = ฮฃ D[j] for j = max(0, iโ3) โฆ i
A rolling four-quarter sum, so TTM[i] represents the income generated in the twelve months ending at quarter i.
Two separate conversion schemes are applied depending on what is being converted:
| What | Rate used | Why |
|---|---|---|
| Cost basis, commission, dividends | Spot rate on the transaction's own date | Locks the historical cost in base currency |
| Current market value | Spot rate on each chart date | Reflects live currency exposure |
FX rates are forward-filled across gaps and backward-filled before the start of history.
GBp (pence) is automatically scaled by ร 0.01 to convert to GBP before any further
conversion.
When a stock's market is closed on a given day (weekend, holiday, or any other gap in the
price feed), getPortfolioValues carries the last known price forward to that date instead
of producing a NaN placeholder. This means every stock's value and profit series is always
continuous before it is summed across stocks:
portfolio_profit[t] = ฮฃ stock_profit_i[t]
stock_profit_i[t] = price_last_known_i[t] ร shares_i[t] โ invested_i[t] โ commission_i[t]
Forward-filling is applied at the source (inside getPortfolioValues) so it covers the
leading edge of a date range too โ previously a range starting on a weekend could produce
a leading NaN that could not be back-filled and caused the portfolio to show zero on that
day.
A sailing-themed assistant that explains the user's portfolio in plain language, backed by an authenticated Lambda calling OpenAI. Spend is bounded by per-user monthly quotas (free vs paid via a Stripe subscription) plus a global monthly ceiling โ the design is described in ARCHITECTURE.md. Setup, limit configuration, Stripe local dev, and test users live in docs/OPERATIONS.md.