tensortrade.feed.core.base module

class tensortrade.feed.core.base.Constant(value, dtype: str = None)[source]

Bases: tensortrade.feed.core.base.Stream

A stream that generates a constant value.

forward()[source]

Generates the next value from the underlying data streams.

Returns:T – The next value in the stream.
generic_name = 'constant'
has_next()[source]

Checks if there is another value.

Returns:bool – If there is another value or not.
class tensortrade.feed.core.base.Group[source]

Bases: tensortrade.feed.core.base.Stream

A stream that groups together other streams into a dictionary.

forward() → Dict[T][source]

Generates the next value from the underlying data streams.

Returns:T – The next value in the stream.
has_next() → bool[source]

Checks if there is another value.

Returns:bool – If there is another value or not.
class tensortrade.feed.core.base.IterableStream(source: Iterable[T], dtype: str = None)[source]

Bases: tensortrade.feed.core.base.Stream

A private class used the Stream class for creating data sources.

Parameters:
  • source (Iterable[T]) – The iterable to be used for providing the data.
  • dtype (str, optional) – The data type of the source.
forward() → T[source]

Generates the next value from the underlying data streams.

Returns:T – The next value in the stream.
generic_name = 'stream'
has_next()[source]

Checks if there is another value.

Returns:bool – If there is another value or not.
reset(random_start=0)[source]

Resets all inputs to and listeners of the stream and sets stream value to None.

class tensortrade.feed.core.base.NameSpace(name: str)[source]

Bases: tensortrade.feed.core.base.Named

A class providing a context in which to create names.

This becomes useful in cases where Named object would like to use the same name in a different context. In order to resolve naming conflicts in a DataFeed, this class provides a way to solve it.

Parameters:name (str) – The name for the NameSpace.
class tensortrade.feed.core.base.Named(name: str = None)[source]

Bases: object

A class for controlling the naming of objects.

The purpose of this class is to control the naming of objects with respect to the NameSpace to which they belong to. This prevents conflicts that arise in the naming of similar objects under different contexts.

Parameters:name (str, optional) – The name of the object.
name

The name of the object.

Type:str, optional
generic_name = 'generic'
names = {}
namespaces = []
rename(name: str, sep: str = ':/') → tensortrade.feed.core.base.Named[source]

Renames the instance with respect to the current NameSpace.

Parameters:
  • name (str) – The new name to give to the instance.
  • sep (str) – The separator to put between the name of the NameSpace and the new name of the instance (e.g. ns:/example).
Returns:

Named – The instance that was renamed.

class tensortrade.feed.core.base.Placeholder(dtype: str = None)[source]

Bases: tensortrade.feed.core.base.Stream

A stream that acts as a placeholder for data to be provided at later date.

forward() → T[source]

Generates the next value from the underlying data streams.

Returns:T – The next value in the stream.
generic_name = 'placeholder'
has_next() → bool[source]

Checks if there is another value.

Returns:bool – If there is another value or not.
push(value: T) → None[source]
reset() → None[source]

Resets all inputs to and listeners of the stream and sets stream value to None.

class tensortrade.feed.core.base.Sensor(obj, func, dtype=None)[source]

Bases: tensortrade.feed.core.base.Stream

A stream that watches and generates from a particular object.

forward() → T[source]

Generates the next value from the underlying data streams.

Returns:T – The next value in the stream.
generic_name = 'sensor'
has_next()[source]

Checks if there is another value.

Returns:bool – If there is another value or not.
class tensortrade.feed.core.base.Stream(name: str = None, dtype: str = None)[source]

Bases: typing.Generic, tensortrade.feed.core.base.Named, tensortrade.core.base.Observable

A class responsible for creating the inputs necessary to work in a DataFeed.

Parameters:
  • name (str, optional) – The name fo the stream.
  • dtype (str, optional) – The data type of the stream.
source(iterable, dtype=None)[source]

Creates a stream from an iterable.

group(streams)[source]

Creates a group of streams.

sensor(obj, func, dtype=None)[source]

Creates a stream from observing a value from an object.

select(streams, func)[source]

Selects a stream satisfying particular criteria from a list of streams.

constant(value, dtype)[source]

Creates a stream to generate a constant value.

asdtype(dtype)

Converts the data type to dtype.

__call__(*inputs) → tensortrade.feed.core.base.Stream[~T][T][source]

Connects the inputs to this stream.

Parameters:*inputs (positional arguments) – The positional arguments, each a stream to be connected as an input to this stream.
Returns:Stream[T] – The current stream inputs are being connected to.
accumulate(*args, **kwargs)
apply(*args, **kwargs)
astype(dtype: str) → tensortrade.feed.core.base.Stream[~T][T][source]

Converts the data type to dtype.

Parameters:dtype (str) – The data type to be converted to.
Returns:Stream[T] – The same stream with the new underlying data type dtype.
bool

alias of tensortrade.feed.api.boolean.BooleanMethods

