...
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:
- Signal processing functions for creating oscillators and adjusting returns
- 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
Creating an oscillator
from pathlib import Path
import pandas as pd
from tinycta.signal import osc
path = Path(__name__).resolve().parent.parent
# Load price data
prices = pd.read_csv("data.csv", index_col=0, parse_dates=True)
# Create an oscillator with default parameters
oscillator = prices.apply(osc)
# Create an oscillator with custom parameters
custom_oscillator = prices.apply(osc, fast=16, slow=64, scaling=False)
Adjusting returns for volatility
from tinycta.signal import returns_adjust
# Adjust returns for volatility
adjusted_returns = prices.apply(returns_adjust)
Linear algebra operations
import numpy as np
from tinycta.linalg import solve
# Create a matrix and right-hand side vector
matrix = np.array([[1.0, 0.5], [0.5, 1.0]])
rhs = np.array([1.0, 2.0])
# Solve the linear system
solution = solve(matrix, rhs)
print(solution)
[0. 2.]
📚 API Reference
Signal Processing
osc(prices, fast=32, slow=96, scaling=True): Creates an oscillator based on the difference between fast and slow moving averagesreturns_adjust(price, com=32, min_periods=300, clip=4.2): Adjusts log-returns by volatility and applies winsorizationshrink2id(matrix, lamb=1.0): Performs shrinkage of a matrix towards the identity matrix
Linear Algebra
valid(matrix): Constructs a valid subset of a matrix by filtering out rows/columns with NaN valuesa_norm(vector, matrix=None): Computes the matrix-norm of a vector with respect to a matrixinv_a_norm(vector, matrix=None): Computes the inverse matrix-norm of a vectorsolve(matrix, rhs): Solves a linear system of equations, 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.9.1.tar.gz.
File metadata
- Download URL: tinycta-0.9.1.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c1c9e71d7a4b629c72e2eefb9aa7d3e2aedae96f12fe7d03862bff722568c6e
|
|
| MD5 |
daae64228a438bdf42e54122d4761776
|
|
| BLAKE2b-256 |
9ba27bb04610e6c9cc9fc75f6a46f991950bd9acaa12ed628af7633894fd8e0d
|
Provenance
The following attestation bundles were made for tinycta-0.9.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.9.1.tar.gz -
Subject digest:
3c1c9e71d7a4b629c72e2eefb9aa7d3e2aedae96f12fe7d03862bff722568c6e - Sigstore transparency entry: 985106695
- Sigstore integration time:
-
Permalink:
tschm/TinyCTA@fea1d8e2da3f29d94d41621df5513b69c8bdccb6 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/tschm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
rhiza_release.yml@fea1d8e2da3f29d94d41621df5513b69c8bdccb6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tinycta-0.9.1-py3-none-any.whl.
File metadata
- Download URL: tinycta-0.9.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d1723f914276791642821ecc4bc1bd065e4ef5019253870e5bba3d224b826d6
|
|
| MD5 |
23958230f556bd7449812f4b735af25b
|
|
| BLAKE2b-256 |
9f825a1a8e673092108687580d9256c61d618ccde9fad67b2cff5f68dc2f431d
|
Provenance
The following attestation bundles were made for tinycta-0.9.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.9.1-py3-none-any.whl -
Subject digest:
8d1723f914276791642821ecc4bc1bd065e4ef5019253870e5bba3d224b826d6 - Sigstore transparency entry: 985106732
- Sigstore integration time:
-
Permalink:
tschm/TinyCTA@fea1d8e2da3f29d94d41621df5513b69c8bdccb6 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/tschm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
rhiza_release.yml@fea1d8e2da3f29d94d41621df5513b69c8bdccb6 -
Trigger Event:
push
-
Statement type: