tensortrade 1.0.0b0__py3-none-any.whl → 1.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tensortrade/__init__.py +23 -16
- tensortrade/agents/__init__.py +7 -7
- tensortrade/agents/a2c_agent.py +239 -237
- tensortrade/agents/agent.py +52 -49
- tensortrade/agents/dqn_agent.py +375 -202
- tensortrade/agents/parallel/__init__.py +5 -5
- tensortrade/agents/parallel/parallel_dqn_agent.py +172 -170
- tensortrade/agents/parallel/parallel_dqn_model.py +85 -83
- tensortrade/agents/parallel/parallel_dqn_optimizer.py +96 -90
- tensortrade/agents/parallel/parallel_dqn_trainer.py +97 -95
- tensortrade/agents/parallel/parallel_queue.py +95 -92
- tensortrade/agents/replay_memory.py +54 -52
- tensortrade/core/__init__.py +6 -6
- tensortrade/core/base.py +167 -173
- tensortrade/core/clock.py +48 -48
- tensortrade/core/component.py +129 -129
- tensortrade/core/context.py +182 -182
- tensortrade/core/exceptions.py +211 -211
- tensortrade/core/registry.py +45 -45
- tensortrade/data/__init__.py +1 -1
- tensortrade/data/cdd.py +152 -151
- tensortrade/env/__init__.py +2 -2
- tensortrade/env/default/__init__.py +96 -89
- tensortrade/env/default/actions.py +428 -399
- tensortrade/env/default/informers.py +14 -16
- tensortrade/env/default/observers.py +475 -284
- tensortrade/env/default/renderers.py +787 -586
- tensortrade/env/default/rewards.py +360 -240
- tensortrade/env/default/stoppers.py +33 -33
- tensortrade/env/generic/__init__.py +22 -22
- tensortrade/env/generic/components/__init__.py +13 -13
- tensortrade/env/generic/components/action_scheme.py +54 -54
- tensortrade/env/generic/components/informer.py +45 -45
- tensortrade/env/generic/components/observer.py +59 -59
- tensortrade/env/generic/components/renderer.py +86 -86
- tensortrade/env/generic/components/reward_scheme.py +44 -44
- tensortrade/env/generic/components/stopper.py +46 -46
- tensortrade/env/generic/environment.py +211 -163
- tensortrade/feed/__init__.py +5 -5
- tensortrade/feed/api/__init__.py +5 -5
- tensortrade/feed/api/boolean/__init__.py +44 -44
- tensortrade/feed/api/boolean/operations.py +20 -20
- tensortrade/feed/api/float/__init__.py +49 -48
- tensortrade/feed/api/float/accumulators.py +199 -199
- tensortrade/feed/api/float/imputation.py +40 -40
- tensortrade/feed/api/float/operations.py +233 -233
- tensortrade/feed/api/float/ordering.py +105 -105
- tensortrade/feed/api/float/utils.py +140 -140
- tensortrade/feed/api/float/window/__init__.py +3 -3
- tensortrade/feed/api/float/window/ewm.py +459 -452
- tensortrade/feed/api/float/window/expanding.py +189 -185
- tensortrade/feed/api/float/window/rolling.py +227 -217
- tensortrade/feed/api/generic/__init__.py +4 -4
- tensortrade/feed/api/generic/imputation.py +51 -51
- tensortrade/feed/api/generic/operators.py +118 -121
- tensortrade/feed/api/generic/reduce.py +119 -119
- tensortrade/feed/api/generic/warmup.py +54 -54
- tensortrade/feed/api/string/__init__.py +44 -43
- tensortrade/feed/api/string/operations.py +135 -131
- tensortrade/feed/core/__init__.py +3 -3
- tensortrade/feed/core/accessors.py +30 -30
- tensortrade/feed/core/base.py +634 -584
- tensortrade/feed/core/feed.py +120 -59
- tensortrade/feed/core/methods.py +37 -37
- tensortrade/feed/core/mixins.py +23 -23
- tensortrade/feed/core/operators.py +174 -174
- tensortrade/oms/__init__.py +2 -2
- tensortrade/oms/exchanges/__init__.py +1 -1
- tensortrade/oms/exchanges/exchange.py +176 -164
- tensortrade/oms/instruments/__init__.py +5 -5
- tensortrade/oms/instruments/exchange_pair.py +44 -44
- tensortrade/oms/instruments/instrument.py +161 -161
- tensortrade/oms/instruments/quantity.py +321 -318
- tensortrade/oms/instruments/trading_pair.py +58 -58
- tensortrade/oms/orders/__init__.py +13 -13
- tensortrade/oms/orders/broker.py +129 -125
- tensortrade/oms/orders/create.py +312 -312
- tensortrade/oms/orders/criteria.py +218 -218
- tensortrade/oms/orders/order.py +368 -368
- tensortrade/oms/orders/order_listener.py +62 -62
- tensortrade/oms/orders/order_spec.py +102 -102
- tensortrade/oms/orders/trade.py +159 -159
- tensortrade/oms/services/__init__.py +2 -2
- tensortrade/oms/services/execution/__init__.py +4 -4
- tensortrade/oms/services/execution/simulated.py +197 -183
- tensortrade/oms/services/slippage/__init__.py +21 -21
- tensortrade/oms/services/slippage/random_slippage_model.py +56 -56
- tensortrade/oms/services/slippage/slippage_model.py +46 -46
- tensortrade/oms/wallets/__init__.py +20 -20
- tensortrade/oms/wallets/ledger.py +92 -92
- tensortrade/oms/wallets/portfolio.py +330 -329
- tensortrade/oms/wallets/wallet.py +376 -365
- tensortrade/stochastic/__init__.py +12 -12
- tensortrade/stochastic/processes/brownian_motion.py +55 -55
- tensortrade/stochastic/processes/cox.py +103 -103
- tensortrade/stochastic/processes/fbm.py +88 -88
- tensortrade/stochastic/processes/gbm.py +129 -129
- tensortrade/stochastic/processes/heston.py +281 -281
- tensortrade/stochastic/processes/merton.py +91 -91
- tensortrade/stochastic/processes/ornstein_uhlenbeck.py +113 -113
- tensortrade/stochastic/utils/__init__.py +2 -2
- tensortrade/stochastic/utils/helpers.py +180 -179
- tensortrade/stochastic/utils/parameters.py +172 -172
- tensortrade/version.py +1 -1
- tensortrade-1.0.4.dist-info/METADATA +65 -0
- tensortrade-1.0.4.dist-info/RECORD +114 -0
- {tensortrade-1.0.0b0.dist-info → tensortrade-1.0.4.dist-info}/WHEEL +1 -1
- {tensortrade-1.0.0b0.dist-info → tensortrade-1.0.4.dist-info/licenses}/LICENSE +200 -200
- tensortrade-1.0.0b0.dist-info/METADATA +0 -74
- tensortrade-1.0.0b0.dist-info/RECORD +0 -114
- {tensortrade-1.0.0b0.dist-info → tensortrade-1.0.4.dist-info}/top_level.txt +0 -0
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
from tensortrade.env.generic import Stopper, TradingEnv
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class MaxLossStopper(Stopper):
|
|
6
|
-
"""A stopper that stops an episode if the portfolio has lost a particular
|
|
7
|
-
percentage of its wealth.
|
|
8
|
-
|
|
9
|
-
Parameters
|
|
10
|
-
----------
|
|
11
|
-
max_allowed_loss : float
|
|
12
|
-
The maximum
|
|
13
|
-
be lost before stopping the episode.
|
|
14
|
-
|
|
15
|
-
Attributes
|
|
16
|
-
----------
|
|
17
|
-
max_allowed_loss : float
|
|
18
|
-
The maximum
|
|
19
|
-
be lost before stopping the episode.
|
|
20
|
-
|
|
21
|
-
Notes
|
|
22
|
-
-----
|
|
23
|
-
This stopper also stops if it has reached the end of the observation feed.
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
def __init__(self, max_allowed_loss: float):
|
|
27
|
-
super().__init__()
|
|
28
|
-
self.max_allowed_loss = max_allowed_loss
|
|
29
|
-
|
|
30
|
-
def stop(self, env: 'TradingEnv') -> bool:
|
|
31
|
-
c1 = env.action_scheme.portfolio.profit_loss
|
|
32
|
-
c2 = not env.observer.has_next()
|
|
33
|
-
return c1 or c2
|
|
1
|
+
|
|
2
|
+
from tensortrade.env.generic import Stopper, TradingEnv
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MaxLossStopper(Stopper):
|
|
6
|
+
"""A stopper that stops an episode if the portfolio has lost a particular
|
|
7
|
+
percentage of its wealth.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
max_allowed_loss : float
|
|
12
|
+
The maximum percentage of initial funds that is willing to
|
|
13
|
+
be lost before stopping the episode.
|
|
14
|
+
|
|
15
|
+
Attributes
|
|
16
|
+
----------
|
|
17
|
+
max_allowed_loss : float
|
|
18
|
+
The maximum percentage of initial funds that is willing to
|
|
19
|
+
be lost before stopping the episode.
|
|
20
|
+
|
|
21
|
+
Notes
|
|
22
|
+
-----
|
|
23
|
+
This stopper also stops if it has reached the end of the observation feed.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, max_allowed_loss: float):
|
|
27
|
+
super().__init__()
|
|
28
|
+
self.max_allowed_loss = max_allowed_loss
|
|
29
|
+
|
|
30
|
+
def stop(self, env: 'TradingEnv') -> bool:
|
|
31
|
+
c1 = env.action_scheme.portfolio.profit_loss > self.max_allowed_loss
|
|
32
|
+
c2 = not env.observer.has_next()
|
|
33
|
+
return c1 or c2
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License
|
|
14
|
-
|
|
15
|
-
from tensortrade.env.generic.components.reward_scheme import RewardScheme
|
|
16
|
-
from tensortrade.env.generic.components.action_scheme import ActionScheme
|
|
17
|
-
from tensortrade.env.generic.components.observer import Observer
|
|
18
|
-
from tensortrade.env.generic.components.stopper import Stopper
|
|
19
|
-
from tensortrade.env.generic.components.informer import Informer
|
|
20
|
-
from tensortrade.env.generic.components.renderer import Renderer
|
|
21
|
-
|
|
22
|
-
from tensortrade.env.generic.environment import TradingEnv
|
|
1
|
+
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License
|
|
14
|
+
|
|
15
|
+
from tensortrade.env.generic.components.reward_scheme import RewardScheme
|
|
16
|
+
from tensortrade.env.generic.components.action_scheme import ActionScheme
|
|
17
|
+
from tensortrade.env.generic.components.observer import Observer
|
|
18
|
+
from tensortrade.env.generic.components.stopper import Stopper
|
|
19
|
+
from tensortrade.env.generic.components.informer import Informer
|
|
20
|
+
from tensortrade.env.generic.components.renderer import Renderer
|
|
21
|
+
|
|
22
|
+
from tensortrade.env.generic.environment import TradingEnv
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License
|
|
1
|
+
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License
|
|
14
|
-
|
|
15
|
-
from abc import abstractmethod, ABCMeta
|
|
16
|
-
from typing import Any
|
|
17
|
-
|
|
18
|
-
from
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
from tensortrade.core.component import Component
|
|
22
|
-
from tensortrade.core.base import TimeIndexed
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ActionScheme(Component, TimeIndexed, metaclass=ABCMeta):
|
|
26
|
-
"""A component for determining the action to take at each step of an
|
|
27
|
-
episode.
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
registered_name = "actions"
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
@abstractmethod
|
|
34
|
-
def action_space(self) -> Space:
|
|
35
|
-
"""The action space of the `TradingEnv`. (`Space`, read-only)
|
|
36
|
-
"""
|
|
37
|
-
raise NotImplementedError()
|
|
38
|
-
|
|
39
|
-
@abstractmethod
|
|
40
|
-
def perform(self, env: 'TradingEnv', action: Any) -> None:
|
|
41
|
-
"""Performs an action on the environment.
|
|
42
|
-
|
|
43
|
-
Parameters
|
|
44
|
-
----------
|
|
45
|
-
env : `TradingEnv`
|
|
46
|
-
The trading environment to perform the `action` on.
|
|
47
|
-
action : Any
|
|
48
|
-
The action to perform on `env`.
|
|
49
|
-
"""
|
|
50
|
-
raise NotImplementedError()
|
|
51
|
-
|
|
52
|
-
def reset(self) -> None:
|
|
53
|
-
"""Resets the action scheme."""
|
|
54
|
-
pass
|
|
1
|
+
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License
|
|
14
|
+
|
|
15
|
+
from abc import abstractmethod, ABCMeta
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from gymnasium.spaces import Space
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
from tensortrade.core.component import Component
|
|
22
|
+
from tensortrade.core.base import TimeIndexed
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ActionScheme(Component, TimeIndexed, metaclass=ABCMeta):
|
|
26
|
+
"""A component for determining the action to take at each step of an
|
|
27
|
+
episode.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
registered_name = "actions"
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def action_space(self) -> Space:
|
|
35
|
+
"""The action space of the `TradingEnv`. (`Space`, read-only)
|
|
36
|
+
"""
|
|
37
|
+
raise NotImplementedError()
|
|
38
|
+
|
|
39
|
+
@abstractmethod
|
|
40
|
+
def perform(self, env: 'TradingEnv', action: Any) -> None:
|
|
41
|
+
"""Performs an action on the environment.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
env : `TradingEnv`
|
|
46
|
+
The trading environment to perform the `action` on.
|
|
47
|
+
action : Any
|
|
48
|
+
The action to perform on `env`.
|
|
49
|
+
"""
|
|
50
|
+
raise NotImplementedError()
|
|
51
|
+
|
|
52
|
+
def reset(self) -> None:
|
|
53
|
+
"""Resets the action scheme."""
|
|
54
|
+
pass
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License
|
|
14
|
-
|
|
15
|
-
from abc import abstractmethod
|
|
16
|
-
|
|
17
|
-
from tensortrade.core.component import Component
|
|
18
|
-
from tensortrade.core.base import TimeIndexed
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Informer(Component, TimeIndexed):
|
|
22
|
-
"""A component to provide information at each step of an episode.
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
registered_name = "monitor"
|
|
26
|
-
|
|
27
|
-
@abstractmethod
|
|
28
|
-
def info(self, env: 'TradingEnv') -> dict:
|
|
29
|
-
"""Provides information at a given step of an episode.
|
|
30
|
-
|
|
31
|
-
Parameters
|
|
32
|
-
----------
|
|
33
|
-
env: 'TradingEnv'
|
|
34
|
-
The trading environment.
|
|
35
|
-
|
|
36
|
-
Returns
|
|
37
|
-
-------
|
|
38
|
-
dict:
|
|
39
|
-
A dictionary of information about the portfolio and net worth.
|
|
40
|
-
"""
|
|
41
|
-
raise NotImplementedError()
|
|
42
|
-
|
|
43
|
-
def reset(self):
|
|
44
|
-
"""Resets the informer."""
|
|
45
|
-
pass
|
|
1
|
+
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License
|
|
14
|
+
|
|
15
|
+
from abc import abstractmethod
|
|
16
|
+
|
|
17
|
+
from tensortrade.core.component import Component
|
|
18
|
+
from tensortrade.core.base import TimeIndexed
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Informer(Component, TimeIndexed):
|
|
22
|
+
"""A component to provide information at each step of an episode.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
registered_name = "monitor"
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def info(self, env: 'TradingEnv') -> dict:
|
|
29
|
+
"""Provides information at a given step of an episode.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
env: 'TradingEnv'
|
|
34
|
+
The trading environment.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
dict:
|
|
39
|
+
A dictionary of information about the portfolio and net worth.
|
|
40
|
+
"""
|
|
41
|
+
raise NotImplementedError()
|
|
42
|
+
|
|
43
|
+
def reset(self):
|
|
44
|
+
"""Resets the informer."""
|
|
45
|
+
pass
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
from abc import abstractmethod
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import numpy as np
|
|
20
|
-
|
|
21
|
-
from
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
from tensortrade.core.component import Component
|
|
25
|
-
from tensortrade.core.base import TimeIndexed
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class Observer(Component, TimeIndexed):
|
|
29
|
-
"""A component to generate an observation at each step of an episode.
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
registered_name = "observer"
|
|
33
|
-
|
|
34
|
-
@property
|
|
35
|
-
@abstractmethod
|
|
36
|
-
def observation_space(self) -> Space:
|
|
37
|
-
"""The observation space of the `TradingEnv`. (`Space`, read-only)
|
|
38
|
-
"""
|
|
39
|
-
raise NotImplementedError()
|
|
40
|
-
|
|
41
|
-
@abstractmethod
|
|
42
|
-
def observe(self, env: 'TradingEnv') -> np.array:
|
|
43
|
-
"""Gets the observation at the current step of an episode
|
|
44
|
-
|
|
45
|
-
Parameters
|
|
46
|
-
----------
|
|
47
|
-
env: 'TradingEnv'
|
|
48
|
-
The trading environment.
|
|
49
|
-
|
|
50
|
-
Returns
|
|
51
|
-
-------
|
|
52
|
-
`np.array`
|
|
53
|
-
The current observation of the environment.
|
|
54
|
-
"""
|
|
55
|
-
raise NotImplementedError()
|
|
56
|
-
|
|
57
|
-
def reset(self):
|
|
58
|
-
"""Resets the observer."""
|
|
59
|
-
pass
|
|
1
|
+
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from abc import abstractmethod
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from gymnasium.spaces import Space
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from tensortrade.core.component import Component
|
|
25
|
+
from tensortrade.core.base import TimeIndexed
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Observer(Component, TimeIndexed):
|
|
29
|
+
"""A component to generate an observation at each step of an episode.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
registered_name = "observer"
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def observation_space(self) -> Space:
|
|
37
|
+
"""The observation space of the `TradingEnv`. (`Space`, read-only)
|
|
38
|
+
"""
|
|
39
|
+
raise NotImplementedError()
|
|
40
|
+
|
|
41
|
+
@abstractmethod
|
|
42
|
+
def observe(self, env: 'TradingEnv') -> np.array:
|
|
43
|
+
"""Gets the observation at the current step of an episode
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
env: 'TradingEnv'
|
|
48
|
+
The trading environment.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
`np.array`
|
|
53
|
+
The current observation of the environment.
|
|
54
|
+
"""
|
|
55
|
+
raise NotImplementedError()
|
|
56
|
+
|
|
57
|
+
def reset(self, random_start=0):
|
|
58
|
+
"""Resets the observer."""
|
|
59
|
+
pass
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License
|
|
14
|
-
|
|
15
|
-
from abc import ABCMeta, abstractmethod
|
|
16
|
-
from typing import List
|
|
17
|
-
|
|
18
|
-
from tensortrade.core import Component
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Renderer(Component, metaclass=ABCMeta):
|
|
22
|
-
"""A component for rendering a view of the environment at each step of
|
|
23
|
-
an episode."""
|
|
24
|
-
|
|
25
|
-
registered_name = "renderer"
|
|
26
|
-
|
|
27
|
-
@abstractmethod
|
|
28
|
-
def render(self, env: 'TradingEnv', **kwargs):
|
|
29
|
-
"""Renders a view of the environment at the current step of an episode.
|
|
30
|
-
|
|
31
|
-
Parameters
|
|
32
|
-
----------
|
|
33
|
-
env: 'TradingEnv'
|
|
34
|
-
The trading environment.
|
|
35
|
-
kwargs : keyword arguments
|
|
36
|
-
Additional keyword arguments for rendering the environment.
|
|
37
|
-
"""
|
|
38
|
-
raise NotImplementedError()
|
|
39
|
-
|
|
40
|
-
def save(self) -> None:
|
|
41
|
-
"""Saves the rendered view of the environment."""
|
|
42
|
-
pass
|
|
43
|
-
|
|
44
|
-
def reset(self) -> None:
|
|
45
|
-
"""Resets the renderer."""
|
|
46
|
-
pass
|
|
47
|
-
|
|
48
|
-
def close(self) -> None:
|
|
49
|
-
"""Closes the renderer."""
|
|
50
|
-
pass
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class AggregateRenderer(Renderer):
|
|
54
|
-
"""A renderer that aggregates compatible renderers so they can all be used
|
|
55
|
-
to render a view of the environment.
|
|
56
|
-
|
|
57
|
-
Parameters
|
|
58
|
-
----------
|
|
59
|
-
renderers : List[Renderer]
|
|
60
|
-
A list of renderers to aggregate.
|
|
61
|
-
|
|
62
|
-
Attributes
|
|
63
|
-
----------
|
|
64
|
-
renderers : List[Renderer]
|
|
65
|
-
A list of renderers to aggregate.
|
|
66
|
-
"""
|
|
67
|
-
|
|
68
|
-
def __init__(self, renderers: List[Renderer]) -> None:
|
|
69
|
-
super().__init__()
|
|
70
|
-
self.renderers = renderers
|
|
71
|
-
|
|
72
|
-
def render(self, env: 'TradingEnv', **kwargs) -> None:
|
|
73
|
-
for r in self.renderers:
|
|
74
|
-
r.render(env, **kwargs)
|
|
75
|
-
|
|
76
|
-
def save(self) -> None:
|
|
77
|
-
for r in self.renderers:
|
|
78
|
-
r.save()
|
|
79
|
-
|
|
80
|
-
def reset(self) -> None:
|
|
81
|
-
for r in self.renderers:
|
|
82
|
-
r.reset()
|
|
83
|
-
|
|
84
|
-
def close(self) -> None:
|
|
85
|
-
for r in self.renderers:
|
|
86
|
-
r.close()
|
|
1
|
+
# Copyright 2020 The TensorTrade Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License
|
|
14
|
+
|
|
15
|
+
from abc import ABCMeta, abstractmethod
|
|
16
|
+
from typing import List
|
|
17
|
+
|
|
18
|
+
from tensortrade.core import Component
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Renderer(Component, metaclass=ABCMeta):
|
|
22
|
+
"""A component for rendering a view of the environment at each step of
|
|
23
|
+
an episode."""
|
|
24
|
+
|
|
25
|
+
registered_name = "renderer"
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def render(self, env: 'TradingEnv', **kwargs):
|
|
29
|
+
"""Renders a view of the environment at the current step of an episode.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
env: 'TradingEnv'
|
|
34
|
+
The trading environment.
|
|
35
|
+
kwargs : keyword arguments
|
|
36
|
+
Additional keyword arguments for rendering the environment.
|
|
37
|
+
"""
|
|
38
|
+
raise NotImplementedError()
|
|
39
|
+
|
|
40
|
+
def save(self) -> None:
|
|
41
|
+
"""Saves the rendered view of the environment."""
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
def reset(self) -> None:
|
|
45
|
+
"""Resets the renderer."""
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
def close(self) -> None:
|
|
49
|
+
"""Closes the renderer."""
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AggregateRenderer(Renderer):
|
|
54
|
+
"""A renderer that aggregates compatible renderers so they can all be used
|
|
55
|
+
to render a view of the environment.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
renderers : List[Renderer]
|
|
60
|
+
A list of renderers to aggregate.
|
|
61
|
+
|
|
62
|
+
Attributes
|
|
63
|
+
----------
|
|
64
|
+
renderers : List[Renderer]
|
|
65
|
+
A list of renderers to aggregate.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(self, renderers: List[Renderer]) -> None:
|
|
69
|
+
super().__init__()
|
|
70
|
+
self.renderers = renderers
|
|
71
|
+
|
|
72
|
+
def render(self, env: 'TradingEnv', **kwargs) -> None:
|
|
73
|
+
for r in self.renderers:
|
|
74
|
+
r.render(env, **kwargs)
|
|
75
|
+
|
|
76
|
+
def save(self) -> None:
|
|
77
|
+
for r in self.renderers:
|
|
78
|
+
r.save()
|
|
79
|
+
|
|
80
|
+
def reset(self) -> None:
|
|
81
|
+
for r in self.renderers:
|
|
82
|
+
r.reset()
|
|
83
|
+
|
|
84
|
+
def close(self) -> None:
|
|
85
|
+
for r in self.renderers:
|
|
86
|
+
r.close()
|