<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: a353551071</title>
    <description>The latest articles on DEV Community by a353551071 (@a353551071).</description>
    <link>https://dev.to/a353551071</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4068758%2F6995e0f8-1b9a-4641-8d99-565663720faf.png</url>
      <title>DEV Community: a353551071</title>
      <link>https://dev.to/a353551071</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/a353551071"/>
    <language>en</language>
    <item>
      <title>I open-sourced the math behind my dividend calculator</title>
      <dc:creator>a353551071</dc:creator>
      <pubDate>Sat, 08 Aug 2026 11:57:05 +0000</pubDate>
      <link>https://dev.to/a353551071/i-open-sourced-the-math-behind-my-dividend-calculator-2in7</link>
      <guid>https://dev.to/a353551071/i-open-sourced-the-math-behind-my-dividend-calculator-2in7</guid>
      <description>&lt;p&gt;When I built a free &lt;a href="https://www.dividendpayoutcalculator.com" rel="noopener noreferrer"&gt;dividend payout calculator&lt;/a&gt;, the interesting part wasn't the UI — it was the math. Dividend yield, payout ratio, and especially the way a DRIP (dividend reinvestment plan) compounds year over year. So I pulled the formulas out into a tiny, zero-dependency TypeScript library: &lt;strong&gt;&lt;a href="https://github.com/a353551071/dividend-math" rel="noopener noreferrer"&gt;dividend-math&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This post is the story of the library and the one calculation that surprised me: how reinvestment plus growth quietly outruns a flat high yield.&lt;/p&gt;

&lt;h2&gt;
  
  
  The library
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;dividend-math&lt;/code&gt; is one file of pure functions. No runtime dependencies, no I/O, fully tree-shakeable. You can &lt;code&gt;npm install dividend-math&lt;/code&gt; or just copy &lt;a href="https://github.com/a353551071/dividend-math/blob/main/src/dividend.ts" rel="noopener noreferrer"&gt;&lt;code&gt;src/dividend.ts&lt;/code&gt;&lt;/a&gt; into your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;dividendYield&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payoutRatio&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;monthlyDividendIncome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;dripCalculator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dividend-math&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Yield: $2.80 annual dividend on an $80 share&lt;/span&gt;
&lt;span class="nf"&gt;dividendYield&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;annualDividendPerShare&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;2.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// → 3.5 (%)&lt;/span&gt;

&lt;span class="c1"&gt;// Sustainability: dividend vs earnings&lt;/span&gt;
&lt;span class="nf"&gt;payoutRatio&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;dividendPerShare&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;earningsPerShare&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// → 40 (%)&lt;/span&gt;

&lt;span class="c1"&gt;// Monthly cash flow on a position&lt;/span&gt;
&lt;span class="nf"&gt;monthlyDividendIncome&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;investment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dividendYieldPct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// → ~541.67/month&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All percentage inputs are plain numbers (&lt;code&gt;5&lt;/code&gt; for 5%); money is in dollars. Returns are numeric and predictable — &lt;code&gt;dividendYield&lt;/code&gt; returns &lt;code&gt;NaN&lt;/code&gt; for a zero price, &lt;code&gt;payoutRatio&lt;/code&gt; returns &lt;code&gt;NaN&lt;/code&gt; for zero earnings, so the bad inputs fail loudly instead of producing pretty-looking nonsense.&lt;/p&gt;

&lt;h2&gt;
  
  
  The interesting one: DRIP compounding
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;dripCalculator&lt;/code&gt; simulates a dividend reinvestment plan year by year. Each year it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Computes dividends at the &lt;strong&gt;current&lt;/strong&gt; yield on the &lt;strong&gt;current&lt;/strong&gt; share count.&lt;/li&gt;
&lt;li&gt;Reinvests those dividends into more shares at the &lt;strong&gt;current&lt;/strong&gt; price.&lt;/li&gt;
&lt;li&gt;Adds monthly contributions buying shares at the current price.&lt;/li&gt;
&lt;li&gt;Then grows the price by &lt;code&gt;priceGrowthPct&lt;/code&gt; and the yield by &lt;code&gt;dividendGrowthPct&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dripCalculator&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;initialInvestment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dividendYieldPct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;3.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dividendGrowthPct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;priceGrowthPct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;monthlyContribution&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;years&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// → { shares, finalPrice, finalValue, totalInvested, totalDividends, finalAnnualDividendIncome }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result that always gets people: &lt;strong&gt;a 3.5% yield with 10% annual dividend growth, reinvested, beats a flat 6% yield over a long horizon&lt;/strong&gt; — because the dividend grows &lt;em&gt;and&lt;/em&gt; buys more shares as it does. The starting yield is the wrong number to optimize; the growth rate matters more.&lt;/p&gt;

&lt;p&gt;That's the whole reason a "good" dividend yield is usually 3–5%, not 8%+. A high yield often means the price collapsed or the payout is unsustainable — which is why the calculator pairs yield with the payout ratio.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why pure functions, and why a library at all?
&lt;/h2&gt;

&lt;p&gt;Two reasons. First, &lt;strong&gt;testability&lt;/strong&gt;: every formula is a pure function, so the edge cases (zero price, zero growth, g = 0 in the geometric series for cumulative dividends) are covered by &lt;a href="https://github.com/a353551071/dividend-math/blob/main/tests/dividend.test.ts" rel="noopener noreferrer"&gt;16 unit tests&lt;/a&gt;. Second, &lt;strong&gt;reuse&lt;/strong&gt;: the same &lt;code&gt;dripCalculator&lt;/code&gt; drives the DRIP page, the SCHD and QQQI ETF calculators, and the monthly-income page on the live site. One source of truth, no drift.&lt;/p&gt;

&lt;h2&gt;
  
  
  The live calculator
&lt;/h2&gt;

&lt;p&gt;The library powers &lt;a href="https://www.dividendpayoutcalculator.com" rel="noopener noreferrer"&gt;dividendpayoutcalculator.com&lt;/a&gt; — a free suite with dedicated calculators for &lt;a href="https://www.dividendpayoutcalculator.com/calculators/schd-dividend-calculator" rel="noopener noreferrer"&gt;SCHD&lt;/a&gt; and &lt;a href="https://www.dividendpayoutcalculator.com/calculators/qqqi-dividend-calculator" rel="noopener noreferrer"&gt;QQQI&lt;/a&gt;, plus yield, payout ratio, growth, and monthly income. No sign-up, runs entirely in the browser.&lt;/p&gt;

&lt;p&gt;If you're building anything finance-adjacent and need the math, grab the library. If you just want to run the numbers, the calculator's free.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Library (npm):&lt;/strong&gt; &lt;code&gt;npm install dividend-math&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source:&lt;/strong&gt; &lt;a href="https://github.com/a353551071/dividend-math" rel="noopener noreferrer"&gt;github.com/a353551071/dividend-math&lt;/a&gt; (MIT)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live app:&lt;/strong&gt; &lt;a href="https://www.dividendpayoutcalculator.com" rel="noopener noreferrer"&gt;dividendpayoutcalculator.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thoughts on the DRIP model — anything you'd add to the simulation (tax drag, FX, variable monthly contributions)? I'd love to hear how you'd extend it.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>finance</category>
      <category>opensource</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
