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.13.0.tar.gz (45.9 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.13.0-py3-none-any.whl (63.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xarizmi-0.13.0.tar.gz
Algorithm Hash digest
SHA256 6fb7b9547a7c779c03b5c75f1f6013ed1dfa83261e6b5a92204428f18dfd2813
MD5 58a48a559c4c8f02d505398a72465331
BLAKE2b-256 f058f779d4b065ac6839bbb27507900cdd9df0bd5a7426feaea43277fc439b80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xarizmi-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 63.4 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.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 293dbc92ae4b4f6dc3ff5673d0347ea642553bb2762e7866ba12a653144ae830
MD5 157ff3c02c529d3bdcddb62495e1d7ed
BLAKE2b-256 6c78a95f45cceba8452aacaaa2e8fe84b01d6019e50b4dcf97b1104df8a8cc6c

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