<?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: CalcUnit</title>
    <description>The latest articles on DEV Community by CalcUnit (@calcunit).</description>
    <link>https://dev.to/calcunit</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%2F4268156%2F3c1dd5be-4eaa-447d-87b9-978ddfd32c18.png</url>
      <title>DEV Community: CalcUnit</title>
      <link>https://dev.to/calcunit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/calcunit"/>
    <language>en</language>
    <item>
      <title>CAGR vs Simple Average: Why 150% Over 5 Years Is Not 30% a Year (With Code)</title>
      <dc:creator>CalcUnit</dc:creator>
      <pubDate>Sun, 06 Dec 2026 15:00:49 +0000</pubDate>
      <link>https://dev.to/calcunit/cagr-vs-simple-average-why-150-over-5-years-is-not-30-a-year-with-code-11el</link>
      <guid>https://dev.to/calcunit/cagr-vs-simple-average-why-150-over-5-years-is-not-30-a-year-with-code-11el</guid>
      <description>&lt;p&gt;An investment grows from $10,000 to $25,000 in 5 years. Total return is 150%. Is that 30% a year?&lt;/p&gt;

&lt;p&gt;No. 150 ÷ 5 = 30 is the naive average, and it is wrong by almost ten points. The true compounded rate — CAGR — is &lt;strong&gt;20.11% a year&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The formula&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CAGR = (ending / beginning) ^ (1 / years) - 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cagr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cagr&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="mi"&gt;25000&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="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# 0.2011 -&amp;gt; 20.11%&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cagr&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="mi"&gt;18000&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="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# 0.1247 -&amp;gt; 12.47%&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cagr&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="mi"&gt;13310&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# 0.1000 -&amp;gt; exactly 10.00%&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cagr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20000&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="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# 0.1487 -&amp;gt; 14.87%&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cagr&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="mi"&gt;8000&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="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;# -0.0436 -&amp;gt; -4.36%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Excel or Google Sheets, with beginning in B1, ending in B2, years in B3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=(B2/B1)^(1/B3)-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or the built-in &lt;code&gt;=RRI(B3,B1,B2)&lt;/code&gt;. Format as a percentage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why the simple average lies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Compound $10,000 at a true 30% for 5 years and you get $10,000 × 1.3^5 = $37,129, not $25,000. The naive average pretends each year's gain does not itself earn gains. CAGR fixes that by taking the nth root of the total growth factor.&lt;/p&gt;

&lt;p&gt;Sanity-check any implementation with the round case: $10,000 → $13,310 over 3 years must return exactly &lt;strong&gt;10.00%&lt;/strong&gt;, because 1.1^3 = 1.331. If yours returns anything else, you typed a wrong value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What CAGR smooths away&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CAGR only sees endpoints. A fund that rose 40% then fell 10% can share a CAGR with a steady grower. Same CAGR, very different ride. CAGR also assumes one lump sum with no deposits or withdrawals. For monthly contributions, use XIRR instead — it weights each cash flow by its date.&lt;/p&gt;

&lt;p&gt;It works downward too: $10,000 → $8,000 over 5 years is &lt;strong&gt;−4.36% a year&lt;/strong&gt;, a steady decline compounding to a 20% total loss.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two traps to avoid&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cherry-picked endpoints.&lt;/strong&gt; A CAGR measured from a market bottom to a peak quotes a tailwind, not skill. Always ask: over exactly which dates, and what did a benchmark do over the same dates?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Annualizing a short streak.&lt;/strong&gt; A 10% gain in six months annualizes to about 21%. That is a good half-year wearing a full-year costume. Treat sub-year CAGRs as illustrations, not track records.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I maintain a free calculator that computes CAGR, total return, and absolute gain from any start value, end value, and duration: &lt;a href="https://calcunit.net/finance/cagr-calculator/" rel="noopener noreferrer"&gt;https://calcunit.net/finance/cagr-calculator/&lt;/a&gt; (canonical: calcunit.net). Education only, not financial advice.&lt;/p&gt;

