Bonds for Developers: What Fixed Income Actually Does in a Portfolio
A practical literacy guide to bonds, duration, and why fixed income plays a specific role in a portfolio — written for developers who already understand stock-index investing.
If you already own a total-market index fund, you probably understand the basic mechanics: buy a slice of many companies, accept volatility, collect long-run growth. Bonds are different enough that the same intuition breaks down in places. They are not just a “safer stock.” They have their own mechanics, their own failure modes, and a specific job in a portfolio that is worth understanding precisely — especially because that job becomes more relevant as you approach a point in time when you actually need the money.
What a Bond Actually Is
A bond is a loan. When a government or company needs capital, one way it raises funds is by issuing bonds — formal IOUs that promise to pay the holder a fixed interest rate (the coupon) at regular intervals and to return the original loan amount (the principal or face value) at a specified future date (maturity). Buy a 10-year Treasury bond with a $1,000 face value and a 4% annual coupon, and you are lending the U.S. government $1,000, collecting $40 per year for ten years, and getting your $1,000 back at the end.
That is the contractual structure. The market complication is that bonds trade on secondary markets between issuance and maturity, which means their price fluctuates — and the key driver of that price movement is interest rates.
The Inverse Relationship: Rates and Prices
This is the part that trips people up most. When interest rates rise, bond prices fall. When rates fall, prices rise. The logic is straightforward once you see it: if you hold a bond paying a 4% coupon and new bonds are now being issued at 5%, your 4% bond is less attractive. Buyers will only purchase it at a discount — a lower price — so the effective yield to a new buyer matches what the market currently offers. The coupon payment is fixed; the price adjusts to make the math work out.
To make this concrete with an illustrative number: imagine (purely for illustration) a bond with a face value of $1,000, a 4% annual coupon, and five years to maturity. If market rates rise by one percentage point, the price of that bond might fall to roughly $957 — a loss of about 4.3% on paper. Those numbers are approximate and depend on the exact structure, but the direction is always the same: rates up, price down.
Duration is the concept that measures this sensitivity. Duration (expressed in years) tells you approximately how much a bond’s price will change for a 1% move in interest rates. A bond with a duration of 7 means a 1% rise in rates causes roughly a 7% drop in price. Longer-maturity bonds have higher duration — they are more sensitive to rate changes — because you are locked into their cash flows for longer. Short-term bonds have low duration and are much less sensitive to rate swings.
The Risks You Are Actually Taking
Holding bonds means taking on several distinct risks, and conflating them leads to muddled thinking.
Interest-rate risk is the price sensitivity described above. It is the dominant risk for high-quality government bonds. If you hold to maturity, you get your principal back regardless of interim price swings — but if you need to sell before maturity, you are exposed. Bond funds never mature, so this risk is always present.
Credit risk (also called default risk) is the chance the issuer cannot pay. A U.S. Treasury is treated as essentially zero credit risk — the U.S. government has never defaulted on domestic-currency debt. Investment-grade corporate bonds carry some credit risk; the issuer is a company that can fail. High-yield bonds (sometimes called junk bonds) carry substantially more — they typically offer higher coupons as compensation, but you are accepting real default probability in exchange. Ratings agencies (Moody’s, S&P, Fitch) assign letter grades that summarize their credit assessment, though those ratings are imperfect and lagged.
Inflation risk is the one that gets less airtime but is worth understanding clearly. A bond promises a fixed nominal payment. If inflation runs higher than expected over the bond’s life, the real purchasing power of those payments erodes. A 3% coupon in a 5% inflation environment means you are losing ground in real terms. Treasury Inflation-Protected Securities (TIPS) adjust the principal for inflation, which addresses this — but that is a detail for another article.
What Bonds Actually Do in a Portfolio
Here is where a lot of writing on bonds oversimplifies: bonds are not primarily in a portfolio to generate returns. For a long-horizon investor, the expected return on bonds is lower than stocks over decades. You hold bonds because of what they do to the portfolio’s behavior.
Volatility dampener. A portfolio that is 100% equities can draw down 40–50% in a severe bear market. Adding bonds typically reduces that drawdown, because bonds — particularly government bonds — have historically held their value or risen when equities fell sharply. The 2008 financial crisis is the textbook example: long-duration Treasuries were a rare positive in a sea of red.
Dry powder for rebalancing. When equities fall hard, having bonds means you can rebalance — sell bonds, buy equities at lower prices — without having to inject fresh cash. This is a systematic way to buy low, enforced by the portfolio structure.
Buffer to draw from instead of selling stocks in downturns. This is the clearest argument for bonds as you approach a period of active spending. If you retire or need to start withdrawing and the market drops 40% in year one, you face sequence-of-returns risk: selling depreciated assets locks in losses and permanently impairs the portfolio. If you hold, say, two to three years of spending in bonds or short-term fixed income, you can live on that instead of selling stocks at the bottom. The stock portion has time to recover.
How to Hold Bonds: Individual Bonds vs. Funds
You can hold bonds directly (buying individual bonds through a brokerage) or through bond mutual funds and ETFs.
Individual bonds have a defined maturity. If you buy a five-year Treasury and hold to maturity, you get your principal back and experience the coupon payments as stated. Price volatility exists in the interim, but you can largely ignore it if you do not need to sell.
Bond funds pool many bonds together, which provides diversification across issuers and maturities, and makes it easy to hold small positions. The tradeoff is that a bond fund has no maturity date — it perpetually rolls over its holdings. That means the interest-rate risk is always present; there is no “wait it out” option the way there is with an individual bond. If you need the money in three years, a long-duration bond fund is not the same as a bond maturing in three years.
ETFs like broad aggregate bond index funds give you exposure to the overall investment-grade bond market in one ticker. They are cheap and liquid. What they cannot give you is the certainty of getting a fixed sum back on a fixed date.
When and Why Developers Might Hold (or Not Hold) Bonds
If you are 28, employed, still accumulating, and have a 30-year horizon, the argument for holding significant fixed income is weak. Your human capital — future earnings — functions a bit like a bond: it is a relatively predictable stream of payments. Adding bonds to your investment portfolio on top of that may be redundant diversification. The opportunity cost of underweighting equities over a 30-year horizon is real.
The calculus changes as you approach a goal. If you are saving for a house purchase in three years, holding that money in stocks exposes you to a sequence-of-returns problem — the market could be down 40% when you need the cash. Short-duration fixed income or even a high-yield savings account makes more sense than equities for near-term goals.
For retirement savings, the conventional wisdom is to gradually shift toward more bonds as you approach and enter retirement — not because bonds outperform, but because the withdrawal phase makes sequence-of-returns risk concrete and painful in a way the accumulation phase does not.
A note on caveats: Everything here is educational. The illustrative numbers are chosen for clarity, not precision — actual bond pricing depends on exact coupon, maturity, and market conditions. Nothing in this article is a recommendation to buy or sell any specific security or to adopt any particular asset allocation. Your situation — income stability, tax context, risk tolerance, time horizons — determines what is right for you, and that is a conversation for a licensed financial advisor who knows your circumstances.
FAQ
If I hold a bond fund long enough, will I always get my money back? +
Why did both stocks and bonds fall together in 2022? +
Is a high-yield savings account a substitute for bonds in a portfolio? +
Related reading
2026-05-21
Brokerage APIs for Algorithmic Trading: Alpaca, Interactive Brokers, and Tradier Compared
A developer-focused comparison of Alpaca, IBKR, and Tradier brokerage APIs — auth, paper trading, order types, rate limits, and honest caveats.
2026-05-21
Building a Stock Screener: From Data Source to a Ranked List
A pipeline-focused engineering guide to building a stock screener: universe selection, data sources, ranking metrics, storage, and the pitfalls that quietly break each stage.
2026-05-21
Dollar-Cost Averaging vs Lump-Sum Investing: What the Data Actually Says
Historical data favors deploying a lump sum immediately, but DCA reduces regret and worst-case outcomes. Here is how to think through the tradeoff rigorously.
2026-05-21
Expense Ratios: The Quiet Fee That Compounds Against You
Expense ratios are deducted silently from your fund every day. A worked 30-year example shows how even a 1% annual fee erodes a meaningful fraction of your ending balance.
2026-05-21
Portfolio Rebalancing: When and How Often It Actually Matters
Evidence on portfolio rebalancing frequency: why it is primarily a risk-control tool, how drift works, and what the research actually says about costs and timing.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.