Skip to main content

...

Project description

📈 TinyCTA

PyPI version MIT License Downloads Coverage Status CodeFactor

📦 A lightweight Python package for implementing Commodity Trading Advisor (CTA) strategies with a focus on trend-following signals and linear algebra operations.

📋 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

import pandas as pd
from tinycta.signal import osc

# Load price data
prices = pd.read_csv('tests/resources/prices_hashed.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)
</code></pre>
<h3>Adjusting returns for volatility</h3>
<!--pytest-codeblocks:cont-->
<pre lang="python"><code>from tinycta.signal import returns_adjust

# Adjust returns for volatility
adjusted_returns = prices.apply(returns_adjust)
</code></pre>
<h3>Linear algebra operations</h3>
<pre lang="python"><code>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 averages
  • returns_adjust(price, com=32, min_periods=300, clip=4.2): Adjusts log-returns by volatility and applies winsorization
  • shrink2id(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 values
  • a_norm(vector, matrix=None): Computes the matrix-norm of a vector with respect to a matrix
  • inv_a_norm(vector, matrix=None): Computes the inverse matrix-norm of a vector
  • solve(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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinycta-0.8.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinycta-0.8.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file tinycta-0.8.0.tar.gz.

File metadata

  • Download URL: tinycta-0.8.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tinycta-0.8.0.tar.gz
Algorithm Hash digest
SHA256 606bb9a459ac4a9c7f16e53193011fd6e527336f5a21108d3e2ff5c4145bd489
MD5 09c6047f5456502186fcc19ddb917de5
BLAKE2b-256 3689df3ddbbf6cc69fc999df9c57dcd47ee203878c6b4d49f9d68f690272bde8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinycta-0.8.0.tar.gz:

Publisher: release.yml on tschm/TinyCTA

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinycta-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: tinycta-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tinycta-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d435f9f0830f5e84e4b40d6969790886e62e3d908df99ea7ccd4a305087f3e6
MD5 433bbda47958af3829ddf2092a8eac2d
BLAKE2b-256 2133efe2b83b888aa493cdb3b11d2f33d359a377110b15595e03fadaf25f786e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinycta-0.8.0-py3-none-any.whl:

Publisher: release.yml on tschm/TinyCTA

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page