NegPart#

Description#

The NegPart class computes the negative part of a value, returning max(-x, 0). Together with PosPart, it decomposes any real number: x = PosPart(x) - NegPart(x). This is useful for separating signed quantities into their positive and negative components, for example splitting signed trade volume into buy volume and sell volume.

Equation:

\[ f(x) = \max(-x, 0) \]

Parameters: NegPart takes no parameters.

NaN handling: NaN values pass through unchanged.

NaN handling#

Policy: ignore. A NaN in any input at index t causes the function to skip that step: output at t is NaN and internal state is unchanged. Subsequent finite samples are processed as if step t had not occurred.

Examples#

Usage example#

import numpy as np
import plotly.graph_objects as go
from screamer import PosPart, NegPart

data = np.linspace(-3, 3, 100)
pos = PosPart()(data)
neg = NegPart()(data)

fig = go.Figure()
fig.add_trace(go.Scatter(y=data, mode='lines', name='Input'))
fig.add_trace(go.Scatter(y=pos, mode='lines', name='PosPart', line=dict(color='green')))
fig.add_trace(go.Scatter(y=neg, mode='lines', name='NegPart', line=dict(color='red')))

fig.update_layout(
    title="PosPart and NegPart Decomposition",
    yaxis_title="Output",
    xaxis_title="Input",
    margin=dict(l=20, r=20, t=40, b=20)
)

fig.show()