Challenge: Plot Portfolio and Asset Growth
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 5
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Suggested prompts:
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you give me a real-world example?
Fantastisk!
Completion rate forbedret til 4.76
Challenge: Plot Portfolio and Asset Growth
Sveip for å vise menyen
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 5
single