def testUniqueIndex(self): with recorder.open_store(mode='a') as store: for key in store.keys(): df = store[key] self.assertEqual(len(df.index.unique()), len(df.index), msg=key)
def testAppend(self): path = 'data/test.hdf' # First open and close fst_df = pd.DataFrame(data={'a': [0, 1], 'b': [2, 3]}) with recorder.open_store(path) as hdf_store: hdf_store['fst'] = fst_df
# Engine connect to MySQL sa_url = 'sqlalchemy.url' mysql_url, dbname = db_conf[sa_url].rsplit(sep='/', maxsplit=1) mysql_engine = sa.engine_from_config({sa_url: mysql_url}) create_fmt = 'CREATE DATABASE IF NOT EXISTS {dbname}' mysql_engine.execute(create_fmt.format(dbname=dbname)) # Engine connecting to MySQL database engine = sa.engine_from_config(db_conf) metadata = sa.MetaData() mkt_conf = config.read_markets() create_all(metadata, mkt_conf) metadata.create_all(engine) insert_config_data(engine) # Query market table. Does metadata drop and create the table? db_mkt_df = pd.read_sql_table(config.MARKETS, engine, index_col=config.ID) db_bundle_df = pd.read_sql_table(config.BUNDLES, engine, index_col=config.ID) db_asset_df = pd.read_sql_table(config.ASSETS, engine, index_col=config.ID) # TODO: Populate data markets = [contract.Market(mkt_nm) for mkt_nm in mkt_conf.keys()] with recorder.open_store('data/hist_iem.hdf') as hdf_store: for market in markets: mkt_hist_key = recorder.history_key(market) mkt_hist_df = hdf_store[mkt_hist_key]
def plot_cumsum(bundle_history_srs): cumsum_df = cumsum_frame(bundle_history_srs) # First trade index fst_trade_idx = (cumsum_df.sum(axis=1) > 0).idxmax() nonzero_cum_units_df = cumsum_df.loc[fst_trade_idx:] plt.figure(get_new_fignum()) plt.plot(nonzero_cum_units_df) plt.show() if __name__ == '__main__': mkt_name = 'FedPolicyB' mkt = contract.Market(mkt_name) with recorder.open_store(mode='r') as hdf_store: px_hist_df = hdf_store[recorder.history_key(market=mkt)] mkts_json = config.read_markets() mkt_conf = mkts_json[mkt_name] # Clean dataframe df = px_hist_df.copy().reset_index() # Expiry df[EXPIRY] = df[iem.CONTRACT].apply(expiry) # Expiry date expiry_date_json = mkt_conf[config.BUNDLE] kwargs = {'expiry_date_json': expiry_date_json} df[config.EXPIRY_DATE] = df[EXPIRY].apply(expiry_date_series, **kwargs) # Days to expiration df[DAYS_TO_EXPIRY_DATE] = df[config.EXPIRY_DATE] - df[iem.DATE]