0

I am trying to create a function which will simulate a poison process for a changeable dt and total time, and have the following:

def compound_poisson(lamda,mu,sigma,dt,T):

points = pd.Series(0)
out = pd.Series(0)
inds = simple_poisson(lamda,dt,T)

for ind in inds.index:
    
    if inds[ind+dt] > inds[ind]:
        points[ind+dt] = np.random.normal(mu,sigma)
        
    else:
        points[ind+dt] = 0
        
out = out.append(np.cumsum(points),ignore_index=True)

out.index = np.linspace(0,T,int(T/dt + 1))

return out

However, I receive a "KeyError: 0.010000000000000002", which should not be in the index at all. Is this a result of being lax with float objects?

W M Seath
  • 113
  • 5

1 Answers1

0

In short, yes, it's a floating point error. It's quite hard to know how you got there, but probably something like this:

>>> 0.1 * 0.1
0.010000000000000002

Maybe use round?

Oin
  • 6,951
  • 2
  • 31
  • 55