Skip to main content

Composer Tools

CI

A small library of useful tools for Composer

📦 Installation

pip install composer-tools

🚀 Quick Example

from composer_tools.converters.short_codes import generate_symphony_code

# When SPY's RSI drops below 30, switch to GLD, otherwise stay in BIL
code = generate_symphony_code("RSI_14_SPY_LT_30 GLD,BIL")

This generates:

(defsymphony
 "RSI_14_SPY_LT_30"
 {:asset-class "EQUITIES", :rebalance-frequency :daily}
 (weight-equal
  [(if
      (< (rsi "SPY" {:window 14}) 30.0)
      [(asset "GLD")]
      [(asset "BIL")])])
)

⚙️ How It Works

The format is simple: CONDITION ASSET1,ASSET2

  • CONDITION: When to switch assets
  • ASSET1: What to buy when condition is true
  • ASSET2: What to buy when condition is false

📊 Condition Types

Absolute Conditions

Compare a metric to a fixed value:

generate_symphony_code("RSI_14_SPY_LT_30 GLD,BIL")          # RSI below 30
generate_symphony_code("STD_20_XLU_GT_0.02 TLT,SPY")       # Volatility above 2%
generate_symphony_code("CUMRET_10_SPY_LT_0 CASH,SPY")      # Negative returns

Relative Conditions

Compare metrics between assets:

generate_symphony_code("MA_50_SPY_LT_MA_20_SPY CASH,SPY")        # Death cross
generate_symphony_code("CUMRET_30_XLK_GT_CUMRET_30_XLU XLK,XLU") # Sector rotation

Nested Conditions

Chain conditions with __ (all must be true):

generate_symphony_code("RSI_14_SPY_LT_30__STD_20_SPY_GT_0.02__CUMRET_5_SPY_LT_0 GLD,SPY")

📈 Supported Metrics

  • RSI - Relative Strength Index
  • STD - Standard deviation of returns
  • CUMRET - Cumulative return
  • MA - Moving average

🔢 Supported Operators

  • LT GT EQ LTE GTE - Less than, greater than, equal, etc.

💡Real Examples

# Momentum strategy
generate_symphony_code("RSI_14_QQQ_GT_70 QQQ,TLT")

# Volatility protection  
generate_symphony_code("STD_20_SPY_GT_0.025 TLT,SPY")

# Trend following
generate_symphony_code("MA_20_SPY_GT_MA_50_SPY SPY,CASH")

# Nested statement
generate_symphony_code("RSI_14_SPY_LT_30__STD_20_VIX_GT_25__CUMRET_10_SPY_LT_-0.05 GLD,SPY")

🔧 API

generate_symphony_code(input_str: str) -> str

Converts short notation to Clojure defsymphony code.

parse_condition(condition_str: str) -> dict

Parses condition strings into structured data (useful for debugging).

parse_condition("RSI_14_SPY_LT_30")
# Returns: {'type': 'absolute', 'metric': 'RSI', 'window': '14', 'ticker': 'SPY', 'operator': 'LT', 'value': '30'}

🤝 Contributing

This project is new and contributors are welcome. Please submit a PR!

There's a lot of interesting work to do:

  • More metrics and functions: The rest of the Composer functions
  • Better conditions: OR logic, more complex nesting
  • Performance: Optimization and caching
  • Documentation: More examples and tutorials

Development Setup 🛠️

git clone https://github.com/your-repo/composer-tools
cd composer-tools
uv sync
uv run pytest

All contributions welcome, from typo fixes to major features. The codebase is clean and the tests are comprehensive, so it's easy to jump in.

📄 License

MIT License - use this code however you want.

Metadata

Release files for composer-tools 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for composer-tools 0.1.0
File Size Uploaded
composer_tools-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for composer-tools 0.1.0
File Interpreter ABI Platform
composer_tools-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / composer_tools-0.1.0.tar.gz

Download URL composer_tools-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
04d9f3af24ba620074dd20708166539ef9ba0624acdc7c5a62d4c415ee7dc318
BLAKE2b-256 checksum
How to use checksums
35644d4fe65c95f47d5d080d50cd04d18ee55e1d428be37c8567f53c5b8bb533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.4

Release files / composer_tools-0.1.0-py3-none-any.whl

Download URL composer_tools-0.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4dd14e0724c58e9d14f97734e4c6a9d745075b0956ce8f756334e5376e0bc8c
BLAKE2b-256 checksum
How to use checksums
e5d7f34f8981308ee984601ee76c6b2cfc36e7eb54bb1fa80f54a62837cbbe47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.4

Release history Release notifications | RSS feed

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page