An example of Monte Carlo simulation, this time for a financial application: estimating the future value of an investment portfolio based on random market returns.
### Example: Estimating Future Value of an Investment Portfolio
In this scenario, we have an initial investment amount, and we want to simulate the future value of the portfolio over a period of time. We assume the annual returns follow a normal distribution based on historical data (mean return and standard deviation).
#### Steps:
1. Start with an initial investment amount.
2. Each year, apply a random return based on a normal distribution (defined by mean and standard deviation).
3. Repeat the process for multiple simulations (e.g., 10,000 simulations).
4. Analyze the distribution of future values to understand the risk and potential outcomes of the portfolio.
Here’s a Python implementation:
```python
import numpy as np
import matplotlib.pyplot as plt
def monte_carlo_investment_simulation(initial_investment, mean_return, std_dev, years, num_simulations):
# Array to store final portfolio values
final_values = []
for _ in range(num_simulations):
portfolio_value = initial_investment
for _ in range(years):
# Simulate random annual return based on normal distribution
annual_return = np.random.normal(mean_return, std_dev)
# Update portfolio value
portfolio_value *= (1 + annual_return)
final_values.append(portfolio_value)
return np.array(final_values)
# Parameters for the simulation
initial_investment = 10000 # Initial investment
mean_return = 0.07 # 7% expected annual return
std_dev = 0.15 # 15% standard deviation in returns
years = 30 # Investment duration in years
num_simulations = 10000 # Number of simulations
# Run the Monte Carlo simulation
final_portfolio_values = monte_carlo_investment_simulation(initial_investment, mean_return, std_dev, years, num_simulations)
# Plot the results
plt.hist(final_portfolio_values, bins=50, color='skyblue', edgecolor='black')
plt.title('Distribution of Portfolio Value after 30 Years')
plt.xlabel('Portfolio Value')
plt.ylabel('Frequency')
plt.show()
# Basic statistics of the outcomes
mean_value = np.mean(final_portfolio_values)
median_value = np.median(final_portfolio_values)
percentile_5 = np.percentile(final_portfolio_values, 5)
percentile_95 = np.percentile(final_portfolio_values, 95)
mean_value, median_value, percentile_5, percentile_95
```
#### Explanation:
1. Initial Investment: We start with a defined initial investment (`$10,000` in this example).
2. Return Simulation: For each year, we generate a random return using the normal distribution with a mean of 7% and a standard deviation of 15%.
3. Monte Carlo Simulations: We run multiple simulations (10,000) to estimate the range of possible future portfolio values.
4. Analysis: We plot the distribution of future portfolio values and calculate basic statistics (mean, median, 5th percentile, and 95th percentile) to understand the outcomes.
This Monte Carlo simulation provides insights into how the portfolio might perform over time under different market conditions.

No comments:
Post a Comment