tensortrade.core.context module¶
-
class
tensortrade.core.context.Context(**kwargs)[source]¶ Bases:
collections.UserDictA context that is injected into every instance of a class that is a subclass of Component.
-
class
tensortrade.core.context.TradingContext(config: dict)[source]¶ Bases:
collections.UserDictA 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
config (dict) – The configuration holding the information for each Component.
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.
References
[1] https://github.com/pymc-devs/pymc3/blob/master/pymc3/model.py
-
__enter__() → tensortrade.core.context.TradingContext[source]¶ Adds a new TradingContext 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.
- Returns
TradingContext – The context associated with the given with statement.
-
__exit__(typ, value, traceback) → None[source]¶ Pops the first TradingContext of the stack.
- Parameters
typ (type) – The type of Exception
value (Exception) – An instance of typ.
traceback (python traceback object) – The traceback object associated with the exception.
-
contexts= <_thread._local object>¶
-
classmethod
from_json(path: str) → tensortrade.core.context.TradingContext[source]¶ Creates a TradingContext from a json file.
- Parameters
path (str) – The path to locate the json file.
- Returns
TradingContext – A trading context with all the variables provided in the json file.
-
classmethod
from_yaml(path: str) → tensortrade.core.context.TradingContext[source]¶ Creates a TradingContext from a yaml file.
- Parameters
path (str) – The path to locate the yaml file.
- Returns
TradingContext – A trading context with all the variables provided in the yaml file.
-
classmethod
get_context() → tensortrade.core.context.TradingContext[source]¶ Gets the first context on the stack.
- Returns
TradingContext – The first context on the stack.
-
classmethod
get_contexts() → List[tensortrade.core.context.TradingContext][source]¶ Gets the stack of trading contexts.
- Returns
List[‘TradingContext’] – The stack of trading contexts.
The shared values in common for all components involved with the TradingContext.
- Returns
dict – Shared values for components under the TradingContext.