lab /python/pandas_ex.py

Language Python Lines 38
MD5 Hash 8146b5aa42181dca4081f5ffcf46184e Estimated Cost $491 (why?)
Repository https://bitbucket.org/jaredlander/lab.git View Raw File View Project SPDX
 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
import numpy as np
import pandas.io.data as web

def pct_change(x):
    return x / x.shift(1) - 1


stocks = ['AAPL', 'FB', 'GOOG']

st = '2012-1-1'
ed = '2012-9-29'

dd = {}

for s in stocks:
    dd[s] = web.get_data_yahoo(s, st, ed)['Adj Close']

from pandas import DataFrame

df = DataFrame(dd)
df
returns = df.pct_change()
returns = returns.dropna(how='all').sort_indx(ascending=False)

type(returns)

fb = return_arr[:, 1]
fb.std()

fb[::-1]
fb[::2]

fb_asc = fb[::-1]
fb_asc = aapl
Back to Top