NOTE: I'm trying to rewrite this Python function which is decorated to compile with Pythran into a Python module. It currently uses OpenMP fine but not SIMD. pythran -DUSE_XSIMD my-script.py
So the bounty is for rewriting a bit of Python code to take advantage of XSIMD + OpenMP... I think vectorizing the code segment will allow it to use SIMD so looking for a bit of help here. Here's what I have - you can find GBM stock price simulation code examples all over the internet BTW; this one is a bit tricky since it's multiple assets though:
#pythran export generate_paths(int, int, int, int, float64, float64, float64[:,:] order(C), float64[:,:,:] order(C))
import numpy as np
def generate_paths(N_assets, sims, Simulated_time_steps, timesteps, timestep, drift, CurrentVol, randnums3Dcorr):
Simulated_paths = np.zeros((N_assets, sims, Simulated_time_steps))
#omp parallel for
for i in range(Simulated_time_steps):
randnumscorr = randnums3Dcorr[:,:, i]
dt = np.array((timestep, timestep*2, timestep*3))
drift_component = np.multiply( drift - 0.5*CurrentVol**2, dt.reshape(dt.shape[0],1))
random_component = np.multiply(randnumscorr.T , np.multiply(CurrentVol.reshape(CurrentVol.shape[0],) , np.sqrt(dt) ))
Simulated_paths[:,:,i] = np.exp( drift_component.reshape(drift_component.shape[0],1) + random_component.T)
return Simulated_paths
# [NOTE] uncomment the below if you want to run it in Python...
#
# if __name__ == "__main__":
# N_assets = 3
# sims = 8192
# Simulated_time_steps = 20
# timesteps = 20
# timestep = 1/365
# drift = 0.0
# CurrentVol = np.array([0.5,0.4,0.3])
# CurrentVol = CurrentVol.reshape(CurrentVol.shape[0],1)
# randnums3Dcorr = np.random.rand(N_assets,sims,timesteps)
# Simulated_paths = generate_paths(N_assets, sims, Simulated_time_steps, timesteps, timestep, drift, CurrentVol, randnums3Dcorr)