Skip to content

Portfolio risk and return calculator

Enter weights, expected returns, volatilities and correlations. Get the portfolio's return, risk, Sharpe ratio and who contributes the risk.

How it works

Expected return is just the weighted average. Risk is not: portfolio variance depends on every pair of assets through their covariance, which is why combining assets that do not move together lowers risk.

Risk contribution splits the portfolio variance between the assets. An asset's share is its weight times its covariance with the whole portfolio, divided by total variance. These shares always add up to 100%, and they often look very different from the weights.

μp=∑iwiμi,σp2=w⊤Σ w,Σij=ρijσiσj\mu_p = \sum_i w_i \mu_i, \qquad \sigma_p^2 = w^\top \Sigma\, w, \qquad \Sigma_{ij} = \rho_{ij}\sigma_i\sigma_jRCi=wi(Σw)iσp2,Sharpe=μp−rfσp\text{RC}_i = \frac{w_i (\Sigma w)_i}{\sigma_p^2}, \qquad \text{Sharpe} = \frac{\mu_p - r_f}{\sigma_p}

Assumptions

  • All inputs are annual; returns are arithmetic expected returns.
  • Correlations must form a valid (positive semi-definite) matrix. The tool warns if they do not.
  • Weights may be negative (short) and need not sum to 100%. The rest is treated as cash earning nothing.
Show the codePython, runs in the playground
portfolio-risk-return-calculator.py
import numpy as np

w = np.array([0.60, 0.30, 0.10])
mu = np.array([0.07, 0.035, 0.04])
vol = np.array([0.16, 0.06, 0.15])
corr = np.array([[1.0, -0.2, 0.1],
                 [-0.2, 1.0, 0.3],
                 [0.1, 0.3, 1.0]])
rf = 0.02

cov = np.outer(vol, vol) * corr
ret = w @ mu
var = w @ cov @ w
contrib = w * (cov @ w) / var
print(f"Expected return: {ret:.6f}")
print(f"Volatility: {np.sqrt(var):.6f}")
print(f"Sharpe: {(ret - rf) / np.sqrt(var):.6f}")
print("Risk contributions:", contrib.round(4))

Questions

Why is my portfolio's volatility lower than the average volatility?

Because the assets are not perfectly correlated. Only with correlation of 1 everywhere would portfolio volatility equal the weighted average volatility.

What is a risk contribution?

The share of portfolio variance that comes from each asset, counting its interactions with the others. A 60/40 stock-bond portfolio typically gets over 90% of its risk from stocks.

What does the invalid correlation warning mean?

Some combinations of pairwise correlations are impossible. For example, A and B cannot both be strongly positively correlated with C and strongly negatively correlated with each other. Such a matrix can give a negative variance.

Where do the expected returns come from?

You supply them. They are the most uncertain input, and small changes move optimal weights a lot, which is why the course covers Black-Litterman.

Educational use only, not investment advice. Results depend on the model's assumptions listed above and on your inputs. Calculations run in your browser and nothing you enter is sent to a server.