From 29ea649aed6582532d0c08e981adcbf029178bb9 Mon Sep 17 00:00:00 2001 From: jinjuncheng Date: Thu, 24 Jan 2019 21:11:44 +0800 Subject: [PATCH 1/4] softmax_actions.py --- rl_portfolio_management/wrappers/softmax_actions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rl_portfolio_management/wrappers/softmax_actions.py b/rl_portfolio_management/wrappers/softmax_actions.py index 6325f2e..c8cdb69 100644 --- a/rl_portfolio_management/wrappers/softmax_actions.py +++ b/rl_portfolio_management/wrappers/softmax_actions.py @@ -17,12 +17,16 @@ class SoftmaxActions(gym.Wrapper): def step(self, action): # also it puts it in a list + # print('action in softmax', type(action)) if isinstance(action, list): - action = action[0] + # action = action[0] + # Junchen: change to fit new Horizon framework + action = action if isinstance(action, dict): action = list(action[k] for k in sorted(action.keys())) action = softmax(action, t=1) + # print('action in softmax after', action.shape) return self.env.step(action) From be7c316c4e3b33539f12266210f9f35810d6de0d Mon Sep 17 00:00:00 2001 From: jinjuncheng Date: Thu, 24 Jan 2019 22:38:46 +0800 Subject: [PATCH 2/4] dd --- rl_portfolio_management/wrappers/softmax_actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rl_portfolio_management/wrappers/softmax_actions.py b/rl_portfolio_management/wrappers/softmax_actions.py index c8cdb69..ba8ebc1 100644 --- a/rl_portfolio_management/wrappers/softmax_actions.py +++ b/rl_portfolio_management/wrappers/softmax_actions.py @@ -27,6 +27,6 @@ def step(self, action): action = list(action[k] for k in sorted(action.keys())) action = softmax(action, t=1) - # print('action in softmax after', action.shape) + # print('action in softmax after', action.shape) return self.env.step(action) From 25a7b51921ca29fd645c1d0a9dfb6e4329b59329 Mon Sep 17 00:00:00 2001 From: jinjuncheng Date: Fri, 25 Jan 2019 15:07:58 +0800 Subject: [PATCH 3/4] modify by junchen --- rl_portfolio_management/util.py | 1 + rl_portfolio_management/wrappers/softmax_actions.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/rl_portfolio_management/util.py b/rl_portfolio_management/util.py index 02d5494..3c668c0 100644 --- a/rl_portfolio_management/util.py +++ b/rl_portfolio_management/util.py @@ -22,6 +22,7 @@ def MDD(X): def softmax(w, t=1.0): """softmax implemented in numpy.""" log_eps = np.log(eps) + #print('w, log_eps, -log_eps', w, log_eps, -log_eps) w = np.clip(w, log_eps, -log_eps) # avoid inf/nan e = np.exp(np.array(w) / t) dist = e / np.sum(e) diff --git a/rl_portfolio_management/wrappers/softmax_actions.py b/rl_portfolio_management/wrappers/softmax_actions.py index ba8ebc1..5b74070 100644 --- a/rl_portfolio_management/wrappers/softmax_actions.py +++ b/rl_portfolio_management/wrappers/softmax_actions.py @@ -18,6 +18,9 @@ class SoftmaxActions(gym.Wrapper): def step(self, action): # also it puts it in a list # print('action in softmax', type(action)) + if isinstance(action, tuple): + action = action[0] + if isinstance(action, list): # action = action[0] # Junchen: change to fit new Horizon framework @@ -27,6 +30,6 @@ def step(self, action): action = list(action[k] for k in sorted(action.keys())) action = softmax(action, t=1) - # print('action in softmax after', action.shape) + #print('action in softmax after', action.shape) return self.env.step(action) From 0ebf5d2b1ae4c9b13f39ce46a7d10ff335556dfe Mon Sep 17 00:00:00 2001 From: jinjuncheng Date: Fri, 25 Jan 2019 21:20:36 +0800 Subject: [PATCH 4/4] test1 --- rl_portfolio_management/wrappers/softmax_actions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rl_portfolio_management/wrappers/softmax_actions.py b/rl_portfolio_management/wrappers/softmax_actions.py index 5b74070..0e05c24 100644 --- a/rl_portfolio_management/wrappers/softmax_actions.py +++ b/rl_portfolio_management/wrappers/softmax_actions.py @@ -33,3 +33,4 @@ def step(self, action): #print('action in softmax after', action.shape) return self.env.step(action) +