English | 中文
Still unsure what your average cost is after averaging down? Bought in multiple batches or traded in and out — and lost track of your blended price? Try this browser extension: enter each batch's quantity and price, and get your weighted average, total amount, and total shares instantly.
A lightweight browser extension for calculating the weighted average cost of stock positions across multiple purchases. Enter quantity and price for each batch to get real-time average cost, total amount, and total shares.
| Initial UI | Results & History |
|---|---|
![]() |
![]() |
The UI automatically switches between English and Chinese based on your browser language. Chinese screenshots:
images/ScreenShot_ZH_01.pngandimages/ScreenShot_ZH_02.png.
- Real-time calculation — Average cost, total amount, and total quantity update as you type
- Multi-batch input — Add multiple rows to simulate scaling in or averaging down
- History — Automatically saves eligible calculations, up to 50 records
- One-click restore — Click a history entry to refill the input fields
- Clear & reset — Clear all inputs with one click
- Multilingual — Built-in English and Simplified Chinese, follows browser locale
- Privacy-friendly — Only uses the
storagepermission; all data stays local
- Calculate blended cost after buying the same stock in multiple batches
- Quickly estimate new average price after trading or adding to a position
- Compare cost outcomes across different buying strategies
The extension uses a weighted average formula:
Average Cost = Total Amount ÷ Total Quantity
Total Amount = Σ(Quantity × Price)
Total Quantity = Σ(Quantity)
Example: Buy 1,000 shares at 10, then 1,000 shares at 5
| Metric | Value |
|---|---|
| Total Amount | 15,000.00 |
| Total Quantity | 2,000 |
| Average Cost | 7.50 |
-
Clone this repository:
git clone https://github.com/licc12/Stock-Price-Calculator.git cd Stock-Price-Calculator -
Open Chrome (or Edge, Brave, or other Chromium browsers) and go to the extensions page:
- Chrome:
chrome://extensions/ - Edge:
edge://extensions/
- Chrome:
-
Enable Developer mode in the top-right corner
-
Click Load unpacked and select the project root directory
-
Click the extension icon in the toolbar to start using it
Not yet published on the Chrome Web Store. Manual loading is required for now.
- Enter data — Fill in quantity and price for each batch (2 rows by default)
- Add rows — Click "+ Add Row" to record more batches
- View results — The top card shows average cost, total amount, and total quantity
- Save to history — On blur, eligible calculations are saved automatically when:
- At least 2 valid rows exist (quantity > 0, price ≥ 0)
- At least 2 different purchase prices are present
- Restore — Click a history entry to refill the inputs
- Delete — Click "Delete" on a history entry to remove it
- Clear — Click "Clear" to reset all input rows
Stock-Price-Calculator/
├── manifest.json # Extension manifest (Manifest V3)
├── popup/
│ ├── popup.html # Popup page
│ ├── popup.css # Styles
│ └── main.js # Entry point
├── src/
│ ├── calculator.js # Core calculation logic
│ ├── constants.js # Constants
│ ├── i18n.js # Internationalization
│ ├── storage/
│ │ └── history.js # History storage
│ ├── ui/
│ │ ├── inputs.js # Input row management
│ │ ├── result.js # Result display
│ │ └── history.js # History list
│ └── utils/
│ └── format.js # Number formatting
├── _locales/
│ ├── zh_CN/messages.json
│ └── en/messages.json
├── icons/ # Extension icons
└── images/ # Screenshots
- Manifest V3 — Latest Chrome extension standard
- Vanilla JavaScript (ES Modules) — No build step required
- Chrome Storage API — Local history persistence
- Chrome i18n — Native internationalization
This extension:
- Only requests the
storagepermission for local history - Does not collect or upload any user data
- Does not access page content or inject scripts
- Performs all calculations locally
This project is licensed under the MIT License.
Issues and Pull Requests are welcome. Before submitting code:
- Follow the existing code style and directory structure
- Update both
_locales/zh_CNand_locales/enwhen adding UI strings
If you find this project helpful, please give it a Star ⭐

