From e4c3f55216ef3f156b4d54a1e3fa79e5c7ecf133 Mon Sep 17 00:00:00 2001 From: sb Date: Tue, 25 Oct 2022 11:40:15 -0400 Subject: [PATCH] fixing the error due to mismatched number of records in history when building data.csv --- sharkfin/simulation.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sharkfin/simulation.py b/sharkfin/simulation.py index f0d847b..81119ee 100644 --- a/sharkfin/simulation.py +++ b/sharkfin/simulation.py @@ -450,17 +450,23 @@ def data(self): Returns a Pandas DataFrame of the data from the simulation run. """ data = MarketSimulation.data(self) - + + + + ## Total hacks to fix a weird bug: + ## - Depending on whether the market chose in Mock or RPC, we get getting different lengths of broker macro history + days_ran = len(data['t']) + data_dict = { - 'buy_macro': [bs[0] for bs in self.broker.buy_sell_macro_history][self.burn_in_val:], - 'sell_macro': [bs[1] for bs in self.broker.buy_sell_macro_history][self.burn_in_val:], - 'owned': self.history['owned_shares'][1:], - 'total_assets': self.history['total_assets'][1:], - 'mean_income': self.history['mean_income_level'][1:], - 'total_consumption': self.history['total_consumption_level'][1:], + 'buy_macro': [bs[0] for bs in self.broker.buy_sell_macro_history][-days_ran:], + 'sell_macro': [bs[1] for bs in self.broker.buy_sell_macro_history][-days_ran:], + 'owned': self.history['owned_shares'][-days_ran:], + 'total_assets': self.history['total_assets'][-days_ran:], + 'mean_income': self.history['mean_income_level'][-days_ran:], + 'total_consumption': self.history['total_consumption_level'][-days_ran:], #'permshock_std': self.history['permshock_std'][1:], - 'expected_ror': self.fm.expected_ror_list[self.burn_in_val+1:], - 'expected_std': self.fm.expected_std_list[self.burn_in_val+1:], + 'expected_ror': self.fm.expected_ror_list[-days_ran:], + 'expected_std': self.fm.expected_std_list[-days_ran:], } try: