def add_table(self, env_name, table_key, table_name, hash_name, hash_type='S', has_range=False, range_name=None, range_type='S'): (dbr, dbc, s3r, s3c, bucket) = self.init_aws_resources() DB = Client(dbc) tables = DB.list_tables() if "envs" not in tables: raise ValueError("You need to create envs table") table_envs = Table(dbr.Table(self.envs_table_name)) existing_envs = table_envs.scan() names = [e["name"] for e in existing_envs] if env_name in names: env = table_envs.get_item("name", env_name) db_dict = env["db_dict"] if table_name in db_dict.values(): raise ValueError("This table exists already") else: try: DB.create_table(table_name, hash_name, hash_type, has_range, range_name, range_type) except: print("unable to create table") db_dict[table_key] = table_name env["db_dict"] = db_dict table_envs.put_item(env) else: raise ValueError("This env does not exist")
def process_signal_all(ref_ticker, maturity_suffix): table_name = "signals" + "_" + ref_ticker + "_" + maturity_suffix DB = Client(dbc) list_tables = DB.list_tables() # create table if table_name not in list_tables: DB.create_table(table_name, "ticker", "S", True, "trade_date", "S") DB.add_index(table_name, "reverse", "trade_date", "S", "ticker", "S") signal_table = Table(dbr.Table(table_name)) #batch calc_signals selected_signals = select_signals(maturity_suffix, param_rviv.pct_prefix_list, param_rviv.median_prefix_list, param_rviv.proba_1_prefix_list) ref_data = query_rviv(ref_ticker) te_table = Table(dbr.Table(db_dict["vols_table"])) tickers = list(set([item["ticker"] for item in te_table.scan()])) for t in tickers: df = calc_signals(t, ref_data, selected_signals) #write them signal_table.put_df_batch(df)
def select_env(self, env_name): (dbr, dbc, s3r, s3c, bucket) = self.init_aws_resources() DB = Client(dbc) tables = DB.list_tables() if "envs" not in tables: raise ValueError("You need to create envs table") table_envs = Table(dbr.Table(self.envs_table_name)) existing_envs = table_envs.scan() names = [e["name"] for e in existing_envs] if env_name in names: env = table_envs.get_item("name", env_name) db_dict = env["db_dict"] return dbr, dbc, s3r, s3c, bucket, db_dict else: raise ValueError("You need to create this env")
def batch_write_ivs(): te_table = Table(dbr.Table(db_dict["vols_table"])) tickers = list(set([item["ticker"] for item in te_table.scan()])) for t in tickers: lw_date = get_last_written_date(t) write_ticker_iv_date(t, lw_date)