Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Evaluate Portfolio Performance | Risk Analysis and Portfolio Optimization
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Financial Analysts

bookChallenge: Evaluate Portfolio Performance

The Sharpe ratio is a widely used metric to evaluate the risk-adjusted performance of an investment portfolio. It is calculated by subtracting the risk-free rate from the portfolio's return and then dividing this excess return by the portfolio's standard deviation (a measure of risk). A higher Sharpe ratio indicates better risk-adjusted performance, meaning the portfolio is delivering more return per unit of risk taken. This allows you to directly compare different portfolios, even if they have different levels of risk or return.

1234567891011121314
import pandas as pd # Example: Monthly returns (%) for four portfolios over one year data = { "Portfolio_A": [1.2, 0.8, 1.5, 1.1, 0.9, 1.3, 1.0, 1.4, 1.2, 0.7, 1.1, 1.3], "Portfolio_B": [0.9, 0.7, 1.0, 1.2, 1.0, 1.1, 0.8, 1.0, 0.9, 0.6, 0.8, 0.7], "Portfolio_C": [1.5, 1.3, 1.7, 1.6, 1.2, 1.8, 1.4, 1.6, 1.5, 1.1, 1.3, 1.5], "Portfolio_D": [0.6, 0.4, 0.7, 0.5, 0.3, 0.8, 0.6, 0.7, 0.5, 0.2, 0.4, 0.6], } returns_df = pd.DataFrame(data) # Risk-free rate (annual, in %) risk_free_rate = 2.0
copy

To compare portfolios on an annualized basis, you must annualize both the average return and the standard deviation calculated from monthly data. The annualized return is found by multiplying the average monthly return by 12. The annualized standard deviation is calculated by multiplying the standard deviation of monthly returns by the square root of 12. The Sharpe ratio is then computed as:

Sharpe ratio = (Annualized Return - Annual Risk-Free Rate) / Annualized Standard Deviation

This approach ensures that comparisons across portfolios are consistent and meaningful.

Task

Swipe to start coding

You are given monthly returns for four portfolios and an annual risk-free rate. Calculate the annualized Sharpe ratio for each portfolio, create a bar chart of the results, and print a summary identifying the best risk-adjusted performer.

  • Compute the mean of monthly returns for each portfolio.
  • Compute the standard deviation of monthly returns for each portfolio.
  • Calculate the annualized return for each portfolio.
  • Calculate the annualized standard deviation for each portfolio.
  • Compute the annualized Sharpe ratio for each portfolio.
  • Return a pandas Series with the Sharpe ratios.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 7
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Evaluate Portfolio Performance

Swipe to show menu

The Sharpe ratio is a widely used metric to evaluate the risk-adjusted performance of an investment portfolio. It is calculated by subtracting the risk-free rate from the portfolio's return and then dividing this excess return by the portfolio's standard deviation (a measure of risk). A higher Sharpe ratio indicates better risk-adjusted performance, meaning the portfolio is delivering more return per unit of risk taken. This allows you to directly compare different portfolios, even if they have different levels of risk or return.

1234567891011121314
import pandas as pd # Example: Monthly returns (%) for four portfolios over one year data = { "Portfolio_A": [1.2, 0.8, 1.5, 1.1, 0.9, 1.3, 1.0, 1.4, 1.2, 0.7, 1.1, 1.3], "Portfolio_B": [0.9, 0.7, 1.0, 1.2, 1.0, 1.1, 0.8, 1.0, 0.9, 0.6, 0.8, 0.7], "Portfolio_C": [1.5, 1.3, 1.7, 1.6, 1.2, 1.8, 1.4, 1.6, 1.5, 1.1, 1.3, 1.5], "Portfolio_D": [0.6, 0.4, 0.7, 0.5, 0.3, 0.8, 0.6, 0.7, 0.5, 0.2, 0.4, 0.6], } returns_df = pd.DataFrame(data) # Risk-free rate (annual, in %) risk_free_rate = 2.0
copy

To compare portfolios on an annualized basis, you must annualize both the average return and the standard deviation calculated from monthly data. The annualized return is found by multiplying the average monthly return by 12. The annualized standard deviation is calculated by multiplying the standard deviation of monthly returns by the square root of 12. The Sharpe ratio is then computed as:

Sharpe ratio = (Annualized Return - Annual Risk-Free Rate) / Annualized Standard Deviation

This approach ensures that comparisons across portfolios are consistent and meaningful.

Task

Swipe to start coding

You are given monthly returns for four portfolios and an annual risk-free rate. Calculate the annualized Sharpe ratio for each portfolio, create a bar chart of the results, and print a summary identifying the best risk-adjusted performer.

  • Compute the mean of monthly returns for each portfolio.
  • Compute the standard deviation of monthly returns for each portfolio.
  • Calculate the annualized return for each portfolio.
  • Calculate the annualized standard deviation for each portfolio.
  • Compute the annualized Sharpe ratio for each portfolio.
  • Return a pandas Series with the Sharpe ratios.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 7
single

single

some-alt