Skip to content

Commit

Permalink
Merge pull request #472 from tensortrade-org/update-dependencies
Browse files Browse the repository at this point in the history
Bump to gymnasium and update dependencies to Python 3.11.9
  • Loading branch information
carlogrisetti authored May 26, 2024
2 parents cc6bd19 + 0db4217 commit 2cb3a3e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- docker

python:
- '3.9'
- '3.11.9'

install:
- sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.17.0
pandas>=0.25.0
gym>=0.25.2
gymnasium>=0.28.1
pyyaml>=5.1.2
stochastic>=0.6.0
tensorflow>=2.7.0
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
if package.startswith('tensortrade')
],
license='Apache 2.0',
python_requires='>=3.7',
python_requires='>=3.11.9',
install_requires=[
'numpy>=1.17.0',
'pandas>=0.25.0',
'gym>=0.15.7',
'gymnasium>=0.28.1',
'pyyaml>=5.1.2',
'stochastic>=0.6.0',
'tensorflow>=2.7.0',
Expand Down Expand Up @@ -83,9 +83,7 @@
'Intended Audience :: Information Technology',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.11',
'Topic :: Office/Business :: Financial :: Investment',
'Topic :: Office/Business :: Financial',
'Topic :: Scientific/Engineering :: Information Analysis',
Expand Down
2 changes: 1 addition & 1 deletion tensortrade/env/default/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from itertools import product
from typing import Union, List, Any

from gym.spaces import Space, Discrete
from gymnasium.spaces import Space, Discrete

from tensortrade.core import Clock
from tensortrade.env.generic import ActionScheme, TradingEnv
Expand Down
2 changes: 1 addition & 1 deletion tensortrade/env/default/observers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pandas as pd

from gym.spaces import Box, Space
from gymnasium.spaces import Box, Space
from random import randrange


Expand Down
2 changes: 1 addition & 1 deletion tensortrade/env/generic/components/action_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from abc import abstractmethod, ABCMeta
from typing import Any

from gym.spaces import Space
from gymnasium.spaces import Space


from tensortrade.core.component import Component
Expand Down
2 changes: 1 addition & 1 deletion tensortrade/env/generic/components/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from gym.spaces import Space
from gymnasium.spaces import Space


from tensortrade.core.component import Component
Expand Down
21 changes: 8 additions & 13 deletions tensortrade/env/generic/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Dict, Any, Tuple
from random import randint

import gym
import gymnasium
import numpy as np

from tensortrade.core import TimeIndexed, Clock, Component
Expand All @@ -32,7 +32,7 @@
)


class TradingEnv(gym.Env, TimeIndexed):
class TradingEnv(gymnasium.Env, TimeIndexed):
"""A trading environment made for use with Gym-compatible reinforcement
learning algorithms.
Expand Down Expand Up @@ -81,13 +81,6 @@ def __init__(self,
self.min_periods = min_periods
self.random_start_pct = random_start_pct

# Register the environment in Gym and fetch spec
gym.envs.register(
id='TensorTrade-v0',
max_episode_steps=max_episode_steps,
)
self.spec = gym.spec(env_id='TensorTrade-v0')

for c in self.components.values():
c.clock = self.clock

Expand Down Expand Up @@ -135,14 +128,15 @@ def step(self, action: Any) -> 'Tuple[np.array, float, bool, dict]':

obs = self.observer.observe(self)
reward = self.reward_scheme.reward(self)
done = self.stopper.stop(self)
terminated = self.stopper.stop(self)
truncated = False
info = self.informer.info(self)

self.clock.increment()

return obs, reward, done, info
return obs, reward, terminated, truncated, info

def reset(self) -> 'np.array':
def reset(self,seed = None, options = None) -> tuple["np.array", dict[str, Any]]:
"""Resets the environment.
Returns
Expand All @@ -167,10 +161,11 @@ def reset(self) -> 'np.array':
c.reset()

obs = self.observer.observe(self)
info = self.informer.info(self)

self.clock.increment()

return obs
return obs, info

def render(self, **kwargs) -> None:
"""Renders the environment."""
Expand Down

0 comments on commit 2cb3a3e

Please sign in to comment.