File: moments_expw.py

package info (click to toggle)
pandas 0.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 54,924 kB
  • ctags: 53,113
  • sloc: python: 130,524; ansic: 11,510; sh: 329; makefile: 118
file content (35 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from moment_plots import *

np.random.seed(1)

ts = test_series(500) * 10

# ts[::100] = 20

s = ts.cumsum()

fig, axes = plt.subplots(3, 1, figsize=(8, 10), sharex=True)

ax0, ax1, ax2 = axes

ax0.plot(s.index, s.values)
ax0.set_title('time series')

ax1.plot(s.index, m.ewma(s, span=50, min_periods=1).values, color='b')
ax1.plot(s.index, m.rolling_mean(s, 50, min_periods=1).values, color='r')
ax1.set_title('rolling_mean vs. ewma')

line1 = ax2.plot(
    s.index, m.ewmstd(s, span=50, min_periods=1).values, color='b')
line2 = ax2.plot(
    s.index, m.rolling_std(s, 50, min_periods=1).values, color='r')
ax2.set_title('rolling_std vs. ewmstd')

fig.legend((line1, line2),
           ('Exp-weighted', 'Equal-weighted'),
           loc='upper right')
fig.autofmt_xdate()
fig.subplots_adjust(bottom=0.10, top=0.95)

plt.show()
plt.close('all')