Skip to main content

Xarizmi (read Khwarizmi) project is an educational project that contains tools for technical analysis in Python.

Project description

Xarizmi

Xarizmi (read Khwarizmi) project is an educational project that contains tools for technical analysis in Python.

Installation

pip install xarizmi

If you encounter error in installation use Anaconda and then install ta-lib using: bash conda install -c conda-forge ta-lib and then install other packages.

Example

Build Candlestick

from xarizmi.candlestick import Candlestick
c = Candlestick(
    **{
        "open": 2,
        "low": 1,
        "high": 4,
        "close": 3,
    }
)

Portfolio Rebalancing

import datetime
from xarizmi.models.portfolio import Portfolio, PortfolioItem
from xarizmi.models.rebalance import (
    PortfolioAllocation, PortfolioAllocationItem, rebalance
)
from xarizmi.models.symbol import Symbol

now = datetime.datetime(2024, 11, 26)
btc = Symbol.build("BTC", "USD", "USD", "BINANCE")
eth = Symbol.build("ETH", "USD", "USD", "BINANCE")
sol = Symbol.build("SOL", "USD", "USD", "BINANCE")

# Current holdings
portfolio = Portfolio(items=[
    PortfolioItem(symbol=btc, market_value=90_000, quantity=0.9,  datetime=now),
    PortfolioItem(symbol=eth, market_value=30_000, quantity=10.0, datetime=now),
    PortfolioItem(symbol=sol, market_value=10_000, quantity=62.5, datetime=now),
])

# Desired allocation
target = PortfolioAllocation(items=[
    PortfolioAllocationItem(symbol=btc, weight=0.50),
    PortfolioAllocationItem(symbol=eth, weight=0.30),
    PortfolioAllocationItem(symbol=sol, weight=0.20),
])

result = rebalance(portfolio, target)

for item in result.to_sell():
    print(f"SELL {item.symbol.to_string()}: ${-item.delta_market_value:,.0f}")
# SELL BTC-USD: $25,000

for item in result.to_buy():
    print(f"BUY  {item.symbol.to_string()}: ${item.delta_market_value:,.0f}")
# BUY  ETH-USD: $9,000
# BUY  SOL-USD: $16,000

See examples/rebalance.py for the full runnable script.

Indicators

OBV Indicator

from xarizmi.candlestick import CandlestickChart
from xarizmi.ta.obv import OBVIndicator

# assuming btc_usdt_monthly_data is defined (similar to tests/conftest.py)
c = CandlestickChart.model_validate({"candles": btc_usdt_monthly_data})

obv_indicator = OBVIndicator(candlestick_chart=c, volume='amount')
obv_indicator.compute()
print(obv_indicator.indicator_data)
obv_indicator.plot()

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

xarizmi-0.17.0.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

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

xarizmi-0.17.0-py3-none-any.whl (66.6 kB view details)

Uploaded Python 3

File details

Details for the file xarizmi-0.17.0.tar.gz.

File metadata

  • Download URL: xarizmi-0.17.0.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for xarizmi-0.17.0.tar.gz
Algorithm Hash digest
SHA256 72d60fbf8d9477c938e37250af4b9e9b3bfe678eb6bcca20565923a9a0642ee3
MD5 11158e37baa924a697a7163139038392
BLAKE2b-256 b6e909d4394c3ad39955081274d0a1c41c771d7b5827908bb1b2aa622a802644

See more details on using hashes here.

File details

Details for the file xarizmi-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: xarizmi-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 66.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for xarizmi-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16ca5437885cb3f9e97aba850762cba2f73c14393e38f43a2a827bfe84ab1c29
MD5 b72292f8d1a78d282cd5f0173883c9c1
BLAKE2b-256 58700d88d611f146d4a21b39afd99a7ae6f68d63497cbe42dc1b05318da97d23

See more details on using hashes here.

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