How to use the tensortrade.instruments.quantity.Quantity function in tensortrade

To help you get started, we’ve selected a few tensortrade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github notadamking / tensortrade / tensortrade / instruments / quantity.py View on Github external
if isinstance(right, Quantity):
            if left.instrument != right.instrument:
                raise IncompatibleInstrumentOperation(left, right)

            if left.path_id and right.path_id:
                if left._path_id != right._path_id:
                    raise QuantityOpPathMismatch(left.path_id, right.path_id)

            right_size = right.size

        if not isinstance(right_size, Number):
            raise InvalidNonNumericQuantity(right_size)

        size = op(left.size, right_size)

        return Quantity(instrument=left.instrument, size=size, path_id=left.path_id)
github notadamking / tensortrade / tensortrade / instruments / quantity.py View on Github external
def __lt__(self, other: Union['Quantity', float, int]) -> bool:
        return Quantity._bool_operation(self, other, operator.lt)
github notadamking / tensortrade / tensortrade / instruments / quantity.py View on Github external
def __add__(self, other: Union['Quantity', float, int]) -> 'Quantity':
        return Quantity._math_operation(self, other, operator.add)
github notadamking / tensortrade / tensortrade / instruments / instrument.py View on Github external
def __rmul__(self, other: float) -> Quantity:
        return Quantity(instrument=self, size=other)
github notadamking / tensortrade / tensortrade / instruments / quantity.py View on Github external
def _bool_operation(left: Union['Quantity', float, int],
                        right: Union['Quantity', float, int],
                        bool_op: operator) -> bool:
        right_size = right

        if isinstance(right, Quantity):
            if left.instrument != right.instrument:
                raise IncompatibleInstrumentOperation(left, right)

            right_size = right.size

        if not isinstance(right_size, Number):
            raise InvalidNonNumericQuantity(right_size)

        boolean = bool_op(left.size, right_size)

        if not isinstance(boolean, bool):
            raise Exception("`bool_op` cannot return a non-bool type ({}).".format(boolean))

        return boolean