def mul(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]": """Computes the multiplication of two float streams. Parameters ---------- s1 : `Stream[float]` The first float stream. s2 : `Stream[float]` or float The second float stream. Returns ------- `Stream[float]` A stream created from multiplying `s1` and `s2`. """ if np.isscalar(s2): s2 = Stream.constant(s2, dtype="float") return BinOp(np.multiply, dtype="float")(s1, s2) return BinOp(np.multiply, dtype="float")(s1, s2)
def sub(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]": """Computes the subtraction of two float streams. Parameters ---------- s1 : `Stream[float]` The first float stream. s2 : `Stream[float]` or float The second float stream. Returns ------- `Stream[float]` A stream created from subtracting `s2` from `s1`. """ if np.isscalar(s2): s2 = Stream.constant(s2, dtype="float") return BinOp(np.subtract, dtype="float")(s1, s2) return BinOp(np.subtract, dtype="float")(s1, s2)
def truediv(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]": """Computes the division of two float streams. Parameters ---------- s1 : `Stream[float]` The first float stream. s2 : `Stream[float]` or float The second float stream. Returns ------- `Stream[float]` A stream created from dividing `s1` by `s2`. """ if np.isscalar(s2): s2 = Stream.constant(s2, dtype="float") return BinOp(np.divide, dtype="float")(s1, s2) return BinOp(np.divide, dtype="float")(s1, s2)
def diff(s: "Stream[float]", periods: int = 1) -> "Stream[float]": """Computes the difference of a float stream. Parameters ---------- s : `Stream[float]` A float stream. periods : int, default 1 The number of periods to lag for until computing the difference. Returns ------- `Stream[float]` The difference stream of `s`. """ return BinOp(np.subtract)(s, s.lag(periods)).astype("float")
def clamp_min(s: "Stream[float]", c_min: float) -> "Stream[float]": """Clamps the minimum value of a stream. Parameters ---------- s : `Stream[float]` A float stream. c_min : float The mimimum value to clamp by. Returns ------- `Stream[float]` The minimum clamped stream of `s`. """ return BinOp(np.maximum)(s, Stream.constant(c_min)).astype("float")
def max(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]": """Computes the maximum of two streams. Parameters ---------- s1 : `Stream[float]` The first float stream. s2 : `Stream[float]` The second float stream. Returns ------- `Stream[float]` The maximum stream of `s1` and `s2`. """ return BinOp(np.maximum)(s1, s2).astype("float")
def rsub(s1: "Stream[float]", s2: "Stream[float]") -> "Stream[float]": """Computes the reverse subtraction of two float streams. Parameters ---------- s1 : `Stream[float]` The first float stream. s2 : `Stream[float]` or float The second float stream. Returns ------- `Stream[float]` A stream created from subtracting `s1` from `s2`. """ if not np.isscalar(s2): raise Exception("Invalid stream operation.") s2 = Stream.constant(s2, dtype="float") return BinOp(np.subtract, dtype="float")(s2, s1)