1 year ago
#376206
amitkumarpandey
How to run monte carlo similation in python within spacified upper and lower range of values?
I am trying to run Monte Carlo simulation for 520 weeks and 10000 trials. I am using the below code for the purpose.
my code:
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import norm
u=log_return.mean()
var=log_return.var()
drift=u-(0.5*var)
stdev=log_return.std()
weeks=520
trials=10000
z=norm.ppf(np.random.rand(weeks,trials))
weekly_returns=np.exp(drift+stdev * z)
price_paths=np.zeros_like(weekly_returns)
price_paths[0]=data2.iloc[-1]
for t in range(1,weeks):
price_paths[t]=(price_paths[t-1]*weekly_returns[t])
What I want to do is to set upper cut (bound) and lower cut (bound) so that the simulated values remain within these range.
for example: if a series is to have lower bound as 10 and upper as 100, it means, the entire series values will lie within 10 and 100 (both inclusive).
Can it be done?
python
pandas
numpy
simulation
montecarlo
0 Answers
Your Answer