I have a python function:
pval = np.array([1,1,1,1,1,0.999709, 0.99973,0.999743,0.999706, 0.999675, 0.99965, 0.999629])
age1=4
age2=8
def getnpxtocert(mt, age, age2):
val = mt[age]
for i in range(age + 1,age2):
val = val * mt[i]
return val
getnpxtocertv(pval,age1,age2)
The output is:
0.9991822227268075
And then I tried to use cumprod to vectorize it:
def getnpxtocertv(mt, age, age2):
return (mt[age]*np.cumprod(mt[age+1:age2])).sum()
getnpxtocert(pval,age1,age2)
But the output is:
2.998330301296807
What did I wrong?Any friend can help?