Suppose I draw randomly from a normal distribution with mean zero and standard deviation represented by a vector of, say, dimension 3 with
scale_rng=np.array([1,2,3])
eps=np.random.normal(0,scale_rng)
I need to compute a weighted average based on some simulations for which I draw the above mentioned eps
. The weights of this average are "the probability of eps
" (hence I will have a vector with 3 weights). For weighted average I simply mean an arithmetic sum wehere each component is multiplied by a weight, i.e. a number between 0 and 1 and where all the weights should sum up to one.
Such weighted average shall be calculated as follows: I have a time series of observations for one variable, x
. I calculate an expanding rolling standard deviation of x
(say this is the values in scale
). Then, I extract a random variable eps
from a normal distribution as explained above for each time-observation in x
and I add it to it, say obtaining y=x+eps
. Finally, I need to compute the weighted average of y
where each value of y
is weighted by the "probability of drawing each value of eps
from a normal distribution with mean zero and standard deviation equal to scale
.
Now, I know that I cannot think of this being the points on the pdf corresponding to the values randomly drawn because a normal random variable is continuous and as such the pdf at a certain point is zero. Hence, the only solution I Found out is to discretize a normal distribution with a certain number of bins and then find the probability that a value extracted with the code of above is actually drawn. How could I do this in Python?
EDIT: the solution I found is to use
norm.cdf(eps_it+0.5, loc=0, scale=scale_rng)-norm.cdf(eps_it-0.5, loc=0, scale=scale_rng)
which is not really based on the discretization but at least it seems feasible to me "probability-wise".
eps
from a normal and then further weighting by a normal PDF might be doing unexpected things to your estimates – Sam Masoneps
to build a weighted average but someone else, and I have to reproduce such results. Unfortunately I could not find any further help online – Matteo