> ## Documentation Index
> Fetch the complete documentation index at: https://systematica.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Base

> systematica.signals.base

## Variables

* `SIGNAL_MAPPER`: Mapping of signal keys to human-readable names.

* `VALID_SIGNALS`: Get valid signal keys to human-readable names.

## `no_signals_found_nb`

```python theme={null}
no_signals_found_nb(
    model_output: numpy.ndarray,
) ‑> systematica.signals.base.Signals
```

Create a Signals object with no signals found.

**Parameters**:

| Name           | Type       | Default | Description                                               |
| -------------- | ---------- | ------- | --------------------------------------------------------- |
| `model_output` | `tp.Array` | `--`    | A 2d array representing model predictions for two assets. |

**Returns**:

| Type      | Description                                                 |
| --------- | ----------------------------------------------------------- |
| `Signals` | A Signals object with all entries and exits set to `False`. |

## `Thresholds`

```python theme={null}
Thresholds(
    long_entries: float,
    long_exits: float,
    short_entries: float,
    short_exits: float,
)
```

Named tuple to represent signal thresholds.

### Ancestors

* `builtins.tuple`

### Instance variables

* `long_entries: float`: Long entry signals.

* `long_exits: float`: Long exit signals.

* `short_entries: float`: Short entry signals.

* `short_exits: float`: Short exit signals.

## `Signals`

```python theme={null}
Signals(
    long_entries: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame = nan,
    long_exits: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame = nan,
    short_entries: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame = nan,
    short_exits: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame = nan,
)
```

Named tuple to represent trading signals.

### Ancestors

* `builtins.tuple`

### Instance variables

* `long_entries: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame`: Array or DataFrame indicating long entry signals.

* `long_exits: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame`: Array or DataFrame indicating long exit signals.

* `short_entries: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame`: Array or DataFrame indicating short entry signals.

* `short_exits: numpy.ndarray | pandas.core.series.Series | pandas.core.frame.DataFrame`: Array or DataFrame indicating short exit signals.

* `ndim: int`: Get the number of dimensions of the signals.

* `has_latest_signal: Signals`: Check if the latest row in any of the entry or exit signals has a `True` value.

### Methods

#### `get_latest_signals`

```python theme={null}
get_latest_signals(
    self,
    data: vectorbtpro.data.base.Data,
) ‑> Dict[str, str]
```

Get the names of the signals where the latest row contains a `True` value.

Initially checks if latest row in any of the entry or exit signals has
any `True` values. Then maps signal names and symbols.

<Note>
  Convert signals to `pandas.DataFrame` object automatically.
</Note>

**Returns**:

| Type             | Description                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------ |
| `Dict[str, str]` | Dict of symbols and mapped names if latest row has a `True` value. Empty `dict` otherwise. |

#### `to_frame`

```python theme={null}
to_frame(
    self,
    data: pandas.core.frame.DataFrame | vectorbtpro.data.base.Data,
    clean: bool = False,
) ‑> systematica.signals.base.Signals
```

Convert signals to pandas DataFrame objects.

**Parameters**:

| Name    | Type           | Default | Description                                                   |
| ------- | -------------- | ------- | ------------------------------------------------------------- |
| `data`  | `pd.DataFrame` | `--`    | or vbt.Data Market data used to structure the output signals. |
| `clean` | `bool`         | `False` | Whether to clean the signals before converting.               |

**Raises**:

| Type         | Description                                           |
| ------------ | ----------------------------------------------------- |
| `ValueError` | If signal cleaning fails due to Numba-related errors. |

**Returns**:

| Type      | Description                                     |
| --------- | ----------------------------------------------- |
| `Signals` | Converted signals wrapped as DataFrame objects. |

#### `asframe`

```python theme={null}
asframe(
    self,
    data: pandas.core.frame.DataFrame | vectorbtpro.data.base.Data,
    clean: bool = False,
    level_names: List[str] = None,
) ‑> pandas.core.frame.DataFrame
```

Convert Signals object to a pandas DataFrame.

**Parameters**:

| Name          | Type                                  | Default | Description                                                                                                               |
| ------------- | ------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
| `data`        | `pd.DataFrame`                        | `--`    | or `vbt.Data` Market data used to structure the output signals.                                                           |
| `clean`       | `bool`                                | `False` | Whether to clean the signals before converting.                                                                           |
| `level_names` | `tp.List[str, str], default `None\`\` | `--`    | Names for the levels in the resulting hierarchical index. if `None` defaults to `['signals', 'symbol']`. Defaults to None |

**Returns**:

| Type           | Description               |
| -------------- | ------------------------- |
| `pd.DataFrame` | pandas DataFrame objects. |

#### `clean_signals`

```python theme={null}
clean_signals(
    self,
) ‑> systematica.signals.base.Signals
```

Clean raw signals using pre-defined cleaning functions.

**Returns**:

| Type      | Description                           |
| --------- | ------------------------------------- |
| `Signals` | Cleaned signals with noise reduction. |

#### `fshift`

```python theme={null}
fshift(
    self,
    n: int = 1,
) ‑> systematica.signals.base.Signals
```

Shift forward by n positions.

Numba equivalent to `pd.Series(arr).shift(n)`.

**Parameters**:

| Name | Type            | Default | Description                     |
| ---- | --------------- | ------- | ------------------------------- |
| `n`  | `int, optional` | `--`    | Number of steps. Defaults to 1. |

**Returns**:

| Type      | Description                           |
| --------- | ------------------------------------- |
| `Signals` | Cleaned signals with noise reduction. |

#### `plot`

```python theme={null}
plot(
    self,
    df_or_data: pandas.core.series.Series | pandas.core.frame.DataFrame | vectorbtpro.data.base.Data,
    symbol: str | List[str],
    clean: bool = False,
    start: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    end: str | pandas._libs.tslibs.timestamps.Timestamp = None,
    fig: vectorbtpro.utils.figure.FigureWidget = None,
    **plot_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
```

Plot trading signals over the provided market data.

**Parameters**:

| Name          | Type               | Default | Description                                         |
| ------------- | ------------------ | ------- | --------------------------------------------------- |
| `df_or_data`  | `tp.SeriesFrame`   | `--`    | or vbt.Data Market data to use for plotting.        |
| `symbol`      | `str`              | `--`    | or list of str Symbol(s) to plot.                   |
| `clean`       | `bool`             | `False` | Whether to clean signals before plotting.           |
| `start`       | `str`              | `None`  | The start date. Defaults to `None`.                 |
| `end`         | `str`              | `None`  | The end date. Defaults to `None`.                   |
| `fig`         | `vbt.FigureWidget` | `None`  | Figure widget to update with new plots.             |
| `plot_kwargs` | `tp.Kwargs`        | `--`    | Additional keyword arguments for the plot function. |

**Raises**:

| Type         | Description                                           |
| ------------ | ----------------------------------------------------- |
| `ValueError` | If signal cleaning fails due to Numba-related errors. |

**Returns**:

| Type               | Description                                     |
| ------------------ | ----------------------------------------------- |
| `vbt.FigureWidget` | A figure widget containing the plotted signals. |

#### `select_symbols`

```python theme={null}
select_symbols(
    self,
    symbols: str | int | list[str | int],
) ‑> systematica.signals.base.Signals
```

Select specified symbol(s) unchanged and set all other columns to False.

**Parameters**:

| Name      | Type                            | Default | Description                                                                                                                                           |
| --------- | ------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `symbols` | `str, int, or list[str \| int]` | `--`    | The symbol name(s) (e.g., `BTCUSDT` or `ETHUSDT`) or column index(es) (e.g., `0` or `1`) to keep unchanged. All other columns will be set to `False`. |

**Raises**:

| Type         | Description                                                  |
| ------------ | ------------------------------------------------------------ |
| `ValueError` | If any symbol name is invalid or any index is out of bounds. |

**Returns**:

| Type      | Description                                                                             |
| --------- | --------------------------------------------------------------------------------------- |
| `Signals` | New Signals instance with only the specified symbol(s) retained, others set to `False`. |
