Skip to main content

pfund: A Complete Algo-Trading Framework powered by Machine Learning and Data Engineering, TradFi, CeFi and DeFi ready.

Discord X Downloads PyPI PyPI - Support Python Versions afterpython Discussions Ask DeepWiki View Code Wiki

⚠️ Important Notice

pfund is NOT a cryptocurrency project.

pfund has never issued any coin or token and has no plans to issue one.

This project is not affiliated with PFund (pfund.tech), Pump.Fund (PFUND), or any similarly named crypto, meme coin, token, launchpad, or blockchain project.

pfund is an open-source Python algorithmic trading framework for backtesting, paper trading, live trading, and AI-driven trading workflows.


This library is NOT ready for use, please wait for 0.1.0 release.

Problem

Machine learning (AI) and data engineering (Big Data) fields are advancing every year, but everyday traders are not able to enjoy the benefits of these improvements, leading to a widening gap between retail traders and professional traders.

Solution

A modern algo-trading framework is needed to bridge the gap between algo-trading, machine learning and data engineering, empowering retail traders with state-of-the-art machine learning models and data engineering tools so that traders only need to focus on strategy research and the framework takes care of the rest.


PFund (/piː fʌnd/), which stands for "Personal Fund", is an algo-trading framework designed for using machine learning models natively to trade across TradFi (Traditional Finance, e.g. Interactive Brokers), CeFi (Centralized Finance, e.g. Binance) and DeFi (Decentralized Finance, e.g. dYdX), or in simple terms, Stocks and Cryptos.

Core Features

  • Supports vectorized and event-driven backtesting with different resolutions of data, e.g. tick data, second data and minute data etc.
  • Dataframe-centric trading workflow
  • Supports machine learning models, features, technical analysis indicators
  • Trains machine learning models using your favorite frameworks, i.e. PFund is ML-framework agnostic
  • Offers LEGO-style strategy and model building, allowing strategies to add other strategies, models to add other models
  • Streamlines the algo-trading flow, from vectorized backtesting for strategy prototyping and event-driven backtesting for strategy development, to live trading for strategy deployment
  • Enables parallel data processing, e.g. Interactive Brokers and Binance each have their own process for receiving data feeds
  • Switches from backtesting to live trading by just changing ONE line of code!!

As PFund is for trading only, for all the data workloads, there is a separate library to handle that:
PFeed - Data pipeline for algo-trading, helping traders in getting real-time and historical data, and storing them in a local data lake for quantitative research.


Table of Contents

Installation

uv add pfund

# pick your data sources, e.g. yfinance for Yahoo Finance
uv add pfeed[yfinance]

# [optional] install pfund-plot for plotting, pick your notebook, e.g. marimo notebook and/or jupyter notebook
uv add pfund-plot[marimo,jupyter]

# [optional] install mtflow for handling trading ops, e.g. adding monitors, running dashboards, etc.
uv add mtflow

# update to the latest version:
uv update pfund

Using Pip

# same as above, you can choose to install "pfund[all]", "pfund[data,ml,fe]", "pfund[data,ml]", "pfund[data]" or "pfund"
pip install "pfund[all]"

# install the latest version:
pip install -U pfund

Checking your installation

$ pfund --version

Quick Start

Backtesting

import pfund as pf

# NOTE: for more exciting strategies, please visit pfund.ai
class YourStrategy(pf.Strategy):
    # triggered by bar/kline data (e.g. 1-minute data)
    def on_bar(self):
        # write your trading logic here
        pass


engine = pf.BacktestEngine(mode='fast')
strategy = engine.add_strategy(YourStrategy(), name='your_strategy')
strategy.add_data(
  'IB', 'AAPL', 'USD', 'STK', resolutions=['1d'],
  backtest={
    # NOTE: since IB does not provide any historical data for backtesting purpose, use data from 'YAHOO_FINANCE'
    'data_source': 'YAHOO_FINANCE',
    'start_date': '2024-01-01',
    'end_date': '2024-02-01',
  }
)
engine.run()

Live Trading

Just change one line of code, from 'BacktestEngine' to 'TradeEngine'. BOOM! you can now start live trading.

