Skip to main content

pai-mf

pai-mf is a Python library for collecting mutual fund NAV and market price histories, calculating rolling performance, comparing funds with benchmarks, and scoring those comparisons. The import name is paimf.

The project is open source under the MIT license.

Data access and analysis are separate. You can fetch with the included providers, then save or pass the resulting DataFrames to analysis; you can also analyze your own price data without installing either data provider.

Install

Python 3.10 or newer is required. From a checkout, use uv:

uv sync --extra data --extra plot

The core package needs only NumPy and pandas. Sync the integrations you use:

uv sync                         # analysis and scoring
uv sync --extra yahoo           # add Yahoo Finance
uv sync --extra amfi            # add AMFI/mftool
uv sync --extra data            # add both data providers
uv sync --extra data --extra plot  # add data and Plotly charts

To install the published package, use python -m pip install "pai-mf[data,plot]".

Five-minute example

from paimf import AnalysisConfig, FundAnalysis, FundScoringPipeline
from paimf.providers import MarketData

data = MarketData(max_workers=6)
# These fetch calls use the network. Importing paimf and constructing MarketData do not.
funds = data.get_mutual_funds(["122639", "118989"], errors="raise")
indices = data.get_indices(["NIFTY50"], years=10)

analysis = FundAnalysis(
    funds=funds,
    benchmarks=indices,
    config=AnalysisConfig(
        lookback_years=3,
        frequency="weekly",
        return_type="simple",
        risk_free_rate=0.069,
    ),
)

print(analysis.asset_metrics.tail())
print(analysis.relative_metrics.tail())

pipeline = FundScoringPipeline(analysis)
pipeline.run()
print(pipeline.latest())

The scheme codes are examples. The pipeline looks up fund names from AMFI and includes scheme_code in the result. If AMFI is unreachable, it warns that VPN/network access may be needed and uses the scheme code as the fund label. Verify the code and share class against the current AMFI source before interpreting the output. Provider histories and your own inputs use the same two-column contract: date and price.

Use your own price data

Neither Yahoo Finance nor AMFI is needed if you already have price histories:

import pandas as pd

from paimf import AnalysisConfig, FundAnalysis

fund = pd.DataFrame({
    "date": pd.to_datetime(["2023-01-02", "2023-01-03", "2023-01-04"]),
    "price": [100.0, 100.4, 100.2],
})
benchmark = fund.assign(price=[100.0, 100.2, 100.1])

# Supply full histories in real use; these short frames only show the input shape.
analysis = FundAnalysis(
    funds={"My fund": fund},
    benchmarks={"My index": benchmark},
    config=AnalysisConfig(lookback_years=1, frequency="daily"),
)

A one-year daily window needs about 253 price observations to produce the first full rolling metric; the three-row example shows the input shape only.

What is included

Module Purpose
paimf.providers Fetch indices, arbitrary Yahoo tickers, AMFI scheme NAV histories and current quotes; normalize price frames.
paimf.analysis / paimf.metrics Compute rolling fund and benchmark metrics once per asset, then benchmark-relative metrics on aligned dates.
paimf.features / paimf.scoring Build relative features and monthly quality, consistency, and trend scores.
paimf.profiles Named, inspectable scoring weights.
paimf.visualizations Optional Plotly charts.

Available analysis results include annualized return, volatility, downside deviation, Sharpe, Sortino, maximum drawdown, and Calmar; relative results include alpha, beta, correlation, R-squared, tracking error, information ratio, and upside/downside capture. The standard profiles are consistent_compounder, capital_preservation, and balanced_growth.

Documentation

Scope and data notes

The library returns pandas DataFrames and does not write a database or files during a fetch. Provider responses and availability depend on the upstream services. Historical fund NAV, Yahoo market prices, and current quotes can have different calendars and publication times; pairwise relative metrics align sampled weeks or months across the fund and benchmark. Scores describe the supplied history and configured comparison. They are not forecasts.

Metadata

Release files for pai-mf 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pai-mf 0.1.1
File Size Uploaded
pai_mf-0.1.1.tar.gz 54.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pai-mf 0.1.1
File Interpreter ABI Platform
pai_mf-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 91.8 kB

Release files / pai_mf-0.1.1.tar.gz

Download URL pai_mf-0.1.1.tar.gz
Size 54.5 kB
Tags Source
SHA-256 checksum
How to use checksums
41a9ce0536dc85e49af8c6f439563a7c40b6a425ec8180c4aa14d702ec47b439
BLAKE2b-256 checksum
How to use checksums
481ac1a00953e051a6132e5a90bd489005a97bf871d891eff9054f42918ce3a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / pai_mf-0.1.1-py3-none-any.whl

Download URL pai_mf-0.1.1-py3-none-any.whl
Size 37.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0776d3a51f18fa3bea3ff8bd1d81f7035ab4818393b4af679cb3fad749af729
BLAKE2b-256 checksum
How to use checksums
87bd0ae83cd652300e23696a27c98491136b8615c13e5ad1d473123bac6ba44b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page