</description>
      <category>finance</category>
      <category>math</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Simulating a Credit Card Minimum Payment in Code: Why $160 Barely Moves an $8,000 Balance</title>
      <dc:creator>CalcUnit</dc:creator>
      <pubDate>Fri, 04 Dec 2026 15:27:44 +0000</pubDate>
      <link>https://dev.to/calcunit/simulating-a-credit-card-minimum-payment-in-code-why-160-barely-moves-an-8000-balance-54ii</link>
      <guid>https://dev.to/calcunit/simulating-a-credit-card-minimum-payment-in-code-why-160-barely-moves-an-8000-balance-54ii</guid>
      <description>&lt;p&gt;A credit card minimum payment looks small and friendly. Simulate it month by month and it stops looking friendly very fast.&lt;/p&gt;

&lt;p&gt;Most issuers build the minimum like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;minPayment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is 2% of the balance, with a $25 floor. Now run one month of the loop on an $8,000 balance at 22.99% APR:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;monthlyRate = 0.2299 / 12          = 1.9158%
interest    = 8000 * 0.019158      = $153.27
minPayment  = max(8000 * 0.02, 25) = $160.00
principal   = 160.00 - 153.27      = $6.73
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ninety-six percent of the first payment is interest. Only $6.73 touches the balance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hold the payment fixed and count the months&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you keep paying that same $160 every month (instead of letting it shrink with the balance), the simulation needs &lt;strong&gt;167 months&lt;/strong&gt; to reach zero. Total paid: &lt;strong&gt;$26,711.01&lt;/strong&gt;. Interest alone: &lt;strong&gt;$18,711.01&lt;/strong&gt; — more than double the original balance.&lt;/p&gt;

&lt;p&gt;Change one variable, the fixed payment, and the loop tells a different story:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pay $160/mo -&amp;gt; 167 months, $18,711.01 interest
pay $200/mo -&amp;gt;  77 months,  $7,322.69 interest
pay $300/mo -&amp;gt;  38 months,  $3,306.31 interest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first $40 of extra payment buys 90 months. That is because early extra dollars remove principal while the balance — and therefore the interest — is at its largest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two traps the simulation exposes&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The shrinking payment.&lt;/strong&gt; A real minimum is recomputed from the new, smaller balance every month, so the payment falls as you pay. Each smaller payment leaves more balance earning interest for longer. The fixed-payment loop above is the &lt;em&gt;kind&lt;/em&gt; version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The interest line.&lt;/strong&gt; If a payment ever drops to or below that month's interest, the balance stops falling entirely. Always check &lt;code&gt;payment &amp;gt; balance * monthlyRate&lt;/code&gt; before trusting any payoff plan.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I maintain a free calculator that runs exactly this loop and shows months, total paid, and total interest: &lt;a href="https://calcunit.net/credit/credit-card-minimum-calculator/" rel="noopener noreferrer"&gt;https://calcunit.net/credit/credit-card-minimum-calculator/&lt;/a&gt; (canonical: calcunit.net). Education only, not financial advice.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image: AI-generated image. Caption: "AI-generated image."&lt;/em&gt;&lt;/p&gt;

</description>
      <category>finance</category>
      <category>math</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why Is APR Higher Than Your Interest Rate? Solving the Fee Equation Step by Step</title>
      <dc:creator>CalcUnit</dc:creator>
      <pubDate>Thu, 03 Dec 2026 14:57:14 +0000</pubDate>
      <link>https://dev.to/calcunit/why-is-apr-higher-than-your-interest-rate-solving-the-fee-equation-step-by-step-2nb4</link>
      <guid>https://dev.to/calcunit/why-is-apr-higher-than-your-interest-rate-solving-the-fee-equation-step-by-step-2nb4</guid>
      <description>&lt;p&gt;Two lenders can quote the same interest rate and one loan can still cost thousands more. The difference is fees. APR (annual percentage rate) folds those fees into one yearly number so you can compare offers fairly.&lt;/p&gt;

