Skip to content

Instantly share code, notes, and snippets.

@MichaelWS
MichaelWS / dataSourcecsv.py
Created June 28, 2013 18:41
example datasource of zipline
"""
leverage work of briancappello and quantopian team
(especcially twiecki, eddie, and fawce)
"""
import pandas as pd
from zipline.gens.utils import hash_args
from zipline.sources.data_source import DataSource
import datetime
import csv
import numpy as np
@MichaelWS
MichaelWS / ptdump
Created December 16, 2013 01:02
ptdump for table
/ (RootGroup) ''
/._v_attrs (AttributeSet), 5 attributes:
[CLASS := 'GROUP',
FILTERS := Filters(complevel=9, complib='blosc', shuffle=True, fletcher32=False),
PYTABLES_FORMAT_VERSION := '2.1',
TITLE := '',
VERSION := '1.0']
/AR (Group) ''
/AR._v_attrs (AttributeSet), 15 attributes:
[CLASS := 'GROUP',
@MichaelWS
MichaelWS / gist:7981451
Created December 16, 2013 02:14
dataframe
In [7]: us_df.head(10)
Out[7]:
date close country currency high id \
0 1993-01-04 00:00:00 5.382715 US USD 5.432099 B00CQC-S-US
1 1993-01-04 00:00:00 10.708334 US USD 10.833334 B01573-S-US
2 1993-01-04 00:00:00 NaN US USD NaN B07H91-S-US
3 1993-01-04 00:00:00 912.500000 US USD 912.500000 B15R2H-S-US
4 1993-01-04 00:00:00 6.442701 US USD 6.735551 B28D82-S-US
5 1993-01-04 00:00:00 28.091904 US USD 28.210185 B2DTQ7-S-US
6 1993-01-04 00:00:00 12.049219 US USD 12.172170 B2F13F-S-US
in 0.12
ex_date Unnamed: 0 asset_type cusip name shares value form_type accepted period company_name cik sec_id end_date
0 2002-11-08 00:00:00 0 COM 281020107 EDISON INTERNATI 2792500 27925000 13F-HR 2002-11-08 00:00:00 2002-09-30 00:00:00 APPALOOSA MANAGEMENT LP 0001006438 N03TRC-S-US 2002-11-08 00:00:00
4 2002-11-08 00:00:00 4 COM 453235103 INAMED CORPCOM 3669359 84395000 13F-HR 2002-11-08 00:00:00 2002-09-30 00:00:00 APPALOOSA MANAGEMENT LP 0001006438 M89FLH-S-US 2002-11-08 00:00:00
5 2002-11-08 00:00:00 5 COM 494580103 KINDRED HEALTHCA 2475427 91665000 13F-HR 2002-11-08 00:00:00 2002-09-30 00:00:00 APPALOOSA MANAGEMENT LP 0001006438 P7KT40-S-US 2002-11-08 00:00:00
6 2002-11-08 00:00:00 6 042006 494580111 KINDRED HEALTHCA 720398 5064000 13F-HR 2002-11-08 00:00:00 2002-09-30 00:00:00 APPALOOSA MANAGEME
@MichaelWS
MichaelWS / ptdump_of_panel
Created December 16, 2013 23:46
ptdump of panels
/ (RootGroup) ''
/._v_attrs (AttributeSet), 5 attributes:
[CLASS := 'GROUP',
FILTERS := Filters(complevel=9, complib='blosc', shuffle=True, fletcher32=False),
PYTABLES_FORMAT_VERSION := '2.1',
TITLE := '',
VERSION := '1.0']
/AR (Group) ''
/AR._v_attrs (AttributeSet), 15 attributes:
[CLASS := 'GROUP',
@MichaelWS
MichaelWS / data
Created December 17, 2013 01:24
heads of each df
close country currency high id low open volume unadj_open unadj_close unadj_high unadj_low unadj_volume liq adj_factor dividend
date
1994-08-01 0.869021 AR ARS 0.878840 CD6N07-S-AR 0.849382 0 1344112.549706 0 1.7700 1.7900 1.7300 659922 NaN 0.490972 NaN
1994-08-01 2.279286 AR ARS 2.301203 D56641-S-AR 2.264676 0 1003886.791989 0 3.1200 3.1500 3.1000 733380 NaN 0.730541 NaN
1994-08-01 0.527021 AR ARS 0.527021 FBJJ92-S-AR 0.522788 0 1190121.444286 0 0.1245 0.1245 0.1235 5037900 NaN 4.233097 NaN
1994-08-01 38.766332 AR ARS 38.877729 J1DBW2-S-AR 38.543537 0 18402.566557
@MichaelWS
MichaelWS / terms traceback
Created December 18, 2013 03:02
pytables traceback
File "/usr/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py", line 637, in select
auto_close=auto_close).get_values()
File "/usr/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py", line 1311, in get_values
results = self.func(self.start, self.stop)
File "/usr/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py", line 626, in func
columns=columns, **kwargs)
File "/usr/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py", line 3749, in read
if not self.read_axes(where=where, **kwargs):
File "/usr/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py", line 3020, in read_axes
self.selection = Selection(self, where=where, **kwargs)
@MichaelWS
MichaelWS / gist:8186689
Created December 30, 2013 19:22
replace traceback
ValueError Traceback (most recent call last)
<ipython-input-2-b8fda0fafe55> in <module>()
2 ibm = web.DataReader("IBM", "yahoo", "1993/01/01").reset_index()
3 next_date_dict = dict(zip(ibm["Date"], ibm["Date"].shift()))
----> 4 ibm_next_date = ibm["Date"].replace(next_date_dict)
5 print (ibm_next_date == ibm["Date"]).all()
/local/install/pandas_test/lib/python2.7/site-packages/pandas/core/series.pyc in replace(self, to_replace, value, method, inplace, limit)
2838
2839 if isinstance(to_replace, dict):
@MichaelWS
MichaelWS / tail exception
Created January 4, 2014 14:55
tail exception
/usr/anaconda/lib/python2.7/site-packages/pandas-0.13.0_16_g2c8a8ef-py2.7-linux-x86_64.egg/pandas/core/generic.pyc in tail(self, n)
1570 if abs(n) > l:
1571 n = l if n > 0 else -l
-> 1572 return self.iloc[-n:]
1573
1574 #----------------------------------------------------------------------
/usr/anaconda/lib/python2.7/site-packages/pandas-0.13.0_16_g2c8a8ef-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in __getitem__(self, key)
1018 return self._getitem_tuple(key)
1019 else:
-> 302 pickle.load(open(cacs_file, 'rb'))
303
/usr/anaconda/lib/python2.7/site-packages/pandas-0.14.0_413_gf7822bd-py2.7-linux-x86_64.egg/pandas/core/internals.pyc in __setstate__(self, state)
2091 unpickle_block(values,
2092 self.axes[0].get_indexer(items))
-> 2093 for values, items in zip(bvalues, bitems))
2094
2095 self._post_setstate()