static constant(value: T, dtype: str = None) → tensortrade.feed.core.base.Stream[~T][T][source]

Creates a stream to generate a constant value.

Parameters:
  • value (T) – The constant value to be streamed.
  • dtype (str, optional) – The data type of the value.
Returns:

Stream[T] – A stream of the constant value.

copy(*args, **kwargs)
static extend_instance(instance: tensortrade.feed.core.base.Stream[~T][T], mixin: tensortrade.feed.core.mixins.DataTypeMixin) → tensortrade.feed.core.base.Stream[~T][T][source]

Apply mix-ins to a class instance after creation.

Parameters:
  • instance (Stream[T]) – An instantiation of Stream to be injected with mixin methods.
  • mixin (DataTypeMixin) – The mixin holding the methods to be injected into the instance.
Returns:

Stream[T] – The instance with the injected methods provided by the mixin.

float

alias of tensortrade.feed.api.float.FloatMethods

forward() → T[source]

Generates the next value from the underlying data streams.

Returns:T – The next value in the stream.
freeze(*args, **kwargs)
gather() → List[Tuple[tensortrade.feed.core.base.Stream, tensortrade.feed.core.base.Stream]][source]

Gathers all the edges of the DAG connected in ancestry with this stream.

Returns:List[Tuple[Stream, Stream]] – The list of edges connected through ancestry to this stream.
generic_name = 'stream'
static group(streams: List[tensortrade.feed.core.base.Stream[~T][T]]) → tensortrade.feed.core.base.Stream[dict][dict][source]

Creates a group of streams.

Parameters:streams (List[Stream[T]]) – Streams to be grouped together.
Returns:Stream[dict] – A stream of dictionaries with each stream as a key/value in the dictionary being generated.
has_next() → bool[source]

Checks if there is another value.

Returns:bool – If there is another value or not.
lag(*args, **kwargs)
static placeholder(dtype: str = None) → tensortrade.feed.core.base.Stream[~T][T][source]

Creates a placholder stream for data to provided to at a later date.

Parameters:dtype (str) – The data type that will be provided.
Returns:Stream[T] – A stream representing a placeholder.
reduce(*args, **kwargs)
classmethod register_accessor(name: str)[source]

A class decorator that registers an accessor providing useful methods for a particular data type..

Sets the data type accessor to be an attribute of this class.

Parameters:name (str) – The name of the data type.
classmethod register_generic_method(names: List[str])[source]

A function decorator that registers the decorated function with the names provided as a method to the Stream class.

These methods can be used for any instance of Stream.

Parameters:names (List[str]) – The list of names to be used as aliases for the same method.
classmethod register_mixin(dtype: str)[source]

A class decorator the registers a data type mixin providing useful methods directly to the instance of the class.

Parameters:dtype (str) – The name of the data type the mixin is being registered for.
reset() → None[source]

Resets all inputs to and listeners of the stream and sets stream value to None.

run() → None[source]

Runs the underlying streams once and iterates forward.

static select(streams: List[tensortrade.feed.core.base.Stream[~T][T]], func: Callable[[tensortrade.feed.core.base.Stream[~T][T]], bool]) → tensortrade.feed.core.base.Stream[~T][T][source]

Selects a stream satisfying particular criteria from a list of streams.

Parameters:
  • streams (List[Stream[T]]) – A list of streams to select from.
  • func (Callable[[Stream[T]], bool]) – The criteria to be used for finding the particular stream.
Returns:

Stream[T] – The particular stream being selected.

Raises:

Exception – Raised if no stream is found to satisfy the given criteria.

static sensor(obj: Any, func: Callable[[Any], T], dtype: str = None) → tensortrade.feed.core.base.Stream[~T][T][source]

Creates a stream from observing a value from an object.

Parameters:
  • obj (Any) – An object to observe values from.
  • func (Callable[[Any], T]) – A function to extract the data to be observed from the object being watched.
  • dtype (str, optional) – The data type of the stream.
Returns:

Stream[T] – The stream of values being observed from the object.

static source(iterable: Iterable[T], dtype: str = None) → tensortrade.feed.core.base.Stream[~T][T][source]

Creates a stream from an iterable.

Parameters:
  • iterable (Iterable[T]) – The iterable to create the stream from.
  • dtype (str, optional) – The data type of the stream.
Returns:

Stream[T] – The stream with the data type dtype created from iterable.

str

alias of tensortrade.feed.api.string.StringMethods

static toposort(edges: List[Tuple[tensortrade.feed.core.base.Stream, tensortrade.feed.core.base.Stream]]) → List[tensortrade.feed.core.base.Stream][source]

Sorts the order in which streams should be run.

Parameters:edges (List[Tuple[Stream, Stream]]) – The connections that have been found in the DAG.
Returns:List[Stream] – The list of streams sorted with respect to the order in which they should be run.
warmup(*args, **kwargs)