0
$\begingroup$

I would like to use geometric brownian motion (gbm) in order to generate artificial asset prices. I know that gbm has constant volatility, therefore I somehow converted it to stochastic in a very crude way which result in something different than gbm. Other than gbm, is there any algorithm or method for such purpose?

thanks!

import numpy as np
import math
import matplotlib.pyplot as plt
from random import random
import pandas as pd
plt.close('all')




time = 10000
no_of_reps = 5
volatility_arr = np.zeros([no_of_reps,time+1])

for k in range(0,no_of_reps):
    
    
    delta_t = 1/time
    s0 = 1000
    asset_prices = [s0]
    gbm_np_array = []
    gbm_mean = 0
    gbm_std = 0
    volatility = abs(np.random.normal(0.5,1,time))
    
    for i in range(0,time):
        
        drift = 0.1*(-1+2*random())
        dw = np.random.normal(0,math.sqrt(delta_t))
        
        ds = drift*delta_t*asset_prices[i] + volatility[i]*asset_prices[i]*dw
        asset_prices.append(asset_prices[i] + ds)
    
    gbm_np_array = np.asarray(asset_prices)
    for i in range(0,len(gbm_np_array)):
        gbm_mean = np.mean(gbm_np_array[i:i+50])
        gbm_std = np.std(gbm_np_array[i:i+50])
        volatility_arr[k,i] = (gbm_std/gbm_mean)
    
    
    
    
    x = plt.plot(np.arange(0,len(asset_prices)),asset_prices)
    plt.show()
    
```
$\endgroup$
2
  • $\begingroup$ Have a look at how to simulate stock prices from the Heston (1993) stochastic volatility model. This question could be a start. $\endgroup$ – Kevin Mar 18 at 11:47
  • $\begingroup$ Thanks Kevin, however I am looking for a more general approach as it is not based on some theorem. I mean, in Heston's model there is a correlation which I would not look for. I am just looking for some implementation of volatility and drift as they are random at each iteration while generating a new price data point $\endgroup$ – user3119264 Mar 18 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.