...
Project description
📈 TinyCTA
A Lightweight Python Package for Commodity Trading Advisor Strategies.
Quick Links: 📚 Repository • 📦 PyPI • 🐛 Issues • 💬 Discussions
📋 Overview
TinyCTA provides essential tools for quantitative finance and algorithmic trading, particularly for trend-following strategies. The package includes:
- Polars-based signal processing: oscillators, moving-average crossovers, and volatility-adjusted returns
- Robust volatility estimation via rolling median absolute deviation
- Linear algebra utilities that handle matrices with missing values
- Matrix shrinkage techniques commonly used in portfolio optimization
This package is designed to be the foundation for implementing CTA strategies in just a few lines of code, hence the name "TinyCTA".
🚀 Installation
Using pip
pip install tinycta
From source
Clone the repository and install using the provided Makefile:
git clone https://github.com/tschm/tinycta.git
cd tinycta
make install
This will install uv (a fast Python package installer) and create a virtual environment with all dependencies.
💻 Usage
Oscillator signal (Polars)
import polars as pl
from tinycta.osc import osc
prices = pl.DataFrame({"A": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
result = prices.with_columns(osc(pl.col("A"), fast=2, slow=6).alias("osc_A"))
Moving-average crossover (Polars)
import polars as pl
from tinycta.ewma import ma_cross
prices = pl.DataFrame({"A": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
result = prices.with_columns(
ma_cross(pl.col("A"), fast=2, slow=6).alias("sig_A")
)
Volatility-adjusted returns (Polars)
import polars as pl
from tinycta.util import vol_adj, adj_log_prices
prices = pl.DataFrame({"A": [100, 101, 99, 102, 98, 103]})
result = prices.with_columns(
vol_adj(pl.col("A"), vola=3, clip=4.2).alias("vol_adj_A"),
adj_log_prices(pl.col("A"), vola=3, clip=4.2).alias("adj_log_A"),
)
Linear algebra operations
import numpy as np
from tinycta.linalg import solve
matrix = np.array([[1.0, 0.5], [0.5, 1.0]])
rhs = np.array([1.0, 2.0])
solution = solve(matrix, rhs)
print(solution)
[0. 2.]
📚 API Reference
Signal Processing (tinycta.osc, tinycta.ewma, tinycta.util)
osc(x, fast, slow, min_samples=1)— analytically scaled EWMA-difference oscillator (Polars)ma_cross(prices, fast, slow, min_samples=1)— sign of fast-vs-slow EWM crossover: -1, 0, or +1 (Polars)vol_adj(x, vola, clip, min_samples=1)— clipped, volatility-adjusted log returns (Polars)adj_log_prices(x, vola, clip, min_samples=1)— cumulative sum of volatility-adjusted log returns (Polars)
Signal Utilities (tinycta.signal)
moving_absolute_deviation(price, com=32)— robust rolling volatility estimate via median absolute deviation (pandas)shrink2id(matrix, lamb=1.0)— shrink a matrix towards the identity matrix
Linear Algebra (tinycta.linalg)
valid(matrix)— extract the finite subset of a matrix by filtering NaN rows/columnsa_norm(vector, matrix=None)— matrix-norm of a vectorinv_a_norm(vector, matrix=None)— inverse matrix-norm of a vectorsolve(matrix, rhs)— solve a linear system, handling matrices with NaN values
🛠️ Development
Setting up the development environment
make install
Running tests
make test
Code formatting and linting
make fmt
Cleaning up
make clean
📄 License
TinyCTA is licensed under the MIT License. See the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tinycta-0.12.1.tar.gz.
File metadata
- Download URL: tinycta-0.12.1.tar.gz
- Upload date:
- Size: 1.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adfb8b1693dfa881883f50b77d0290b4c98e9cdc353a6b6fd55b117ba4356949
|
|
| MD5 |
6fc45d881e6b4d2882864144531cee93
|
|
| BLAKE2b-256 |
51c6df4a9bdcd96ad67e4a4591090a30b7b199e6bc64160477825dea2f32b87e
|
Provenance
The following attestation bundles were made for tinycta-0.12.1.tar.gz:
Publisher:
rhiza_release.yml on tschm/TinyCTA
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tinycta-0.12.1.tar.gz -
Subject digest:
adfb8b1693dfa881883f50b77d0290b4c98e9cdc353a6b6fd55b117ba4356949 - Sigstore transparency entry: 1547321071
- Sigstore integration time:
-
Permalink:
tschm/TinyCTA@2e1c1abd6b8bb4966df61f3eb6e35906f7699bc0 -
Branch / Tag:
refs/tags/v0.12.1 - Owner: https://github.com/tschm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
rhiza_release.yml@2e1c1abd6b8bb4966df61f3eb6e35906f7699bc0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tinycta-0.12.1-py3-none-any.whl.
File metadata
- Download URL: tinycta-0.12.1-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a39aa8d3fe30fc9d3f5993784895b49f4d85394afee981acac1fe78e028f2260
|
|
| MD5 |
c1daf467e5c946f5b1af9075ae6c2935
|
|
| BLAKE2b-256 |
82e8a6cb7af6752d9842d858696cf287353b45073aab872dbb9ca5689dc80e14
|
Provenance
The following attestation bundles were made for tinycta-0.12.1-py3-none-any.whl:
Publisher:
rhiza_release.yml on tschm/TinyCTA
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tinycta-0.12.1-py3-none-any.whl -
Subject digest:
a39aa8d3fe30fc9d3f5993784895b49f4d85394afee981acac1fe78e028f2260 - Sigstore transparency entry: 1547321105
- Sigstore integration time:
-
Permalink:
tschm/TinyCTA@2e1c1abd6b8bb4966df61f3eb6e35906f7699bc0 -
Branch / Tag:
refs/tags/v0.12.1 - Owner: https://github.com/tschm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
rhiza_release.yml@2e1c1abd6b8bb4966df61f3eb6e35906f7699bc0 -
Trigger Event:
push
-
Statement type: