Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda 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.

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 7
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you show me how to calculate the annualized return and standard deviation from this data?

How do I compute the Sharpe ratio for each portfolio using this example?

Can you explain why we use the square root of 12 for annualizing the standard deviation?

close

bookChallenge: Evaluate Portfolio Performance

Deslize para mostrar o 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.

Tarefa

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 7
single

single

some-alt