Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Plot Portfolio and Asset Growth | Investment Metrics and Portfolio Analysis
Python for Investors

bookChallenge: Plot Portfolio and Asset Growth

Tarea

Swipe to start coding

You are given a pandas DataFrame containing monthly returns for three assets and a portfolio. Your task is to:

  • Calculate cumulative returns for each asset and the portfolio, starting at 1.0 and using the cumulative product of (1 + monthly return) for each series.
  • Plot all four cumulative return series on a single chart using matplotlib.
  • Add clear labels for each line, include a legend, and add an informative chart title.
  • Visually highlight (e.g., with shading or annotation) any period where the portfolio's cumulative return is higher than all three individual assets.
  • Display the plot.

Use only the provided libraries and do not modify the DataFrame structure or values.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 5
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain this in simpler terms?

What are the main takeaways from this?

Can you give me a real-world example?

close

bookChallenge: Plot Portfolio and Asset Growth

Desliza para mostrar el menú

Tarea

Swipe to start coding

You are given a pandas DataFrame containing monthly returns for three assets and a portfolio. Your task is to:

  • Calculate cumulative returns for each asset and the portfolio, starting at 1.0 and using the cumulative product of (1 + monthly return) for each series.
  • Plot all four cumulative return series on a single chart using matplotlib.
  • Add clear labels for each line, include a legend, and add an informative chart title.
  • Visually highlight (e.g., with shading or annotation) any period where the portfolio's cumulative return is higher than all three individual assets.
  • Display the plot.

Use only the provided libraries and do not modify the DataFrame structure or values.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 5
single

single

some-alt