From c0fe5348e874224c332a1328967459cea99c13e7 Mon Sep 17 00:00:00 2001 From: 1024064118 <1024064118@qq.com> Date: Fri, 14 May 2021 23:39:01 +0800 Subject: [PATCH] Create env_stocktrading.py I believe it may help agent avoid getting negative asset when agent cannot afford transaction cost in the extreme --- finrl/env/env_stocktrading.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/finrl/env/env_stocktrading.py b/finrl/env/env_stocktrading.py index ccb615eaa..ced683f79 100644 --- a/finrl/env/env_stocktrading.py +++ b/finrl/env/env_stocktrading.py @@ -132,7 +132,7 @@ def _buy_stock(self, index, action): def _do_buy(): if self.state[index+1]>0: #Buy only if the price is > 0 (no missing data in this particular date) - available_amount = self.state[0] // self.state[index+1] + available_amount = self.state[0] // ((self.state[index+1])*(1+ self.buy_cost_pct)) # print('available_amount:{}'.format(available_amount)) #update balance @@ -377,4 +377,4 @@ def _seed(self, seed=None): def get_sb_env(self): e = DummyVecEnv([lambda: self]) obs = e.reset() - return e, obs \ No newline at end of file + return e, obs