Skip to main content

Portfolio and market indicator helpers inspired by Markowitz optimization

Project description

Markowitzify

Markowitzify is a lightweight Python library for portfolio optimization (portfolio) and technical-analysis helpers (stonks).

It includes:

  • Portfolio analytics: Markowitz optimization, NCO optimization, Sharpe ratio, Hurst exponent, Monte Carlo simulation, trend scan.
  • Stonks analytics: Fractal indicator, Bollinger bands, RSI, signal generation, and basic strategy backtesting.

Installation

pip install markowitzify

For local development:

pip install -e ".[dev]"

Optional market-data provider extras:

pip install -e ".[data]"

Quickstart (offline-safe)

import numpy as np
import pandas as pd
import markowitzify
import helper_monkey as hm

rng = np.random.default_rng(42)
returns = rng.normal(0.0005, 0.01, size=(200, 4))
prices = 100 * np.exp(np.cumsum(returns, axis=0))
df = pd.DataFrame(prices, columns=["AAA", "BBB", "CCC", "DDD"])

p = markowitzify.portfolio()
p.portfolio = df
p.cov = hm.cov_matrix(df)

p.markowitz()
print(p.optimal)

p.NCO()
print(p.nco)

API Overview

portfolio

p = markowitzify.portfolio(API_KEY=None, verbose=False)

Key methods/attributes:

  • build_portfolio(TKR_list, time_delta, end_date=None, datareader=True, provider="auto")
    • provider="auto" prefers yfinance if installed, otherwise pandas_datareader.
  • build_TSP() (depends on external endpoint availability).
  • import_portfolio(input_path, filename="portfolio.csv", dates_kw="date")
  • markowitz() → sets p.optimal
  • NCO() / optimize_nco() → sets p.nco
  • hurst(), sharpe_ratio(), simulate(), trend()

stonks

s = markowitzify.stonks("AAPL", provider="auto")

Key methods/attributes:

  • fractal()
  • bollinger()
  • RSI()
  • signal()
  • strategize()

Testing / Contributing

Run checks locally:

ruff check .
pytest -q

Notes and limitations

  • External market APIs/providers may change or break over time.
  • Tests are intentionally offline and do not rely on Yahoo/MarketStack/TSP network calls.
  • MarketStack-based portfolio building requires a valid API key.

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

markowitzify-0.1.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

markowitzify-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file markowitzify-0.1.0.tar.gz.

File metadata

  • Download URL: markowitzify-0.1.0.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for markowitzify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c77922ddaadffa8cc7a28b37576fb2446dfcfc2c073909a528891f6bcae93c36
MD5 6533a67d2d1acd45d0f6931914338810
BLAKE2b-256 a20992bf8063261178189ff7a9cd3a0f0ca8e820baf94bf5a552c1ce5b36fcc3

See more details on using hashes here.

File details

Details for the file markowitzify-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: markowitzify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for markowitzify-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a8a4bacded00cb4e8840ee8970294b845eedc43695ddebf93607b0b708dfe08
MD5 3e8396897778e09af14c50e8ab438f3e
BLAKE2b-256 d73e126747c74775dccc232f17405dc99ec2d3298d76fe9e61a7e1575fd383bd

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