def test_close_simulation(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) self.maxDiff = None statistics_expected_result = { 'number_of_trading_days': 3169, 'number_of_buy_signals': 1297, 'number_of_ignored_buy_signals': 1029, 'number_of_sell_signals': 1152, 'number_of_ignored_sell_signals': 741, 'last_stock_value': 140.41, 'last_exposure': 3268.0, 'last_open_long_positions': 397, 'last_open_short_positions': 396, 'last_portfolio_value': 3368.0, 'last_earnings': 3468.0, 'final_balance': 3568.0 } ts._simulation_data = pd.read_csv( './data/simulation_data_full_with_actions.csv', parse_dates=True, index_col=0) ts._portfolio = pd.read_csv( './data/portfolio_simulation_data_full.csv', parse_dates=True, index_col=0).to_numpy(dtype=np.float64, copy=True) sd_result, st_result = ts.closeSimulation() pd.testing.assert_frame_equal(sd_result, ts._simulation_data) self.assertDictEqual(st_result, statistics_expected_result)
def test_calculate_simulation_statistics_ten_simulation_rounds(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) statistics_expected_result = { 'number_of_trading_days': 10, 'number_of_buy_signals': 4, 'number_of_ignored_buy_signals': 1, 'number_of_sell_signals': 3, 'number_of_ignored_sell_signals': 2, 'last_stock_value': 34.37, 'last_exposure': 109.0, 'last_open_long_positions': 2, 'last_open_short_positions': 3, 'last_portfolio_value': 209.0, 'last_earnings': 309.0, 'final_balance': 409.0 } ts._simulation_data = pd.read_csv( './data/simulation_data_with_actions_ten_rounds.csv', parse_dates=True, index_col=0) ts._portfolio = pd.read_csv( './data/portfolio_simulation_data_ten_rounds.csv', parse_dates=True, index_col=0).to_numpy(dtype=np.float64, copy=True) ts._calculateSimulationStatistics() self.assertDictEqual(ts._statistics, statistics_expected_result)