Arithmetic

All functions · nseries package

Add

func (s Series) Add(y any) Series

Add adds the provided value to each value in the series. The value may be any built-in or defined real numeric scalar type, or another Series; the result always has the receiver’s length. A Series operand is right-aligned with the receiver at the most recent bar: the last values of the two series are added, then the second-last, and so on over the min(len(s), len(y)) bars they share. Positions before that overlap are zero, a longer operand contributes only its trailing bars, and an empty Series operand gives a zero-filled series. A plain []float64 is not a Series: like any other unsupported type it gives a zero-filled series, so convert it with Series(v) or New first. Series are paired by position only; see “Time alignment” in the manual’s “Relative: Alignment” section before combining series with different calendars, missing bars or their own release schedules.

Div

func (s Series) Div(y any) Series

Div divides each value in the series by the provided value. Where the divisor is exactly zero (+0 or -0), the returned value is zero; otherwise the usual IEEE rules apply, so NaN and infinities propagate. The value may be any built-in or defined real numeric scalar type, or another Series; the result always has the receiver’s length. A Series operand is right-aligned with the receiver at the most recent bar, as for Add: each receiver value is divided by the value of y at the same distance from the most recent bar, positions before the overlap are zero, and an empty Series operand gives a zero-filled series. A plain []float64 is not a Series and, like any other unsupported type, gives a zero-filled series. Series are paired by position only; see “Time alignment” in the manual.

Mul

func (s Series) Mul(y any) Series

Mul multiplies each value in the series by the provided value. The value may be any built-in or defined real numeric scalar type, or another Series; the result always has the receiver’s length. A Series operand is right-aligned with the receiver at the most recent bar, as for Add: values at the same distance from the most recent bar are multiplied, positions before the overlap are zero, and an empty Series operand gives a zero-filled series. A plain []float64 is not a Series and, like any other unsupported type, gives a zero-filled series. Series are paired by position only; see “Time alignment” in the manual.

Sub

func (s Series) Sub(y any) Series

Sub subtracts the provided value from each value in the series. The value may be any built-in or defined real numeric scalar type, or another Series; the result always has the receiver’s length. A Series operand is right-aligned with the receiver at the most recent bar, as for Add: each value of y is subtracted from the receiver’s value at the same distance from the most recent bar, positions before the overlap are zero, and an empty Series operand gives a zero-filled series. A plain []float64 is not a Series and, like any other unsupported type, gives a zero-filled series. Series are paired by position only; see “Time alignment” in the manual.