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

The package is set up for a later PyPI release. These commands install from the repository; they do not publish it. After a release, the equivalent package install will be 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={"Fund A": funds["122639"], "Fund B": funds["118989"]},
    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,
    scheme_codes={"Fund A": "122639", "Fund B": "118989"},
)
pipeline.run()
print(pipeline.latest())

The scheme codes are examples. 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.0

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.0
File Size Uploaded
pai_mf-0.1.0.tar.gz 53.2 kB Details

Built distribution (wheel)

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

Total release size: 90.0 kB

Release files / pai_mf-0.1.0.tar.gz

Download URL pai_mf-0.1.0.tar.gz
Size 53.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f7b6f6ec5da4646aa8b6b2d46e41962dfbc511849881fd1d347f1543499cd781
BLAKE2b-256 checksum
How to use checksums
856f3cff073e4c5ac8eaac2939f1f9232f8460c4c9db9628ecbfbfe1e127259d
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.0-py3-none-any.whl

Download URL pai_mf-0.1.0-py3-none-any.whl
Size 36.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b27f0b05f4f6c6f9d0894fd1f75efab01f0ea8b19be772bc9b74fd19fba995b
BLAKE2b-256 checksum
How to use checksums
8db52ef0c851bd7dc45749353d11fb66bda1c3b12e53e1a08a83108139b8265c
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

0.1.1

2 release files

This release

0.1.0 This release

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