Skip to main content

A Python library for quantitative finance and financial modeling

Project description

IdleFinance

IdleFinance reimagines quantitative finance in Python by embedding portfolio theory, risk modeling, and asset pricing tools directly into the pandas ecosystem.

Rather than acting as a standalone optimizer, IdleFinance extends financial data structures with institutional-grade analytical capabilities through a seamless .finance accessor — transforming raw market data into a research-ready quantitative framework.

🚀 Key Pillars

IdleFinance is built on four core modules:

  1. Portfolio Optimization (Black-Litterman):

    • Full implementation of the J. Walters & T. Idzorek models.
    • Flexible constraint handling (bounds, target sums) and objective functions (Utility vs. Tracking Error).
    • Automated derivation of market-implied risk aversion and prior equilibrium returns.
  2. Risk Metrics:

    • Covariance Estimation:
      • Shrinkage Estimators: Ledoit-Wolf and Oracle Approximating Shrinkage (OAS) for robust covariance matrix estimation.
      • Factor Models: Single-factor (Market) and Multi-factor (Fama-French 3/5 Factor) models for risk decomposition.
      • Dynamic Models: Constant Conditional Correlation (CCC) and Orthogonal GARCH (OGARCH) for time-varying volatility and correlation.
    • Risk Decomposition:
      • Marginal Contribution to Risk (MCTR): Contribution of each asset to total portfolio risk.
      • Component Value at Risk (CVaR): Risk contribution of each asset to the portfolio's Value at Risk.
      • Risk Decomposition: Decomposition of portfolio risk into systematic and idiosyncratic components.
  3. Fixed Income:

    • Unified Bond Pricing: Automatic detection of zero-coupon vs. coupon-bearing bonds.
    • Risk Metrics: Macaulay/Modified Duration, Convexity, and Effective Duration/Convexity (for bonds with embedded options).
    • Yield Analysis: Brent-method optimized YTM, Yield to Call (YTC), and current yield.
    • Arbitrary Cashflows: Duration and NPV analysis for any stream of payments.
  4. Core Utilities:

    • Standard financial math: NPV, IRR, Payback Period, Loan Payments (PMT), and more.
    • Seamless conversion between price data and return series.

📦 Installation (not yet available)

pip install IdleFinance

🛠️ Quick Start

1. Pandas Objects accessor

IdleFinance extends pandas DataFrames and Series with the .finance accessor.

import pandas as pd
import IdleFinance as idf

prices = pd.Series([100, 102, 101, 105, 107])

print(f"Annualized Return: {prices.finance.annualized_return():.2%}")
print(f"Sharpe Ratio: {prices.finance.sharpe_ratio():.2f}")
print(f"Max Drawdown: {prices.finance.max_drawdown():.2%}")

1. Portfolio Optimization with Views

Combine market priors with investor views using the Black-Litterman model.

df_prices = pd.read_csv("portfolio_prices.csv", index_col=0)

post_ret, post_cov, weights = df_prices.finance.black_litterman(
    views={'AAPL': 0.12, 'MSFT': 0.08},
    view_confidences=[0.8, 0.6],
    bounds=(0, 0.30)
)

2. Risk Decomposition

prices = pd.Series([100, 102, 101, 105, 107])

print(f"Annualized Return: {prices.finance.annualized_return():.2%}")
print(f"Sharpe Ratio: {prices.finance.sharpe_ratio():.2f}")
print(f"Max Drawdown: {prices.finance.max_drawdown():.2%}")

3. Comprehensive Asset Valuation

ytm = idf.fixed_income.bond_ytm(price=925.61, face_value=1000, coupon_rate=0.05, years_to_maturity=10)

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

idlefinance-0.1.1.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

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

idlefinance-0.1.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file idlefinance-0.1.1.tar.gz.

File metadata

  • Download URL: idlefinance-0.1.1.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for idlefinance-0.1.1.tar.gz
Algorithm Hash digest
SHA256 351b77b318ff07d5995f600eb0d488329971ee059d8ba43b112658df3c8646bc
MD5 4df4b2714b30165e48d2c26bed464cdd
BLAKE2b-256 8e0925e26a68ba0aa3bd1c9f1f18d2bb511507d1c90c027895bb390b3b3d88a7

See more details on using hashes here.

File details

Details for the file idlefinance-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: idlefinance-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for idlefinance-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4209077b5931c64d848d977421bc63bcda805b6e617ea7838ff94e6fc2055398
MD5 eb7c757d6ee9df207ec653cb2ef606cb
BLAKE2b-256 2cfe245ff6364fcc41ff6db09bf6ca2d416664f5e7c6274b0c28eca7e72d17c5

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