Original data from https://s3.amazonaws.com/zanran_storage/www.etftopics.com/ContentPages/13968652.xls , modified and available locally as ETFs.csv .
This notebook only works in Quantopian Research, but one only needs to modify the loading of the file to work with it locally.
In [193]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as pyplot
import seaborn as sns
In [194]:
ETFs = local_csv('ETFs.csv', skipinitialspace=True,
na_values=['n/a','NaN'], thousands=',')
ETFs = ETFs.set_index('Symbol')
ETFs[:2]
Out[194]:
In [195]:
del ETFs['Top_Holdings']
del ETFs['Chart']
In [196]:
ETFs.columns
Out[196]:
In [197]:
def p2f(x):
if type(x) is str:
return float(x.strip('%'))/100
else:
return x / 100
def d2f(x):
if type(x) is str:
return float(x.strip('$').replace(',',''))
else:
return x
def s2b(x):
if type(x) is str:
if x == 'Yes':
return True
else:
return False
else:
return False
In [198]:
# Apply conversions
ETFs.Expense_Ratio = ETFs.Expense_Ratio.apply(p2f)
ETFs.Dividend = ETFs.Dividend.apply(d2f)
ETFs.Div_Yield = ETFs.Div_Yield.apply(p2f)
ETFs.Market_Cap = ETFs.Market_Cap.apply(d2f)
ETFs.Inverse = ETFs.Inverse.apply(s2b)
ETFs[:3]
Out[198]:
In [199]:
len(ETFs.index)
Out[199]:
In [223]:
ETFs.Category.value_counts()
Out[223]:
In [222]:
ETFs.Provider.value_counts()
Out[222]:
In [202]:
ETFs.Expense_Ratio.plot(kind='hist')
Out[202]:
In [203]:
ETFs.Dividend.plot(kind='hist', bins=20)
Out[203]:
In [204]:
ETFs.Div_Yield.plot(kind='hist', bins=20)
Out[204]:
In [205]:
ETFs.Market_Cap.plot(kind='hist',bins=40)
Out[205]:
In [221]:
ETFs.Asset.value_counts()
Out[221]:
In [220]:
ETFs.Size.value_counts()
Out[220]:
In [219]:
ETFs.Style.value_counts()
Out[219]:
In [209]:
ETFs.Beta.plot(kind='hist',bins=8)
Out[209]:
In [218]:
ETFs.Region.value_counts()
Out[218]:
In [217]:
ETFs.Sector.value_counts()
Out[217]:
In [216]:
ETFs.Leveraged.value_counts()
Out[216]:
In [215]:
ETFs.Inverse.value_counts()
Out[215]:
In [213]:
# http://www.etfreplay.com/
In [ ]:
# http://etfdb.com/etf/###
# http://finance.yahoo.com/q/hl?s=### ETF holdings
In [ ]:
# https://accounts.profunds.com/etfdata/ByFund/EFAD-psdlyhld.csv
# http://www.ishares.com/us/products/239709/ishares-russell-2000-growth-etf
In [ ]: