def test_run_simulation_round_buy_max_exposure(self): # close values DataFrame cv_df = pd.read_csv('./data/sample_data.csv', parse_dates=True, index_col=0)[['close']] # input_data DataFrame id_df = pd.read_csv('./data/sample_data.csv', parse_dates=True, index_col=0) ts = TradingSimulation(input_data_index=id_df.index, close_values=cv_df, max_exposure=1, short_exposure_factor=1.5) ts.runSimulationRound(i_index=0, signal=TRADE_SIGNALS['buy']) ts.runSimulationRound(i_index=1, signal=TRADE_SIGNALS['buy']) ts.runSimulationRound(i_index=2, signal=TRADE_SIGNALS['buy']) self.assertListEqual(list(ts._portfolio[2, :]), [0.0, 0.0, 0.0]) self.assertListEqual( ts._simulation_data.iloc[2, :].to_list(), ['buy', 'none', ts._close_values[2, 0], 0.0, 0.0, 0.0, 0.0])
def test_run_simulation_round_sell(self): # close values DataFrame cv_df = pd.read_csv('./data/sample_data.csv', parse_dates=True, index_col=0)[['close']] # input_data DataFrame id_df = pd.read_csv('./data/sample_data.csv', parse_dates=True, index_col=0) ts = TradingSimulation(input_data_index=id_df.index, close_values=cv_df, max_exposure=None, short_exposure_factor=1.5) ts.runSimulationRound(i_index=0, signal=TRADE_SIGNALS['sell']) ts.runSimulationRound(i_index=1, signal=TRADE_SIGNALS['sell']) self.assertListEqual(list(ts._portfolio[1, :]), [1.0, 1.0, 1.5 * ts._close_values[1, 0]]) self.assertListEqual(ts._simulation_data.iloc[1, :].to_list(), [ 'sell', 'short', ts._close_values[1, 0], ts._simulation_data['exposure'].iat[0] + 1.5 * ts._close_values[1, 0], -ts._close_values[1, 0], 0.0, -ts._close_values[1, 0] ])