gaur3009 commited on
Commit
30cd673
·
verified ·
1 Parent(s): 7678692

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -1
app.py CHANGED
@@ -24,7 +24,7 @@ class PortfolioEnv(Env):
24
 
25
  def step(self, action):
26
  action = np.clip(action, 0, 1)
27
- weights = action / np.sum(action)
28
 
29
  portfolio_return = np.dot(weights, self.returns.iloc[self.current_step].values)
30
  self.current_balance *= (1 + portfolio_return)
 
24
 
25
  def step(self, action):
26
  action = np.clip(action, 0, 1)
27
+ weights = action / (np.sum(action) + 1e-8) # Prevent division by zero
28
 
29
  portfolio_return = np.dot(weights, self.returns.iloc[self.current_step].values)
30
  self.current_balance *= (1 + portfolio_return)