tensortrade.base.context module

class tensortrade.base.context.Context(base_instrument=USD, **kwargs)[source]

Bases: collections.UserDict

A context that is injected into every instance of a class that is a subclass of component.

Parameters:base_instrument (Instrument) – The exchange symbol of the instrument to store/measure value in.
base_instrument
Return type:Instrument
class tensortrade.base.context.TradingContext(base_instrument=USD, **config)[source]

Bases: collections.UserDict

A class for objects that put themselves in a Context using the with statement.

The implementation for this class is heavily borrowed from the pymc3 library and adapted with the design goals of TensorTrade in mind.

Parameters:
  • shared – A context that is shared between all components that are made under the overarching TradingContext.
  • exchanges – A context that is specific to components with a registered name of exchanges.
  • actions – A context that is specific to components with a registered name of actions.
  • rewards – A context that is specific to components with a registered name of rewards.
  • features – A context that is specific to components with a registered name of features.

Warning

If there is a conflict in the contexts of different components because they were initialized under different contexts, can have undesirable effects. Therefore, a warning should be made to the user indicating that using components together that have conflicting contexts can lead to unwanted behavior.

Reference:
__enter__()[source]

Adds a new context to the context stack.

This method is used for a with statement and adds a TradingContext to the context stack. The new context on the stack is then used by every class that subclasses Component the initialization of its instances.

actions
Return type:dict
contexts = <_thread._local object>
exchanges
Return type:dict
features
Return type:dict
classmethod from_json(path)[source]
classmethod from_yaml(path)[source]
classmethod get_context()[source]

Gets the deepest context on the stack.

classmethod get_contexts()[source]
rewards
Return type:dict
shared
Return type:dict
slippage
Return type:dict