In [1]:
from pandas import Series, DataFrame
import pandas as pd
from numpy.random import randn
import numpy as np
pd.options.display.max_rows = 12
np.set_printoptions(precision=4, suppress=True)
import matplotlib.pyplot as plt
plt.rc('figure', figsize=(12, 6))
In [2]:
%matplotlib inline
In [5]:
close_px = pd.read_csv('stock_px.csv', parse_dates=True, index_col=0)
volume = pd.read_csv('volume.csv', parse_dates=True, index_col=0)
prices = close_px.ix['2011-09-05':'2011-09-14', ['AAPL', 'JNJ', 'SPX', 'XOM']]
volume = volume.ix['2011-09-05':'2011-09-12', ['AAPL', 'JNJ', 'XOM']]
In [6]:
prices
Out[6]:
In [7]:
volume
Out[7]:
In [8]:
prices * volume
Out[8]:
In [9]:
vwap = (prices * volume).sum() / volume.sum()
In [10]:
vwap
Out[10]:
In [11]:
vwap.dropna()
Out[11]:
In [12]:
prices.align(volume, join='inner')
Out[12]:
In [13]:
s1 = Series(range(3), index=['a', 'b', 'c'])
s2 = Series(range(4), index=['d', 'b', 'c', 'e'])
s3 = Series(range(3), index=['f', 'a', 'c'])
DataFrame({'one': s1, 'two': s2, 'three': s3})
Out[13]:
In [14]:
DataFrame({'one': s1, 'two': s2, 'three': s3}, index=list('face'))
Out[14]:
In [ ]: