def test_redefine_time_frame(): stock = StockDataFrame(get_1m_tencent().iloc[:20], date_col=TIME_KEY, time_frame='5m') new_stock = StockDataFrame(stock, cumulators={'open': cumulators['open']}) stock = stock.cumulate() new_stock = new_stock.cumulate() assert np.array_equal(stock['open'].to_numpy(), new_stock['open'].to_numpy()) assert np.array_equal(stock['close'].to_numpy(), new_stock['close'].to_numpy())
def test_cumulate(tencent): stock = StockDataFrame(tencent, date_col=TIME_KEY, time_frame='5m').cumulate() expect_cumulated(tencent, stock, LENGTH) assert stock.equals(stock.cumulate())
def test_cum_append_feat_indicator(): tencent = get_1m_tencent() stock = StockDataFrame(tencent.iloc[:19], date_col=TIME_KEY, time_frame='5m').cumulate() ma = stock['ma:2'][-1] assert ma == stock.iloc[-2:]['close'].sum() / 2 stock = stock.cum_append(tencent.iloc[19:20]) assert stock._stock_columns_info_map['ma:2,close'].size == len(stock) - 1 new_ma = stock['ma:2'][-1] assert ma != new_ma stock = StockDataFrame(stock, time_frame='15m') assert stock._stock_columns_info_map['ma:2,close'].size == len(stock) stock = stock.cum_append(tencent.iloc[20:21]) assert stock._stock_columns_info_map['ma:2,close'].size == len(stock) - 1 stock = stock.cumulate() # Time frame changed, so info map should not be inherited assert 'ma:2,close' not in stock._stock_columns_info_map