Skip to content
toondeboerPublic

About

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

256 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

sailor

CI Angular NgRx TypeScript Python AWS Tailwind CSS

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

โšก Prerequisites

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

๐Ÿ›  Local development

Three processes run together. Use a separate terminal for each.

1 โ€” Install dependencies

yarn install                                    # frontend + Nx toolchain

python3.13 -m venv .venv                       # one-time Python venv
source .venv/bin/activate
pip install -r services/requirements-dev.txt

Activate the venv in every new terminal before running backend commands:

source .venv/bin/activate

2 โ€” Database (DynamoDB Local)

docker-compose up

First run only โ€” create the table:

python services/init_dynamodb.py

3 โ€” Backend APIs (AWS SAM)

First 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.sh

This 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.json supplies OPENAI_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.

4 โ€” Frontend

nx serve frontend

Open 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.


๐Ÿ”ง Useful commands

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

๐Ÿงฎ Financial logic

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.

Portfolio value

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.


Unrealized P&L (Profit & Loss)

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 and gross invested

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.


Total return

absolute  = V(t) โˆ’ net_invested + cumulative_dividends
percentage = absolute / gross_invested ร— 100

Dividends are counted as return; commission is not.


Average share price

avg_share_price = net_invested / shares_held(t)

Computed only when shares_held โ‰  0.


Modified Dietz return (per calendar year)

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.


Rolling period returns (1 D / 1 W / 1 M)

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

Dividend calculations

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.


FX conversion

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.


Multi-stock aggregation

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.


๐Ÿ’ณ Ask the Captain & subscription

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.

About

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages