Reverse-engineering a P/E ratio in 10 lines of JavaScript (with Alphabet as a worked example)
I build Stockinsky, a side project that generates research pages for US and Hong Kong stocks. Every report has a short section called "market-implied expectations". It is the cheapest piece of the whole pipeline (one line of math, no API calls, no model), and it ended up being the part I trust most. This post walks through the formula, the code, a real example, and the guardrail we had to add.
The question flips
Most valuation methods start from your forecasts and end at a price: guess growth, margins and a discount rate, then compute what the company is "worth". The problem is that every input is a guess, and the output inherits all of them.
A reverse approach starts from the price, which is the one number you don't have to guess, and asks:
If I pay today's P/E and want a given annual return, how fast do earnings per share have to grow for that to work out?
You then compare that required growth rate with what the business has actually been doing. That is a much easier judgment than producing a fair value from scratch. It is the same idea behind Michael Mauboussin's reverse DCF, which we describe on our reverse DCF page, stripped down to a single multiple.
The model in one equation
Assume three things:
- You buy at today's P/E, call it
pe0. - You hold for
nyears and want an annual returnr. - At the end you sell at a "normal" multiple
exitPe.
Ignoring dividends, the price grows only if EPS grows or the multiple changes. Your return target says the price must grow by (1 + r)^n. The price at exit is exitPe × EPS_n, and the price today is pe0 × EPS_0. So:
exitPe × EPS_0 × (1 + g)^n = pe0 × EPS_0 × (1 + r)^n EPS_0 cancels out, which is the nice part: you don't need the earnings number at all, only the multiple. Solving for g:
g = (pe0 × (1 + r)^n / exitPe)^(1/n) − 1 The code
This is close to the function our report generator calls, minus some rounding helpers:
const IMPLIED = { years: 10, exitPe: 15, lowBaseGrowth: 0.25 }; function impliedGrowth(pe, requiredReturn = 0.08) { if (!(pe > 0)) return null; // negative or missing earnings: the question has no answer const { years, exitPe, lowBaseGrowth } = IMPLIED; const g = ((pe * (1 + requiredReturn) ** years) / exitPe) ** (1 / years) - 1; return { requiredEpsCagr: g, lowBase: g > lowBaseGrowth, // see "the guardrail" below }; } console.log(impliedGrowth(26.26)); // { requiredEpsCagr: 0.1422..., lowBase: false } A few deliberate choices:
- 10 years and an exit P/E of 15. Ten years is long enough that a single great or terrible year doesn't dominate. Fifteen is roughly where a mature, still-profitable large company tends to trade. Both are assumptions, and the report prints them next to the result.
- 8% required return for US stocks. We use 9% for Hong Kong. It is a hurdle rate, not a forecast.
- No dividends. Ignoring them means the formula slightly overstates the growth required, so the output errs on the demanding side. For Alphabet, with a 0.28% dividend yield, counting dividends would move the answer below from about 14.2% to about 13.9%; for a utility it is not, which is one reason this tool is a screen and not a verdict.
A real example: Alphabet on October 29, 2026
Alphabet (GOOGL) fell 12.64% on October 29, 2026, closing at USD 283.82, as the market digested its Q3 2026 numbers. The research report on our site, dated October 30, records a P/E of 26.26x on the most recent full fiscal year at that close.
Plug that in:
impliedGrowth(26.26); // requiredEpsCagr ≈ 0.142 So at that price, an investor who wants 8% a year and expects the stock to trade at 15x in ten years needs EPS to compound at about 14.2% a year for a decade.
Is that a lot? The same report gives the context. In FY2025 revenue grew 15.1% and net profit attributable to shareholders grew 32.0%. But in Q3 2026 revenue grew 24.7% while net profit fell 24.3%. The report attributes much of that to "net other income" swinging from +USD 12.759 billion to −USD 8.221 billion, and notes that free cash flow for the quarter was −USD 9.07 billion. Search, the cash engine that was 55.7% of FY2025 revenue, grew 13.4% that year.
That is exactly the kind of comparison the number is for. It doesn't tell you whether 14.2% will happen. It tells you that the price asks EPS to compound at roughly the pace search revenue grew in FY2025 (13.4%), sustained for ten years, before you even get to the capex question. Whether that is easy or hard is a judgment about the business, and now it is a much narrower one.
One more lesson from the same report: it lists two consensus 2026E EPS figures from different sources (USD 20.59 and USD 16.26) and refuses to average them because the bases conflict. A reverse multiple doesn't need either number, which is part of why it's robust when the forward estimates are messy.
Sensitivity: the assumptions matter more than the decimals
Because the inputs are assumptions, never show one number without showing how it moves. Here is the grid for a 26.26x P/E:
const pe = 26.26; for (const r of [0.07, 0.08, 0.09, 0.10]) { const row = [10, 15, 20, 25].map((exitPe) => { const g = ((pe * (1 + r) ** 10) / exitPe) ** (1 / 10) - 1; return (g * 100).toFixed(1).padStart(5); }); console.log(`r=${(r * 100).toFixed(0)}%`.padEnd(6) + row.join(" ")); } Output (columns are exit P/E 10, 15, 20, 25):
r=7% 17.8 13.2 10.0 7.5 r=8% 18.9 14.2 11.0 8.5 r=9% 20.0 15.3 12.0 9.5 r=10% 21.1 16.3 13.0 10.5 Two takeaways. First, the exit multiple moves the answer far more than the required return does: going from 15x to 20x knocks about 3 points off the required growth, while going from 8% to 9% adds about 1. Second, the base case sits in the middle of a range from roughly 7.5% to 21%. Anyone quoting "the market expects 14.2%" without the grid is overselling the precision.
The guardrail: when the arithmetic stops meaning anything
Run the formula across a range of P/E ratios at 8% and an exit of 15x:
P/E 10 -> 3.7% P/E 15 -> 8.0% P/E 20 -> 11.2% P/E 40 -> 19.1% P/E 60 -> 24.1% P/E 120 -> 33.0% The first version of our reports printed all of these with the same confidence. The problem shows up at the bottom of the list. A P/E of 120 usually doesn't mean the market expects 33% compounding for ten years. It usually means earnings are temporarily tiny: a bad year, a one-off charge, a company just turning profitable. The ratio is large because the denominator is near zero, and the "required growth" is just the formula amplifying that.
So we added a flag. If the required growth is above 25% a year (at 8% and an exit of 15x, that happens above a P/E of about 65), the result is still shown, but marked as a low-earnings-base artifact, and the report's written conclusion is no longer required to cite it. In code that is the single lowBase line above. It's a small thing, but it removed a whole class of confident-sounding nonsense from the output.
The same logic explains the pe > 0 check at the top: with negative earnings there is no growth rate that solves the equation, and returning NaN or a negative number would be worse than returning nothing.
What this is and isn't
It is a way to turn a multiple into a sentence a person can argue with: "at this price, earnings need to grow about X% a year for ten years." It is not a fair value, not a price target, and not a prediction. It ignores dividends and balance sheets, treats buybacks only through their effect on EPS, and ignores the path of growth (front-loaded growth and back-loaded growth give the same answer here, and they are not the same investment).
If you want to try it on a company you follow, the Alphabet report shows the full section with the peer multiples next to it. The page header refreshes daily, so its P/E will differ from the 26.26x in the October 30 report section. Or just copy the ten lines above and feed it any P/E you like. The interesting part isn't the output; it's arguing with the assumptions.
Not investment advice. Numbers as of October 29-30, 2026 (Alphabet close and report date); the sensitivity tables are outputs of the code shown.