def __init__(self): self.insdustry_quote = base.load_industryquote_xlsx() self.nav = base.load_nav_csv() self.records = base.load_records_csv() self.current_date = time self.trading_day_df = base.load_trading_day_csv() self.quote = base.load_quote_csv()
def test_Update_IR_rank(): records = base.load_records_csv() industry_quote = base.load_industryquote_xlsx() nav = base.load_nav_csv() quote = base.load_quote_csv() IR_rank = base.load_irweek_csv() date = '2017-01-06' df_records = records[records.Updated <= date] df_ind_quote = industry_quote[industry_quote.TradingDay <= date] df_nav = nav[nav.NavDate <= date] df_quote = quote[quote.TradingDay <= date] Update_IR_rank(date, df_records, df_ind_quote, df_nav, df_quote, IR_rank)
def process_data(): df = base.load_quote_csv() df = with_nday_avg(df, 2) df = with_nday_avg(df, 3) df = with_nday_avg(df, 4) df = with_nday_avg(df, 5) df = with_nday_avg(df, 6) df = with_nday_avg(df, 7) df = with_nday_ratio_difference(df, 2) df = with_nday_ratio_difference(df, 3) df = with_nday_ratio_difference(df, 4) df = with_nday_ratio_difference(df, 5) df = with_nday_ratio_difference(df, 6) df = with_nday_ratio_difference(df, 7) df = with_nday_reward_ratio(df, 15) df = label_by_reward_ratio(df, 15) df = df.drop(column[3:] + ex_column, axis=1) df = df.dropna(axis=0, how='any') df.to_csv("../stock_avg.csv", index=False)
import pandas as pd import numpy as np import datetime import time from bitarray import bitarray import base quote = base.load_quote_csv() industry = base.load_industry_csv() quote.dropna(inplace=True) def func(x): if x < 0: return 0 elif x >= 0: return 1 def signs_window(quote, code, size=10): vals = quote[quote.SecuCode == code].Close signs = pd.DataFrame(vals.diff()[1:].apply(func)) names = ['signs_1'] df = signs for i in range(1, size): df = df.merge(signs.shift(-i), left_index=True, right_index=True) names.append('signs_' + str(i + 1)) df.columns = names return np.array(df.dropna().applymap(lambda x: int(x)))