How neochiu1004/rebalance works
1. Purpose and runtime
This is a client-only Taiwan equity portfolio rebalancing tool. It runs as a static browser application with no build or server requirement; index.html is the entry page and JavaScript modules implement the application behavior. Primary runtime state is persisted in browser localStorage.
Paths: index.html, core.js, state.js
2. Application bootstrap and shared control layer
core.js is the likely central application coordinator: it connects page interactions, shared calculations, and feature modules. The UI is hosted in one HTML page, so module-to-module coordination occurs in the browser rather than through backend APIs or server routing.
Paths: index.html, core.js
3. Persistent portfolio state and backup boundary
state.js owns the persistence boundary for holdings, transaction history, and user settings. Data survives browser sessions through localStorage; clearing browser storage, changing devices, or private browsing can lose it. Backup import replaces portfolio/settings data, while API credentials remain local and are excluded from backups.
Paths: state.js, index.html
4. Holdings and transaction-record domain
Asset/holding management is separated from transaction recording. Holdings provide the current portfolio basis, while transaction records capture buys and sells used for cost and performance-oriented calculations. Trading fees and tax treatment are material domain rules: discounted brokerage commission with a minimum fee, plus differing sell tax rates for stocks versus ETFs.
Paths: assets.js, transactions.js, trade.js
5. Trade calculation flow
The trade feature takes an intended buy or sell and applies cost rules to calculate actual paid cost or sale proceeds. Those results feed the portfolio overview’s cost basis, where estimated current-sale commission and transaction tax are recalculated from current price rather than permanently accumulated.
Paths: trade.js, transactions.js, assets.js
6. Rebalancing workflow
The rebalancing module compares current holdings against target allocations and produces the calculations needed to move toward the desired portfolio mix. Its inputs cross the holdings/state boundary and likely use current market prices when available; its output is planning information rather than broker execution.
Paths: rebalance.js, assets.js, state.js
7. Market-data and analytical features
Two external data boundaries supply market information:
• Fugle provides real-time quotes, authenticated with a user-entered API key.
• FinMind provides historical prices and high/low analysis, authenticated with a token.
watch.js represents quote/watch functionality, while waterlevel.js implements high/low “water level” analysis. Credentials are device-local settings and should not enter backup files.
Paths: watch.js, waterlevel.js, state.js
8. Front-end dependencies
The browser UI depends on CDN-delivered Chart.js for chart rendering and Tailwind CSS for styling. The repository itself is plain static HTML/JavaScript; a local static server is optional only to serve index.html.
Paths: index.html, README.md
Main entry points: core.js Application coordinator · state.js Portfolio state · assets.js Holdings · index.html Single-page UI
Components 14
Browser application
Static client-only runtime.
- Single-page UI · Hosts the application interface and browser modules.
index.html - Application coordinator · Connects interactions, calculations, and feature modules.
core.js - Portfolio state · Owns holdings, history, settings, and backup import.
state.js - Browser localStorage · Device-local persistence boundary.
Portfolio domain
- Holdings · Maintains the current portfolio basis.
assets.js - Transaction records · Captures buys and sells for cost and performance calculations.
transactions.js - Trade calculator · Applies commission, minimum fee, and stock/ETF sell-tax rules.
trade.js - Rebalancing planner · Compares holdings with target allocations; does not execute trades.
rebalance.js
Market data
- Quote watch
watch.js - Water-level analysis · Analyzes historical highs and lows.
waterlevel.js
External services
- Fugle quotes · Real-time quotes authenticated by a local API key.
- FinMind history · Historical prices authenticated by a local token.
- Chart.js CDN · Renders charts.
- Tailwind CSS CDN · Styles the interface.
Connections 21
- Single-page UI → Application coordinator: boots
- Single-page UI → Chart.js CDN: loads
- Single-page UI → Tailwind CSS CDN: loads
- Application coordinator → Portfolio state: reads and updates
- Application coordinator → Holdings: coordinates
- Application coordinator → Transaction records: coordinates
- Application coordinator → Trade calculator: uses calculations
- Application coordinator → Rebalancing planner: opens planning
- Application coordinator → Quote watch: opens quotes
- Application coordinator → Water-level analysis: opens analysis
- Portfolio state → Browser localStorage: persists
- Portfolio state → Holdings: stores holdings
- Portfolio state → Transaction records: stores history
- Trade calculator → Transaction records: calculates buy/sell results
- Trade calculator → Holdings: updates cost basis
- Rebalancing planner → Holdings: compares holdings
- Rebalancing planner → Portfolio state: reads targets
- Quote watch → Fugle quotes: fetches quotes
- Water-level analysis → FinMind history: fetches history
- Portfolio state → Fugle quotes: keeps API key local
- Portfolio state → FinMind history: keeps token local