import pfund as pf

engine = pf.TradeEngine(env='LIVE')
strategy = engine.add_strategy(YourStrategy(), name='your_strategy')
strategy.add_data(
  'IB', 'AAPL', 'USD', 'STK', resolutions=['1d'],
  # for convenience, you can keep the kwarg `backtest`, `TradeEngine` will ignore it
  backtest={
    # NOTE: since IB does not provide any historical data for backtesting purpose, use data from 'YAHOO_FINANCE'
    'data_source': 'YAHOO_FINANCE',
    'start_date': '2024-01-01',
    'end_date': '2024-02-01',
  }
)
engine.run()

Parameter Training / Hyperparameter Tuning

The correct term should be "Hyperparameter Tuning", but since not all traders are familiar with machine learning, the framework uses a more well-known term "training".

import pfund as pf

engine = pf.TrainEngine()
strategy = engine.add_strategy(...)
strategy.add_data(...)
strategy.add_indicator(...)
engine.run()

Building LEGO-Style Strategy and Model

import pfund as pf

engine = pf.TradeEngine(env='LIVE')
strategy = engine.add_strategy(...)
strategy.add_data(...)
model = strategy.add_model(...)

model.add_data(...)  # using different data than strategy's
sub_model = model.add_model(...)  # YES, model can add another model to its use
# You can keep going:
# sub_sub_model = sub_model.add_model(...)

engine.run()

PFund Hub

Imagine a space where algo-traders can share their trading strategies and machine learning models with one another. Strategy and model development could be so much faster since you can build on top of an existing working model.


Supported Trading Venues

Trading Venue Vectorized Backtesting Event-Driven Backtesting Paper Trading Live Trading
Bybit 🟢 🟡 🟡 🟡
*Interactive Brokers (IB) 🟡 🟡 🟡 🟡
Binance 🔴 🔴 🔴 🔴
OKX 🔴 🔴 🔴 🔴
*Alpaca 🔴 🔴 🔴 🔴
*Futu 🔴 🔴 🔴 🔴
dYdX 🔴 🔴 🔴 🔴

🟢 = finished
🟡 = in progress
🔴 = todo
* = use a separate data source (e.g. FirstRate Data) for backtesting

  • PFeed — Data engine for algo-trading, helping traders in getting real-time and historical data, and storing them in a local data lake for quantitative research.
  • PyTrade.org - A curated list of Python libraries and resources for algorithmic trading.

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

This algo-trading framework is intended for educational and research purposes only. It should not be used for real trading without understanding the risks involved. Trading in financial markets involves significant risk, and there is always the potential for loss. Your trading results may vary. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this platform.

The developers of this framework are not responsible for any financial losses incurred from using this software. Users should conduct their due diligence and consult with a professional financial advisor before engaging in real trading activities.

Metadata

Release files for pfund 0.0.25

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

Source distribution (sdist)

Source distribution for pfund 0.0.25
File Size Uploaded Provenance Actions
pfund-0.0.25.tar.gz 227.5 kB Without provenance Details for pfund-0.0.25.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pfund 0.0.25
File Interpreter ABI Platform Actions
pfund-0.0.25-py3-none-any.whl Python 3 none any Details for pfund-0.0.25-py3-none-any.whl

Total release size: 544.5 kB

Release files / pfund-0.0.25.tar.gz

Download URL pfund-0.0.25.tar.gz
Size 227.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d1e03006b6a84b86a89ad1b4a31cc7aa5906684771460de5311bec050d649a2e
BLAKE2b-256 checksum
How to use checksums
bd247304bc42534f883d6e42b709dd6ae2a3d6401d846785b3f7080457752bf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pfund-0.0.25-py3-none-any.whl

Download URL pfund-0.0.25-py3-none-any.whl
Size 317.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2b8f9a6dd3ac5e3e718c0acb5ee2a6b8931a1c10961c9f2d0a076de41d77b21
BLAKE2b-256 checksum
How to use checksums
80078d17d55f76f42bb029ff93ee1ae162f67c91e9a55800194db57821573eae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pfund 0.0.25

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.25 This release

2 release files No provenance

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