Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Portfolio Random Walk Simulation | Portfolio and Pricing Toy-Simulations
Simulation and Monte Carlo Modeling with Python

bookPortfolio Random Walk Simulation

A random walk is a sequence of steps where each step is determined by chance, and the direction and size of each move are unpredictable. In portfolio modeling, you can use a random walk to represent how the value of a portfolio might evolve over time if each period's return is random and independent of previous returns. This approach helps you visualize the possible paths a portfolio's value could take and analyze cumulative returns, which is crucial for understanding risk and uncertainty in investments.

1234567891011121314151617181920212223
import numpy as np import matplotlib.pyplot as plt # Set simulation parameters np.random.seed(42) n_steps = 252 # Number of trading days in a year initial_value = 1000 # Starting portfolio value # Simulate daily returns as a normal random variable (mean=0, std=1%) daily_returns = np.random.normal(0, 0.01, n_steps) # Calculate cumulative returns (random walk) portfolio_values = initial_value * np.cumprod(1 + daily_returns) # Plot the results plt.figure(figsize=(10, 5)) plt.plot(portfolio_values, label="Simulated Portfolio Value") plt.title("Portfolio Value Random Walk Simulation") plt.xlabel("Day") plt.ylabel("Portfolio Value ($)") plt.legend() plt.grid(True) plt.show()
copy

The code begins by importing the required libraries and setting a random seed to ensure reproducibility. You specify the number of steps, representing trading days, and the initial portfolio value. The daily returns are simulated using a normal distribution with a mean of zero and a standard deviation of 1%, reflecting the idea that returns can be both positive and negative with no expected drift. Each day's portfolio value is calculated by multiplying the previous value by one plus the daily return, which models compounding. The np.cumprod function applies this compounding across all days, producing a simulated path for the portfolio's value. Finally, the code plots the resulting time series, allowing you to visualize how the random walk leads to fluctuations in the portfolio's cumulative return over time.

question mark

Which statement best describes the random walk model used in portfolio simulations?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookPortfolio Random Walk Simulation

Свайпніть щоб показати меню

A random walk is a sequence of steps where each step is determined by chance, and the direction and size of each move are unpredictable. In portfolio modeling, you can use a random walk to represent how the value of a portfolio might evolve over time if each period's return is random and independent of previous returns. This approach helps you visualize the possible paths a portfolio's value could take and analyze cumulative returns, which is crucial for understanding risk and uncertainty in investments.

1234567891011121314151617181920212223
import numpy as np import matplotlib.pyplot as plt # Set simulation parameters np.random.seed(42) n_steps = 252 # Number of trading days in a year initial_value = 1000 # Starting portfolio value # Simulate daily returns as a normal random variable (mean=0, std=1%) daily_returns = np.random.normal(0, 0.01, n_steps) # Calculate cumulative returns (random walk) portfolio_values = initial_value * np.cumprod(1 + daily_returns) # Plot the results plt.figure(figsize=(10, 5)) plt.plot(portfolio_values, label="Simulated Portfolio Value") plt.title("Portfolio Value Random Walk Simulation") plt.xlabel("Day") plt.ylabel("Portfolio Value ($)") plt.legend() plt.grid(True) plt.show()
copy

The code begins by importing the required libraries and setting a random seed to ensure reproducibility. You specify the number of steps, representing trading days, and the initial portfolio value. The daily returns are simulated using a normal distribution with a mean of zero and a standard deviation of 1%, reflecting the idea that returns can be both positive and negative with no expected drift. Each day's portfolio value is calculated by multiplying the previous value by one plus the daily return, which models compounding. The np.cumprod function applies this compounding across all days, producing a simulated path for the portfolio's value. Finally, the code plots the resulting time series, allowing you to visualize how the random walk leads to fluctuations in the portfolio's cumulative return over time.

question mark

Which statement best describes the random walk model used in portfolio simulations?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
some-alt