Signal¶
Signal processing functions for trend-following CTA strategies.
tinycta.signal
¶
Signal processing functions for trend-following CTA strategies.
Provides oscillator computation and volatility-adjusted return calculations used to generate trading signals from price data.
moving_absolute_deviation(x, com=32)
¶
Compute the rolling median absolute deviation (MAD) of log returns.
A robust alternative to moving standard deviation, less sensitive to outliers. Both the center and dispersion use rolling medians, making the estimate doubly robust. The result is scaled by 1/0.6745 to be a consistent estimator of std under normality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Expr
|
Polars expression representing the price series. |
required |
com
|
int
|
Center of mass used to derive the rolling window as |
32
|
Returns:
| Type | Description |
|---|---|
Expr
|
Polars expression of scaled rolling MAD values consistent with std under normality. |
Source code in src/tinycta/signal.py
shrink2id(matrix, lamb=1.0)
¶
Shrink a square matrix towards the identity matrix by a weight factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
The input square matrix to be shrunk. |
required |
lamb
|
float
|
Mixing ratio for shrinkage. A value of 1.0 retains the original matrix; 0.0 replaces it entirely with the identity matrix. Default is 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The resulting matrix after applying the shrinkage transformation. |