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.18.0.tar.gz (48.2 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.18.0-py3-none-any.whl (67.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xarizmi-0.18.0.tar.gz
Algorithm Hash digest
SHA256 2e00ed8100973e7124211c0f30d973ce67ba4fbe4a277e38e9acf96a897fbc4f
MD5 5e90e942b0a334badf72271247793f6a
BLAKE2b-256 af107fa807d2f9f0558edea38e39cbb2c227b2d5438e1ba823b8db449ba7cf33

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xarizmi-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 67.7 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.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 138b71d3341c818365ee3804fdb56e07f2a720521792d9735d9f2478a154b678
MD5 6c088d218b404127eb7d81db6fb30db9
BLAKE2b-256 9a8765048151aff9d7e4236bc390b68b4e2cc7ee08ae14440b38c30661a6cb4e

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