In [1]:
import scipy as sp, numpy as np, pandas as pd
from matplotlib import pyplot as plt
In [22]:
np.random.rand()
Out[22]:
In [39]:
stepsize = 1
numsteps = 100
position = []
x = 0
for i in range(numsteps):
number = np.random.rand()
if number < 0.5:
x = x - stepsize
else:
x = x + stepsize
position = position + [x]
# could have typed
# position.append(x)
In [40]:
plt.plot(position)
Out[40]:
In [41]:
pos = np.array(position)
In [34]:
np.average(pos)
Out[34]:
In [35]:
pos[-10]
Out[35]:
In [36]:
np.std(pos)
Out[36]:
In [42]:
df = pd.DataFrame(pos)
In [43]:
df.plot()
Out[43]:
In [44]:
df.rolling(window=10).mean().plot()
Out[44]:
In [45]:
roll = df.rolling(window=10)
In [46]:
m = roll.mean()
In [47]:
m.plot()
Out[47]:
In [ ]: