def add_data_to_day_price(day_price: DataFrame, index_day_price: DataFrame) -> DataFrame: group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: group = group.reset_index(drop=True) group["sma_10"] = sma(group["close"], 10) group["increase_ratio_3"] = increase_from_lowest_price( group["low"], group["close"], 3) group["sma"] = sma(group["close"], 5) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: increase_condition = group["sma"] >= 0.1 # Result group["#result"] = increase_condition group["#priority"] = group["increase_ratio_3"].shift( 1) + group["increase_ratio_3"].shift(2) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) # Market Timing index_day_price["sma_3"] = sma(index_day_price["close"], 3) index_day_price["sma_5"] = sma(index_day_price["close"], 5) index_day_price["sma_10"] = sma(index_day_price["close"], 10) index_day_price["#market_timing"] = ( (index_day_price["close"] > index_day_price["sma_3"]) | (index_day_price["close"] > index_day_price["sma_5"]) | (index_day_price["close"] > index_day_price["sma_10"])) index_day_price = index_day_price.set_index("date") return day_price, index_day_price
def add_data_to_day_price(day_price: DataFrame, index_day_price: DataFrame) -> DataFrame: group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: group = group.reset_index(drop=True) group["sma_10"] = sma(group["close"], 10) group["increase_ratio_3"] = increase_from_lowest_price( group["low"], group["close"], 3) group["pdi_5"] = pdi(group["high"], group["low"], group["close"], 5, MovingAverage.ema) group["pdi_5_sto"] = stochastic_fast_k(group["pdi_5"], group["pdi_5"], group["pdi_5"], 20) group["pdi_5_sto_pct_change_3"] = pct_change(group["pdi_5_sto"], 3) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: increase_condition1 = (group["pdi_5_sto_pct_change_3"].shift(1) >= 0.1) | (group["pdi_5_sto_pct_change_3"].shift(2) >= 0.1) increase_condition = increase_condition1 # Result group["#result"] = increase_condition group["#priority"] = group["increase_ratio_3"].shift( 1) + group["increase_ratio_3"].shift(2) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) # Market Timing index_day_price["sma_3"] = sma(index_day_price["close"], 3) index_day_price["sma_5"] = sma(index_day_price["close"], 5) index_day_price["sma_10"] = sma(index_day_price["close"], 10) index_day_price["#market_timing"] = ( (index_day_price["close"] > index_day_price["sma_3"]) | (index_day_price["close"] > index_day_price["sma_5"]) | (index_day_price["close"] > index_day_price["sma_10"])) index_day_price = index_day_price.set_index("date") return day_price, index_day_price
def add_data_to_day_price(day_price: DataFrame, index_day_price: DataFrame) -> DataFrame: group_list = [] grouped = day_price.groupby("ticker") for key, group in grouped: group = group.reset_index(drop=True) group["sma_10"] = sma(group["close"], 10) group["sma_20"] = sma(group["close"], 20) group["sma_tr_val_5"] = sma(group["tr_val"], 5) group["ibs"] = ibs(group["high"], group["low"], group["close"]) group["increase_ratio_3"] = increase_from_lowest_price( group["low"], group["close"], 3) group["decrease_ratio_3"] = decrease_from_highest_price( group["high"], group["close"], 3) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("date") for key, group in grouped: group = group.reset_index(drop=True) group["rank_tr_val"] = rank(group["tr_val"]) group["rank_tr_val_5"] = rank(group["sma_tr_val_5"]) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("ticker") for key, group in grouped: # Condition1 increase_condition1 = (group["increase_ratio_3"].shift(1) >= 0.1) | ( group["increase_ratio_3"].shift(2) >= 0.1) increase_condition = increase_condition1 decrease_condition1 = (group["decrease_ratio_3"] < 0) & (group["decrease_ratio_3"] > -0.1) decrease_condition2 = group["ibs"] < 0.25 decrease_condition = decrease_condition1 & decrease_condition2 liquidity_condition1 = group["rank_tr_val_5"] > 0.8 liquidity_condition = liquidity_condition1 # Result group[ "#result"] = increase_condition & decrease_condition & liquidity_condition group["#priority"] = group["increase_ratio_3"] group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) # Market Timing index_day_price["sma_3"] = sma(index_day_price["close"], 3) index_day_price["sma_5"] = sma(index_day_price["close"], 5) index_day_price["sma_10"] = sma(index_day_price["close"], 10) index_day_price["#market_timing"] = ( (index_day_price["close"] > index_day_price["sma_3"]) | (index_day_price["close"] > index_day_price["sma_5"]) | (index_day_price["close"] > index_day_price["sma_10"])) index_day_price = index_day_price.set_index("date") return day_price, index_day_price
def add_data_to_day_price(day_price: DataFrame, index_day_price: DataFrame) -> DataFrame: group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: group = group.reset_index(drop=True) group["sma_10"] = sma(group["close"], 10) group["sma_20"] = sma(group["close"], 20) group["sma_tr_val_5"] = sma(group["tr_val"], 5) group["pct_change_1"] = pct_change(group["close"], 1) group["ibs"] = ibs(group["high"], group["low"], group["close"]) group["increase_ratio_3"] = increase_from_lowest_price( group["low"], group["close"], 3) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("date") for key, group in grouped: group = group.reset_index(drop=True) group["rank_tr_val_5"] = rank(group["sma_tr_val_5"]) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: decrease_condition1 = group["open"] > group["close"] decrease_condition2 = group["pct_change_1"] < 0 decrease_condition3 = group["ibs"] < 0.25 decrease_condition = (decrease_condition1 | decrease_condition2) & decrease_condition3 # Result group["#result"] = decrease_condition group["#priority"] = group["increase_ratio_3"].shift( 1) + group["increase_ratio_3"].shift(2) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) # Market Timing index_day_price["sma_3"] = sma(index_day_price["close"], 3) index_day_price["sma_5"] = sma(index_day_price["close"], 5) index_day_price["sma_10"] = sma(index_day_price["close"], 10) index_day_price["#market_timing"] = ( (index_day_price["close"] > index_day_price["sma_3"]) | (index_day_price["close"] > index_day_price["sma_5"]) | (index_day_price["close"] > index_day_price["sma_10"])) index_day_price = index_day_price.set_index("date") return day_price, index_day_price
def add_data_to_day_price(day_price: DataFrame, index_day_price: DataFrame) -> DataFrame: group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: group = group.reset_index(drop=True) group["sma_10"] = sma(group["close"], 10) group["sma_20"] = sma(group["close"], 20) group["sma_tr_val_5"] = sma(group["tr_val"], 5) group["pct_change_1"] = pct_change(group["close"], 1) group["ts_max_20"] = ts_max(group["close"], 20) group["ibs"] = ibs(group["high"], group["low"], group["close"]) group["increase_ratio_3"] = increase_from_lowest_price( group["low"], group["close"], 3) group["pdi_5"] = pdi(group["high"], group["low"], group["close"], 5, MovingAverage.ema) group["pdi_5_sto"] = stochastic_fast_k(group["pdi_5"], group["pdi_5"], group["pdi_5"], 20) group["pdi_5_sto_pct_change_3"] = pct_change(group["pdi_5_sto"], 3) group["pivot_standard"] = pivot_standard(group["high"], group["low"], group["close"]) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("date") for key, group in grouped: group = group.reset_index(drop=True) group["rank_tr_val_5"] = rank(group["sma_tr_val_5"]) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) group_list = [] grouped = day_price.groupby("ticker_id") for key, group in grouped: increase_condition1 = (group["pdi_5_sto_pct_change_3"].shift(1) >= 0.1) | (group["pdi_5_sto_pct_change_3"].shift(2) >= 0.1) increase_condition = increase_condition1 decrease_condition1 = group["open"] > group["close"] decrease_condition2 = group["pct_change_1"] < 0 decrease_condition3 = group["ibs"] < 0.25 decrease_condition = (decrease_condition1 | decrease_condition2) & decrease_condition3 liquidity_condition1 = group["rank_tr_val_5"] > 0.8 liquidity_condition = liquidity_condition1 # Result group[ "#result"] = increase_condition & decrease_condition & liquidity_condition group["#priority"] = group["increase_ratio_3"].shift( 1) + group["increase_ratio_3"].shift(2) group_list.append(group) day_price = pd.concat(group_list, axis=0) day_price = day_price.reset_index(drop=True) # Market Timing index_day_price["sma_3"] = sma(index_day_price["close"], 3) index_day_price["sma_5"] = sma(index_day_price["close"], 5) index_day_price["sma_10"] = sma(index_day_price["close"], 10) index_day_price["#market_timing"] = ( (index_day_price["close"] > index_day_price["sma_3"]) | (index_day_price["close"] > index_day_price["sma_5"]) | (index_day_price["close"] > index_day_price["sma_10"])) index_day_price = index_day_price.set_index("date") return day_price, index_day_price