Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Visualizing Portfolio Performance | Investment Metrics and Portfolio Analysis
Python for Investors

bookVisualizing Portfolio Performance

Visualizing cumulative returns and portfolio growth is essential for investors who want to understand not just the final outcome of their investment decisions, but also the journey along the way. By plotting how the value of a portfolio and its individual assets change over time, you can quickly spot trends, periods of outperformance or underperformance, and the effects of diversification. These visualizations make it much easier to communicate investment results and to compare different strategies or assets.

1234567891011121314151617181920212223242526272829
import matplotlib.pyplot as plt import pandas as pd import numpy as np # Simulate daily returns for three assets and a portfolio np.random.seed(42) dates = pd.date_range("2022-01-01", periods=252) assets = { "Stock A": np.random.normal(0.0005, 0.01, size=252), "Stock B": np.random.normal(0.0003, 0.012, size=252), "Stock C": np.random.normal(0.0004, 0.009, size=252) } returns = pd.DataFrame(assets, index=dates) weights = np.array([0.4, 0.4, 0.2]) returns["Portfolio"] = returns.dot(weights) # Calculate cumulative returns cumulative = (1 + returns).cumprod() - 1 # Plot cumulative returns plt.figure(figsize=(10, 6)) for col in cumulative.columns: plt.plot(cumulative.index, cumulative[col], label=col) plt.title("Cumulative Returns: Portfolio vs. Assets") plt.xlabel("Date") plt.ylabel("Cumulative Return") plt.legend() plt.tight_layout() plt.show()
copy

When you look at a cumulative return chart like the one above, you are seeing how much each asset and the portfolio have grown, relative to their starting value, over time. The lines show the compounded effect of daily returns, so a steady upward slope indicates consistent growth, while dips reveal drawdowns or periods of loss. By comparing the portfolio's line to those of the individual assets, you can see whether diversification has reduced risk or boosted returns. If the portfolio line is smoother or higher than any single asset, it suggests effective risk management or smart asset selection.

123456789101112131415161718192021222324252627
# Highlight and annotate key periods on the cumulative return chart plt.figure(figsize=(10, 6)) for col in cumulative.columns: plt.plot(cumulative.index, cumulative[col], label=col) # Highlight a period of strong growth plt.axvspan("2022-03-01", "2022-04-15", color="yellow", alpha=0.2, label="Growth Period") # Annotate the maximum point of the portfolio max_date = cumulative["Portfolio"].idxmax() max_value = cumulative["Portfolio"].max() plt.annotate( "Portfolio Peak", xy=(max_date, max_value), xytext=(max_date, max_value + 0.05), arrowprops=dict(arrowstyle="->", color="black"), fontsize=10, color="black" ) plt.title("Cumulative Returns with Highlights and Annotations") plt.xlabel("Date") plt.ylabel("Cumulative Return") plt.legend() plt.tight_layout() plt.show()
copy

1. What does a cumulative return chart show?

2. Why might an investor compare portfolio growth to individual asset growth?

3. Which matplotlib function is used to add annotations to a plot?

question mark

What does a cumulative return chart show?

Select the correct answer

question mark

Why might an investor compare portfolio growth to individual asset growth?

Select the correct answer

question mark

Which matplotlib function is used to add annotations to a plot?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4

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 explain how to interpret the highlighted and annotated areas on the chart?

What other types of events or periods could I highlight on a cumulative return chart?

How can I customize the appearance of the annotations and highlights?

bookVisualizing Portfolio Performance

Deslize para mostrar o menu

Visualizing cumulative returns and portfolio growth is essential for investors who want to understand not just the final outcome of their investment decisions, but also the journey along the way. By plotting how the value of a portfolio and its individual assets change over time, you can quickly spot trends, periods of outperformance or underperformance, and the effects of diversification. These visualizations make it much easier to communicate investment results and to compare different strategies or assets.

1234567891011121314151617181920212223242526272829
import matplotlib.pyplot as plt import pandas as pd import numpy as np # Simulate daily returns for three assets and a portfolio np.random.seed(42) dates = pd.date_range("2022-01-01", periods=252) assets = { "Stock A": np.random.normal(0.0005, 0.01, size=252), "Stock B": np.random.normal(0.0003, 0.012, size=252), "Stock C": np.random.normal(0.0004, 0.009, size=252) } returns = pd.DataFrame(assets, index=dates) weights = np.array([0.4, 0.4, 0.2]) returns["Portfolio"] = returns.dot(weights) # Calculate cumulative returns cumulative = (1 + returns).cumprod() - 1 # Plot cumulative returns plt.figure(figsize=(10, 6)) for col in cumulative.columns: plt.plot(cumulative.index, cumulative[col], label=col) plt.title("Cumulative Returns: Portfolio vs. Assets") plt.xlabel("Date") plt.ylabel("Cumulative Return") plt.legend() plt.tight_layout() plt.show()
copy

When you look at a cumulative return chart like the one above, you are seeing how much each asset and the portfolio have grown, relative to their starting value, over time. The lines show the compounded effect of daily returns, so a steady upward slope indicates consistent growth, while dips reveal drawdowns or periods of loss. By comparing the portfolio's line to those of the individual assets, you can see whether diversification has reduced risk or boosted returns. If the portfolio line is smoother or higher than any single asset, it suggests effective risk management or smart asset selection.

123456789101112131415161718192021222324252627
# Highlight and annotate key periods on the cumulative return chart plt.figure(figsize=(10, 6)) for col in cumulative.columns: plt.plot(cumulative.index, cumulative[col], label=col) # Highlight a period of strong growth plt.axvspan("2022-03-01", "2022-04-15", color="yellow", alpha=0.2, label="Growth Period") # Annotate the maximum point of the portfolio max_date = cumulative["Portfolio"].idxmax() max_value = cumulative["Portfolio"].max() plt.annotate( "Portfolio Peak", xy=(max_date, max_value), xytext=(max_date, max_value + 0.05), arrowprops=dict(arrowstyle="->", color="black"), fontsize=10, color="black" ) plt.title("Cumulative Returns with Highlights and Annotations") plt.xlabel("Date") plt.ylabel("Cumulative Return") plt.legend() plt.tight_layout() plt.show()
copy

1. What does a cumulative return chart show?

2. Why might an investor compare portfolio growth to individual asset growth?

3. Which matplotlib function is used to add annotations to a plot?

question mark

What does a cumulative return chart show?

Select the correct answer

question mark

Why might an investor compare portfolio growth to individual asset growth?

Select the correct answer

question mark

Which matplotlib function is used to add annotations to a plot?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
some-alt