tensortrade.core.component module

class tensortrade.core.component.Component[source]

Bases: abc.ABC, tensortrade.core.component.ContextualizedMixin, tensortrade.core.base.Identifiable

The main class for setting up components to be used in the TradingEnv.

This class if responsible for providing a common way in which different components of the library can be created. Specifically, it enables the creation of components from a TradingContext. Therefore making the creation of complex environments simpler where there are only a few things that need to be changed from case to case.


The name under which constructor arguments are to be given in a dictionary and passed to a TradingContext.

classmethod __init_subclass__(**kwargs) → None[source]

Constructs the concrete subclass of Component.

In constructing the subclass, the concrete subclass is also registered into the project level registry.

Parameters:kwargs (keyword arguments) – The keyword arguments to be provided to the concrete subclass of Component to create an instance.
default(key: str, value: Any, kwargs: dict = None) → Any[source]

Resolves which defaults value to use for construction.

A concrete subclass will use this method to resolve which default value it should use when creating an instance. The default value should go to the value specified for the variable within the TradingContext. If that one is not provided it will resolve to value.

  • key (str) – The name of the attribute to be resolved for the class.
  • value (any) – The value the attribute should be set to if not provided in the TradingContext.
  • kwargs (dict, optional) – The dictionary to search through for the value associated with key.
registered_name = None
class tensortrade.core.component.ContextualizedMixin[source]

Bases: object

A mixin that is to be mixed with any class that must function in a contextual setting.


Gets the Context the object is under.

Returns:Context – The context the object is under.
class tensortrade.core.component.InitContextMeta[source]

Bases: abc.ABCMeta

Metaclass that executes __init__ of instance in it’s core.

This class works with the TradingContext class to ensure the correct data is being given to the instance created by a concrete class that has subclassed Component.

__call__(*args, **kwargs) → tensortrade.core.component.InitContextMeta[source]
  • args – positional arguments to give constructor of subclass of Component
  • kwargs – keyword arguments to give constructor of subclass of Component

Component – An instance of a concrete class the subclasses Component