T-Bill Ladders for Developers: Automating a Cash Management Strategy in Python
How I model and run a Treasury bill ladder for emergency funds and business cash — yield vs HYSA, TreasuryDirect vs brokerage, auto-roll, the state-tax-exempt angle, and a small Python model you can copy.
I keep about six months of expenses in cash, plus a separate pile of business operating money I don’t touch between quarterly tax payments. For years that money sat in a high-yield savings account earning whatever the bank felt like paying that month, which is to say: less than the bank earned lending it out. Sometime in 2023 I did the math on what I was leaving on the table and switched the bulk of it into a Treasury bill ladder. I’ve run that ladder through three different rate regimes since, including the cuts that started rolling through in late 2024, and it has done exactly what I wanted: paid me a little more than the bank, kept the money government-backed, and stayed liquid enough that I never lay awake about it.
This is a guide for developers who have a cash position they want to manage deliberately rather than passively. If you can write a for-loop and read a yield curve, you can run a T-bill ladder. I’ll explain what the instrument actually is, why laddering beats lump-sum buying, where to hold it, the tax wrinkle that makes Treasuries quietly better than they look, and a small Python model you can adapt to size your own ladder. I’ll also be honest about when this is the wrong move.
What a T-bill actually is
A Treasury bill is a short-term debt obligation of the U.S. federal government, issued in maturities of 4, 8, 13, 17, 26, and 52 weeks. Bills don’t pay a coupon. You buy them at a discount to face value and they mature at face value, and the difference is your return. Buy a 26-week bill at $987.50 with a $1,000 face value and you collect $1,000 at maturity — that $12.50 is the interest, even though no “interest payment” ever lands in your account.
The yield is set at auction. The Treasury runs regular auctions (weekly for the shorter bills, every four weeks for the 52-week), and the auction clears at a rate driven by demand. When you buy at auction you take the auction yield; when you buy on the secondary market through a brokerage you take whatever the market is pricing at that moment. For cash management purposes the practical point is this: bills track short-term rates closely, so their yield moves with what the Fed is doing, which is the whole reason they tend to keep pace with — and usually slightly beat — a high-yield savings account.
The credit risk is, for practical purposes, zero. These are direct obligations of the U.S. Treasury. The risk you’re actually taking is reinvestment risk: when your bill matures, the rate you can get on the next one might be lower than what you just earned. That is precisely the risk a ladder is built to manage.
Why a ladder instead of one big bill
If you put your entire cash position into a single 52-week bill, two bad things can happen. First, all of it is locked into one rate for a year — great if rates fall right after you buy, painful if they rise. Second, if you need cash in month three, you have to sell that bill on the secondary market, possibly at a loss if rates moved against you, and pay a spread to do it.
A ladder fixes both. You split the money across several maturities — say 4, 8, 13, 26, and 52 weeks — so a rung is always coming due soon, and when each rung matures you roll it back out to the long end of the ladder. The effect is a portfolio with a blended yield somewhere between the short and long rates, with something maturing every few weeks for liquidity, and with reinvestment spread out over time so no single rate decision dominates your outcome. You’re dollar-cost-averaging across the yield curve.
The practical liquidity profile matters for an emergency fund. With a five-rung ladder, on any given month you’re rarely more than a few weeks from a scheduled maturity, and the shortest rung gives you a near-term exit without ever selling on the secondary market. You give up the instant-access nature of a savings account, but in exchange you get a meaningfully better-defined yield and a structure that survives rate cuts gracefully.
TreasuryDirect vs buying bills in a brokerage
There are two places to hold this, and the choice has real ergonomic consequences.
TreasuryDirect is the government’s own platform. You buy bills at auction directly, with zero fees, no markup, no middleman. The yield you get is the clean auction yield. The downsides are the experience: the site is a relic, the UI is from another era, linking a bank account can be slow, and — the big one — selling a bill before maturity is genuinely awkward (you have to transfer it out to a broker first). It does have an auto-roll feature called “Schedule Reinvestments” that will automatically reinvest a maturing bill into the next auction of the same term, which is the closest thing to set-and-forget the platform offers.
A brokerage (Fidelity, Schwab, Vanguard, and others) lets you buy bills both at auction and on the secondary market, usually with no commission on Treasuries bought at auction. The experience is dramatically better: real interfaces, instant visibility into your whole ladder, the ability to sell a bill mid-flight in seconds if you genuinely need the cash, and consolidated tax reporting. Many brokers also offer auto-roll on auction purchases. The tradeoff is that secondary-market purchases carry a bid-ask spread, and you have to trust the broker’s plumbing.
For most developers I’d point at a brokerage. The liquidity and the consolidated view are worth more than the few basis points TreasuryDirect saves you, and the ability to actually sell a rung in an emergency is the difference between a real emergency fund and a theoretical one. Use TreasuryDirect if you’re allergic to brokers or buying I-bonds (which live only there).
| Tool | Venue | Fees | Mid-term selling | Best for |
|---|---|---|---|---|
| TreasuryDirect Best for Buy-and-hold purists, I-bond buyers | None — clean auction yield | Awkward (must transfer to a broker) | ||
| Brokerage (auction) Best for Most cash-management ladders | Usually $0 on auction buys | Easy — sell on secondary in seconds | ||
| Brokerage (secondary) Best for Filling odd maturities or buying off-auction | Small bid-ask spread | Easy — full liquidity |
The tax wrinkle that makes Treasuries quietly better
Here is the part people miss. Interest from Treasury bills is exempt from state and local income tax. It’s fully taxable at the federal level, but your state can’t touch it. A high-yield savings account, by contrast, is taxed at both federal and state level.
That exemption is worth real money if you live somewhere with a meaningful state income tax. To compare a T-bill yield against a savings account honestly, you have to gross up the bill’s yield by your state tax savings — the “taxable-equivalent yield.” Roughly, the equivalent yield is the bill’s yield divided by (1 minus your state marginal rate). If you’re in a state with a 9% income tax and a savings account and a bill both nominally pay the same rate, the bill is the clearly better deal after tax, because that last slice of the savings-account interest goes to the state and the bill’s doesn’t. If you live in a no-income-tax state, this whole paragraph doesn’t apply to you and the comparison is just nominal yield against nominal yield.
One reporting note: the discount income on a bill is reported on Form 1099-INT in the year the bill matures, in the box for Treasury interest, so it flows through your return cleanly. Keep your brokerage’s year-end statements; the math is done for you there.
A small Python model for sizing your ladder
You don’t need a library for this. Here’s a compact model that takes a cash amount and a set of current bill yields, splits the money evenly across the rungs, computes the blended yield, and prints the reinvestment schedule so you can see when each rung comes due. Plug in real yields from the latest auction results or your broker’s quote screen.
from datetime import date, timedelta
# Current annualized yields per maturity (decimals). Replace with real quotes.rungs = { "4-week": 0.0440, "8-week": 0.0438, "13-week": 0.0435, "26-week": 0.0430, "52-week": 0.0425,}weeks = {"4-week": 4, "8-week": 8, "13-week": 13, "26-week": 26, "52-week": 52}
cash = 50_000per_rung = cash / len(rungs) # equal-weight each rungstart = date.today()
print(f"Ladder: ${cash:,.0f} across {len(rungs)} rungs " f"(${per_rung:,.0f} each)\n")
blended = 0.0for name, y in rungs.items(): matures = start + timedelta(weeks=weeks[name]) # discount-style interest earned over the bill's life interest = per_rung * y * (weeks[name] / 52) blended += y / len(rungs) print(f"{name:8} yield {y:6.3%} matures {matures} " f"interest ${interest:7,.2f}")
print(f"\nBlended annualized yield: {blended:.3%}")
# Taxable-equivalent yield vs a savings account, given a state marginal ratestate_rate = 0.093 # your state marginal income tax; 0.0 if nonete_yield = blended / (1 - state_rate)print(f"Taxable-equivalent yield (state {state_rate:.1%}): {te_yield:.3%}")Run it and you get a per-rung interest estimate, a blended yield, and the taxable-equivalent yield to compare against a savings account. The auto-roll logic is the easy part conceptually: when a rung matures, you reinvest the proceeds into a new bill at the longest rung’s term, which keeps the ladder’s shape intact and pushes that money back out to the end of the line. In practice you let your broker’s or TreasuryDirect’s reinvestment feature do this automatically rather than logging in every four weeks. The model’s job is to tell you the shape and the expected yield before you commit, not to execute trades.
A caveat on the interest math: this uses a simple linear approximation of discount yield, which is close enough for sizing decisions but isn’t the exact discount-vs-investment-rate convention the Treasury uses. Don’t use these numbers for your taxes — use the broker’s 1099.
Who should run a T-bill ladder
This is a good fit if you have a cash position you genuinely won’t need to spend in the next few weeks: an emergency fund, a house down payment a year out, business operating cash between tax payments, a sabbatical fund. It’s especially worth it if you live in a high-tax state, because the state-tax exemption widens the gap over a savings account.
It’s a bad fit for money you might need tomorrow — keep your true checking buffer in checking. It’s also less compelling if you’re in a no-income-tax state and your bank’s HYSA is already paying a competitive rate, because then you’re trading liquidity for a thin margin. And it’s the wrong tool for long-term growth: bills are cash management, not investing. If your time horizon is five-plus years, that money belongs in a diversified portfolio inside a tax-advantaged account, not a bill ladder. (If you want the mechanics of building that longer-horizon side, our fixed-income and tax-advantaged-account guides cover where bonds and bond funds fit, and how to use the tax shelters first.)
The honest summary: a ladder is a deliberate, low-effort way to make idle cash work a little harder with essentially no credit risk. The edge is modest and rate-dependent. If you’re the kind of developer who already automates the boring parts of your life, this fits right in — model it, build the rungs, turn on auto-roll, and check the curve once a quarter.
FAQ
Is a T-bill ladder safer than a high-yield savings account?+
How much money do I need to start a ladder?+
What happens to my ladder when interest rates fall?+
Do I pay state income tax on T-bill interest?+
Can I sell a T-bill before it matures if I need the cash?+
Related reading
2026-06-04
Building a Crypto Trading Bot With CCXT in Python: From API Keys to Live Orders
A hands-on Python guide to CCXT — installing the library, generating testnet keys, fetching OHLCV and order books, coding an SMA crossover signal, placing orders, and surviving rate limits before you risk real money.
2026-06-04
Financial Modeling Prep vs Sharadar: Fundamental Data APIs for Quant Backtests
I rebuilt the same equity backtest on Financial Modeling Prep and Sharadar's SF1 to see which fundamental data source you can actually trust. The difference comes down to point-in-time data — and it decides whether your backtest is real or a fantasy.
2026-06-04
SnapTrade vs Plaid Investments: Brokerage Aggregation APIs for Fintech Builders
A hands-on developer comparison of SnapTrade and Plaid Investments — trade execution vs read-only holdings, broker coverage, auth flows, data freshness, and pricing for fintech builders in 2026.
2026-06-04
Walk-Forward Optimization in Python: The Backtest Validation Step Everyone Skips
A hands-on guide to walk-forward optimization in Python — why a single train/test split lies to you, how rolling and anchored windows work, and the robustness metrics that catch overfit strategies before they lose money.
2026-05-28
Alpha Vantage vs Yahoo Finance API: Free Market Data for Side Projects — An Honest Comparison
After building 8 side projects on both APIs, here's the real difference between Alpha Vantage's structured approach and Yahoo Finance's undocumented-but-free data pipeline.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.