simulate the stock price by G-normal distribution established by Peng using python
时间: 2023-05-16 12:04:47 浏览: 62
Sure, I can help you with that. Peng's G-normal distribution is a statistical model that can be used to simulate stock prices. To implement this in Python, you can use the numpy and scipy libraries. Here's some sample code:
```python
import numpy as np
from scipy.stats import norm
def simulate_stock_price(S0, r, sigma, T, N, M):
dt = T / N
G = np.random.normal(size=(M, N))
S = np.zeros((M, N+1))
S[:,0] = S0
for i in range(1, N+1):
S[:,i] = S[:,i-1] * np.exp((r - 0.5*sigma**2)*dt + sigma*np.sqrt(dt)*G[:,i-1])
return S
# Example usage
S0 = 100
r = 0.05
sigma = 0.2
T = 1
N = 252
M = 10000
S = simulate_stock_price(S0, r, sigma, T, N, M)
```
This code simulates the stock price over a period of one year (252 trading days) using the G-normal distribution. The parameters S0, r, sigma, T, N, and M are the initial stock price, risk-free interest rate, volatility, time horizon, number of time steps, and number of simulations, respectively. The function returns a matrix S of size M x (N+1), where each row represents a simulated stock price path.