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.
Files changed (111) hide show
  1. tensortrade/__init__.py +23 -16
  2. tensortrade/agents/__init__.py +7 -7
  3. tensortrade/agents/a2c_agent.py +239 -237
  4. tensortrade/agents/agent.py +52 -49
  5. tensortrade/agents/dqn_agent.py +375 -202
  6. tensortrade/agents/parallel/__init__.py +5 -5
  7. tensortrade/agents/parallel/parallel_dqn_agent.py +172 -170
  8. tensortrade/agents/parallel/parallel_dqn_model.py +85 -83
  9. tensortrade/agents/parallel/parallel_dqn_optimizer.py +96 -90
  10. tensortrade/agents/parallel/parallel_dqn_trainer.py +97 -95
  11. tensortrade/agents/parallel/parallel_queue.py +95 -92
  12. tensortrade/agents/replay_memory.py +54 -52
  13. tensortrade/core/__init__.py +6 -6
  14. tensortrade/core/base.py +167 -173
  15. tensortrade/core/clock.py +48 -48
  16. tensortrade/core/component.py +129 -129
  17. tensortrade/core/context.py +182 -182
  18. tensortrade/core/exceptions.py +211 -211
  19. tensortrade/core/registry.py +45 -45
  20. tensortrade/data/__init__.py +1 -1
  21. tensortrade/data/cdd.py +152 -151
  22. tensortrade/env/__init__.py +2 -2
  23. tensortrade/env/default/__init__.py +96 -89
  24. tensortrade/env/default/actions.py +428 -399
  25. tensortrade/env/default/informers.py +14 -16
  26. tensortrade/env/default/observers.py +475 -284
  27. tensortrade/env/default/renderers.py +787 -586
  28. tensortrade/env/default/rewards.py +360 -240
  29. tensortrade/env/default/stoppers.py +33 -33
  30. tensortrade/env/generic/__init__.py +22 -22
  31. tensortrade/env/generic/components/__init__.py +13 -13
  32. tensortrade/env/generic/components/action_scheme.py +54 -54
  33. tensortrade/env/generic/components/informer.py +45 -45
  34. tensortrade/env/generic/components/observer.py +59 -59
  35. tensortrade/env/generic/components/renderer.py +86 -86
  36. tensortrade/env/generic/components/reward_scheme.py +44 -44
  37. tensortrade/env/generic/components/stopper.py +46 -46
  38. tensortrade/env/generic/environment.py +211 -163
  39. tensortrade/feed/__init__.py +5 -5
  40. tensortrade/feed/api/__init__.py +5 -5
  41. tensortrade/feed/api/boolean/__init__.py +44 -44
  42. tensortrade/feed/api/boolean/operations.py +20 -20
  43. tensortrade/feed/api/float/__init__.py +49 -48
  44. tensortrade/feed/api/float/accumulators.py +199 -199
  45. tensortrade/feed/api/float/imputation.py +40 -40
  46. tensortrade/feed/api/float/operations.py +233 -233
  47. tensortrade/feed/api/float/ordering.py +105 -105
  48. tensortrade/feed/api/float/utils.py +140 -140
  49. tensortrade/feed/api/float/window/__init__.py +3 -3
  50. tensortrade/feed/api/float/window/ewm.py +459 -452
  51. tensortrade/feed/api/float/window/expanding.py +189 -185
  52. tensortrade/feed/api/float/window/rolling.py +227 -217
  53. tensortrade/feed/api/generic/__init__.py +4 -4
  54. tensortrade/feed/api/generic/imputation.py +51 -51
  55. tensortrade/feed/api/generic/operators.py +118 -121
  56. tensortrade/feed/api/generic/reduce.py +119 -119
  57. tensortrade/feed/api/generic/warmup.py +54 -54
  58. tensortrade/feed/api/string/__init__.py +44 -43
  59. tensortrade/feed/api/string/operations.py +135 -131
  60. tensortrade/feed/core/__init__.py +3 -3
  61. tensortrade/feed/core/accessors.py +30 -30
  62. tensortrade/feed/core/base.py +634 -584
  63. tensortrade/feed/core/feed.py +120 -59
  64. tensortrade/feed/core/methods.py +37 -37
  65. tensortrade/feed/core/mixins.py +23 -23
  66. tensortrade/feed/core/operators.py +174 -174
  67. tensortrade/oms/__init__.py +2 -2
  68. tensortrade/oms/exchanges/__init__.py +1 -1
  69. tensortrade/oms/exchanges/exchange.py +176 -164
  70. tensortrade/oms/instruments/__init__.py +5 -5
  71. tensortrade/oms/instruments/exchange_pair.py +44 -44
  72. tensortrade/oms/instruments/instrument.py +161 -161
  73. tensortrade/oms/instruments/quantity.py +321 -318
  74. tensortrade/oms/instruments/trading_pair.py +58 -58
  75. tensortrade/oms/orders/__init__.py +13 -13
  76. tensortrade/oms/orders/broker.py +129 -125
  77. tensortrade/oms/orders/create.py +312 -312
  78. tensortrade/oms/orders/criteria.py +218 -218
  79. tensortrade/oms/orders/order.py +368 -368
  80. tensortrade/oms/orders/order_listener.py +62 -62
  81. tensortrade/oms/orders/order_spec.py +102 -102
  82. tensortrade/oms/orders/trade.py +159 -159
  83. tensortrade/oms/services/__init__.py +2 -2
  84. tensortrade/oms/services/execution/__init__.py +4 -4
  85. tensortrade/oms/services/execution/simulated.py +197 -183
  86. tensortrade/oms/services/slippage/__init__.py +21 -21
  87. tensortrade/oms/services/slippage/random_slippage_model.py +56 -56
  88. tensortrade/oms/services/slippage/slippage_model.py +46 -46
  89. tensortrade/oms/wallets/__init__.py +20 -20
  90. tensortrade/oms/wallets/ledger.py +92 -92
  91. tensortrade/oms/wallets/portfolio.py +330 -329
  92. tensortrade/oms/wallets/wallet.py +376 -365
  93. tensortrade/stochastic/__init__.py +12 -12
  94. tensortrade/stochastic/processes/brownian_motion.py +55 -55
  95. tensortrade/stochastic/processes/cox.py +103 -103
  96. tensortrade/stochastic/processes/fbm.py +88 -88
  97. tensortrade/stochastic/processes/gbm.py +129 -129
  98. tensortrade/stochastic/processes/heston.py +281 -281
  99. tensortrade/stochastic/processes/merton.py +91 -91
  100. tensortrade/stochastic/processes/ornstein_uhlenbeck.py +113 -113
  101. tensortrade/stochastic/utils/__init__.py +2 -2
  102. tensortrade/stochastic/utils/helpers.py +180 -179
  103. tensortrade/stochastic/utils/parameters.py +172 -172
  104. tensortrade/version.py +1 -1
  105. tensortrade-1.0.4.dist-info/METADATA +65 -0
  106. tensortrade-1.0.4.dist-info/RECORD +114 -0
  107. {tensortrade-1.0.0b0.dist-info → tensortrade-1.0.4.dist-info}/WHEEL +1 -1
  108. {tensortrade-1.0.0b0.dist-info → tensortrade-1.0.4.dist-info/licenses}/LICENSE +200 -200
  109. tensortrade-1.0.0b0.dist-info/METADATA +0 -74
  110. tensortrade-1.0.0b0.dist-info/RECORD +0 -114
  111. {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 proportion 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 proportion 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
+
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 gym.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
+ # 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 gym.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):
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()