A compound interest calculator is a weekend project. A "what if I had invested $1,000 in NVDA in January 2016" calculator is not: you need years of daily prices, split adjustments, dividends you can reinvest or ignore, a benchmark to compare against, and a chart that still reads well at 320 px wide.
Personal finance bloggers, newsletter writers and small advisory firms ask for exactly that second kind. So we built a set of them, as embeddable iframes that anyone can drop into a page for free. This post shows two of them running live, the embed code, the URL parameters, and the engineering behind auto-height iframes that don't need a library.
Live: What If I Had Invested
This is the real embed code running inside a LiveCodes sandbox, with symbol=NVDA, amount=1000 and from=2016-01 set in the URL. Change the ticker or the month and it recalculates from the price history.
Live: Stock Seasonality, dark theme
Same embed, different calculator: average return and the share of up years for each calendar month, here for SPY with theme=dark and period=all.
The whole embed
Each calculator page has a generator, but the code it produces is short enough to write by hand:
<iframe src="https://www.quotelinks.com/calculators/embed/what-if-invested.html?symbol=NVDA&amount=1000&from=2016-01" title="What if I had invested calculator" loading="lazy" referrerpolicy="strict-origin-when-cross-origin" style="display:block;width:100%;max-width:760px;height:690px;border:0"></iframe> <p style="max-width:760px;margin:6px 0 0;font-size:13px"><a href="https://www.quotelinks.com/calculators/what-if-invested.html">What if I had invested calculator</a> by <a href="https://www.quotelinks.com/">Quotelinks</a></p> <script src="https://www.quotelinks.com/calculators/resize.js" async></script> Three parts:
- The iframe. A fixed starting height so the page doesn't jump while it loads,
loading="lazy"so a calculator far down an article costs nothing until it's scrolled to. - The credit line. A normal paragraph in your page, under the iframe. That's the only "price" of using them.
-
resize.js(optional). About 1 KB. It resizes the iframe to fit its content, so there's no inner scrollbar and no empty space when a result panel opens or closes.
URL parameters
Every calculator accepts three shared parameters:
| Parameter | Values | Notes |
|---|---|---|
theme | light (default), dark, auto | auto follows the visitor's prefers-color-scheme |
currency | USD, EUR, GBP, CAD, AUD, INR, JPY… | Changes symbols and number formatting. Stock prices stay in USD. |
locale | any BCP 47 tag, e.g. de-DE | Defaults to a sensible locale for the currency |
Each calculator then has its own starting values. A few examples:
| Calculator | Parameters |
|---|---|
| What If I Invested | symbol, amount, from (YYYY-MM), monthly, compare (default SPY), div (tr reinvested / px price only) |
| Stock Seasonality | symbol, period (all, 20, 10, 5 years), div |
| Historical Inflation | amount, from, to (YYYY or YYYY-MM) |
| Portfolio Backtest | portfolio=SPY:60,AGG:40, amount, monthly, from, rebalance, compare |
Parameters are treated as a public API: once published they never change meaning, only new ones are added, so an embed pasted today keeps working.
Six worth starting with
There are 33 in total; these six show the range best:
| Calculator | What it answers |
|---|---|
| What If I Invested | What a past investment in a stock or ETF is worth today, vs. the S&P 500 |
| Stock Seasonality | Average return and share of up years for each calendar month |
| Portfolio Backtest | Return, volatility and worst drawdown for a mix of up to 10 holdings |
| Dividend & DRIP | Future dividend income and the effect of reinvesting |
| Historical Inflation | What an amount from any month since 1913 is worth now (US CPI) |
| Compound Interest | Growth of savings net of fees, tax and inflation |
The rest cover risk (beta, Sharpe ratio, drawdown, rolling returns, correlation), dividends (yield on cost, dividend capture, dividend discount), valuation (Graham number, P/E fair value), trading (stock profit, average down, position size), bonds, and planning (rule of 72, DCA vs lump sum, rebalancing, salary inflation, Fed funds rate history, currency conversion).
How it works
Why an iframe and not a script widget. Our scrolling ticker tape is a script that renders into Shadow DOM, which is fine for a strip of prices. A calculator has forms, a ticker autocomplete, charts with a crosshair and a lot more JavaScript. An iframe isolates all of it in both directions: a WordPress theme's input { width: 100% !important } can't reach in, and nothing we run can touch the host page. It also survives page builders that strip <script> tags but allow iframes.
Auto-height with postMessage, in about 20 lines. Inside the embed, a ResizeObserver watches the document and posts its height to the parent, skipping changes under 2 px so it can't feed back into itself:
var lastH = 0; function postHeight() { if (window.parent === window) return; var h = Math.ceil(document.documentElement.getBoundingClientRect().height); if (Math.abs(h - lastH) < 2) return; lastH = h; window.parent.postMessage({ type: 'ql-calc-height', h: h }, '*'); } new ResizeObserver(postHeight).observe(document.documentElement); On the host page, resize.js checks the sender's origin, finds which iframe sent the message by comparing contentWindow with event.source (so five calculators on one page each get their own height), and clamps the value to a sane range:
window.addEventListener('message', function (e) { if (!ORIGINS[e.origin]) return; var d = e.data; if (!d || d.type !== 'ql-calc-height') return; var h = Math.round(+d.h); if (!(h > 100 && h < 5000)) return; var fr = document.getElementsByTagName('iframe'); for (var i = 0; i < fr.length; i++) { if (fr[i].contentWindow === e.source) { fr[i].style.height = h + 'px'; break; } } }); A window.__qlCalcResize guard makes it safe to include the script twice, which happens a lot when people paste the embed code more than once. Posting to '*' is fine here because a height isn't sensitive; the receiving side is where the checks belong.
Formatting is Intl.NumberFormat, not string math. currency=EUR&locale=de-DE gives 1.234 € with no custom formatting code. The currency option only changes how numbers are shown; stock prices are USD and are never silently converted.
Charts are hand-built inline SVG. No chart library: each chart is a viewBox SVG string with a pointer-move crosshair and tooltip. That keeps each calculator's script to roughly 5–20 KB.
Data loads lazily. Typing a ticker triggers one request for that symbol's history, cached in memory, so switching back and forth costs nothing. The autocomplete list is a static JSON file fetched once on first focus.
Nothing to track. All calculations run in the visitor's browser. No cookies, no analytics, no ads inside the iframe, which matters if your own site has a cookie banner you don't want to extend.
Pasting it into common platforms
- WordPress: a Custom HTML block.
- Blogger: switch the post editor to HTML view and paste.
- Ghost: an HTML card.
- Squarespace: a Code block.
- Webflow: an Embed element.
- Wix: Embed code → Embed HTML. Wix wraps your HTML in its own iframe, so set the box height to match the calculator instead of relying on
resize.js.
If a platform removes the <script> line, nothing breaks: the iframe keeps its fixed height and scrolls inside if it needs to.
The fine print
Free for personal and commercial websites, with no sign-up and no API key. Please keep the credit line under the calculator visible and unchanged. Results are estimates for illustration, not investment advice.
All 33 calculators, each with its embed generator, are on quotelinks.com/calculators. Free stock research and screeners are on Quotelinks.
Which calculator is missing? If you've had to build one for a client or your own blog, tell me in the comments and it may be number 34.
