liveBook · Manning

Risk-free return

As explained in Investing for Programmers

The risk-free rate is the theoretical return on an investment with no default or uncertainty risk, commonly approximated by government security yields.

A risk-free return is the baseline return associated with an investment assumed to have no default or uncertainty risk. In practice, government security yields commonly approximate it, while black-swan events remain a qualification. section 7.6.1

Use the risk-free return as a comparison baseline:

  • Subtract it from portfolio returns when calculating excess return in the Sharpe ratio. section 7.6.1
  • Treat higher-risk assets as requiring higher expected returns than the risk-free baseline. section 7.6.1
  • Do not substitute the stock market’s historical average for the risk-free return. section 7.6.1

Treasury yield versus dividend yield

A 10-year US Treasury yield of about 4.3% in June 2025 provided a risk-free-return benchmark, compared with Apple’s approximately 0.49% dividend yield. The comparison shows why dividend income alone may not compensate for inflation or equity risk. section 1.2.1

Listing 7.4 Creating a Markowitz efficient portfolio
risk_free_rate = 0.0422

for i in range(num_portfolios):      #1
    weights = np.random.dirichlet(np.ones(num_assets), size=1).flatten()
    all_weights[i, :] = weights
    port_returns[i] = np.dot(weights, mean_returns)
    port_volatility[i] = np.sqrt(np.dot(weights.T, 
                                 np.dot(cov_matrix, weights)))
    sharpe_ratios[i] = (port_returns[i] - risk_free_rate) / port_volatility[i]
# 
max_sharpe_idx = np.argmax(sharpe_ratios)            #2
optimal_weights = all_weights[max_sharpe_idx, :]     #2

Insert a risk-free rate into portfolio analysis, calculate each portfolio’s Sharpe ratio, and select the simulated portfolio with the maximum value. section 7.6.1

How Investing for Programmers covers it

How deep it goes
Defines the rate, distinguishes it from market averages, and applies it in Sharpe-ratio portfolio calculations.
Examples
Compares a 10-year US Treasury yield with Apple’s dividend yield and uses a 4.22% rate in portfolio simulation.
What you can do after
Apply via Python by inserting a risk-free rate into Sharpe-ratio and efficient-portfolio calculations.
How it connects
Connects risk-free return to the Sharpe ratio, efficient frontier, and Markowitz-efficient portfolio.

Also explained in

Compare how 2 books explain risk-free return →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.