def test_skew(): logging.debug("测试偏度") for i in range(2010, 2018): s = '{0}-01-01'.format(i) e = '{0}-12-31'.format(i) df = data_processor.merge({ test.index_code: get_index_daily().loc[s:e], test.stock_code: get_stock_daily().loc[s:e] }) v = calcs.skew(df['close'].dropna()) print('{0}:{1}'.format(i, v))
def test_is_trade_suspension(): """测试是否停牌的计算""" df = data_processor.merge( { test.stock_code: get_stock_daily(), test.index_code: get_index_daily() }, how='right') is_sus = calcs.is_trade_suspension(df) assert not is_sus['2012-02-22'] assert is_sus['2012-02-23'] assert not is_sus['2012-02-24'] print(is_sus['2012-02-23'])
def test_merge(): df_merge = test.merged_dataframe() df_index = test.get_index_daily() df_stock = test.get_stock_daily() assert not df_merge.empty print(df_merge.head()) print(df_merge.tail()) for col in df_index.columns: assert col in df_merge.columns assert df_index[col].dtype == df_merge[col].dtype for col in df_stock.columns: c = '{0}{1}'.format(col, test.stock_code) assert c in df_merge.columns assert df_stock[col].dtype == df_merge[c].dtype print(df_merge.dtypes)
def test_merge_dropcolumn(): columns = ['up_count', 'down_count'] df = data_processor.merge( { test.index_code: get_index_daily(), test.stock_code: get_stock_daily() }, append_funcs={ 'drop_columns': (calcs.drop_column, { 'columns': columns, 'replace': True }) }) for col in columns: assert col not in df.columns print(df.dtypes)
def test_sharpe_ratio(): rate = get_deposit_rate().sort_index() df_s = get_stock_daily().index[0].date() df_e = get_stock_daily().index[-1].date() for i in range(len(rate.index)): s = str2date(rate.index[i]).date() e = str2date(rate.index[i + 1]).date() if rate[i] != rate[-1] else df_e if s >= df_s and e <= df_e: df = data_processor.merge({ test.index_code: get_index_daily().loc[s:e], test.stock_code: get_stock_daily().loc[s:e] }) k = '{0}~{1}'.format(s, e) v = calcs.sharpe_ratio(df['close'].dropna(), rate[i]) print('{0}:{1}'.format(k, v))