&lt;p&gt;The interest rate (note rate) sets your monthly payment. APR does not set any payment. It answers a different question: if the fees are taken out of what you effectively receive, what rate makes your payments worth exactly that amount today?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The equation the calculator solves&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amountFinanced = loanAmount - totalFees
payment * (1 - (1 + r)^-n) / r = amountFinanced   -&amp;gt;  solve for r, APR = r * 12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Worked example 1 — mortgage:&lt;/strong&gt; loan $200,000, fees $3,000, term 360 months, payment $1,200.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amountFinanced = 200,000 - 3,000 = $197,000
APR = 6.149%   total paid = 1,200 x 360 = $432,000   interest + fees = $235,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The payment alone implies a note rate of about 6.01%. The $3,000 of fees pushes the true cost to 6.149%.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worked example 2 — auto loan:&lt;/strong&gt; loan $25,000, fees $500, term 60 months, payment $500.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APR = 8.275%   total paid = $30,000   interest + fees = $5,500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here $500 of fees adds about 0.85 of a point, far more than in the mortgage example, because the same fee dollars are recovered over 5 years of payments instead of 30. Small, short loans punish fees hardest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two mistakes the math warns you about&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Comparing APR to a note rate.&lt;/strong&gt; Compare APR to APR, on the same term. A 15-year APR and a 30-year APR are not rivals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring how long you will keep the loan.&lt;/strong&gt; APR assumes you keep it to the end. Sell or refinance after 5 years and upfront fees were spread over 5 years, not 30 — your real cost was higher than the APR suggested.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I maintain a free calculator that solves this equation and shows total cost next to the rate: &lt;a href="https://calcunit.net/loans/apr-calculator/" rel="noopener noreferrer"&gt;https://calcunit.net/loans/apr-calculator/&lt;/a&gt; (canonical: calcunit.net). Education only, not financial advice.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image: AI-generated image — two loan cards with the same percent symbol, one with fee coins stacked on top. Caption: "AI-generated image."&lt;/em&gt;&lt;/p&gt;

</description>
      <category>finance</category>
      <category>math</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How Much Can You Borrow With a HELOC? The CLTV Formula, Computed Step by Step</title>
      <dc:creator>CalcUnit</dc:creator>
      <pubDate>Tue, 01 Dec 2026 14:59:07 +0000</pubDate>
      <link>https://dev.to/calcunit/how-much-can-you-borrow-with-a-heloc-the-cltv-formula-computed-step-by-step-2c3c</link>
      <guid>https://dev.to/calcunit/how-much-can-you-borrow-with-a-heloc-the-cltv-formula-computed-step-by-step-2c3c</guid>
      <description>&lt;p&gt;A HELOC limit is not a guess. It is one formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;maxLine = homeValue × cltvCap − mortgageBalance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;homeValue&lt;/code&gt; = what the home is worth today&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cltvCap&lt;/code&gt; = the lender's combined loan-to-value cap (often 0.80–0.85)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mortgageBalance&lt;/code&gt; = what you still owe on the first mortgage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Worked example:&lt;/strong&gt; home worth $500,000, mortgage balance $300,000, cap 80%.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;maxLine = 500,000 × 0.80 − 300,000 = 400,000 − 300,000 = $100,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At an 85% cap the same house gives $125,000 — usually at a higher rate. The cap exists so a cushion of equity stays in the home.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The second formula people miss: two different payments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A HELOC has a draw period (often 10 years, interest-only) and then a repayment period (often 20 years, principal + interest). On a $50,000 balance at 8.5%:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drawPayment      = 50,000 × 0.085 / 12          = $354.17/month
repaymentPayment = PMT(0.085/12, 240, 50,000)   = $433.91/month
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same balance, same rate — the payment jumps about $80 a month when repayment starts, because each payment must now retire principal too. On the full $100,000 line the jump is roughly double. Lenders call this payment shock, and it is the most common way HELOC borrowers get into trouble.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two mistakes the math warns you about&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Budgeting on the draw payment.&lt;/strong&gt; Always check the repayment payment against your budget before you draw.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treating the rate as fixed.&lt;/strong&gt; Most HELOC rates are variable (prime + margin). Stress-test your numbers at +2%: the interest-only payment on $50,000 rises from $354.17 to $437.50.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I maintain a free calculator that shows every step — maximum line, CLTV, draw payment, repayment payment: &lt;a href="https://calcunit.net/loans/heloc-calculator/" rel="noopener noreferrer"&gt;https://calcunit.net/loans/heloc-calculator/&lt;/a&gt; (canonical: calcunit.net).&lt;/p&gt;

&lt;p&gt;AI-generated image.&lt;/p&gt;

</description>
      <category>finance</category>
      <category>math</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
