Package: pfund
PFund: Algo-Trading Framework for Machine Learning, TradFi, CeFi and DeFi ready.PFund (/piː fʌnd/), which stands for "Personal Fund", is an algo-trading framework designed for using machine learning models 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,StocksandCryptos.PFund allows traders to:perform vectorized or event-driven backtesting withdifferent resolutions of data, e.g. orderbook data, tick data, bar data etc.different data tools, e.g. pandas,polarsetc.train machine learning models using their favorite frameworks, i.e. PFund isML-framework agnostictune strategy (hyper)parameters by splitting data into training sets, development sets and test setsgo from backtesting to live trading by just changingONE line of code!!It is created to enable trading forPFund.ai- a trading platform that bridges algo-trading and manual trading using AI (LLM).Since PFund's sole purpose is for trading only, for all the data work, 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 ContentsProject StatusMissionCore FeaturesInstallationQuick StartBacktestingLive TradingParameter Training / Hyperparameter TuningBuilding LEGO-Style Strategy and ModelModel HubSupported Trading VenuesRelated ProjectsDisclaimerProject StatusCaution: PFund is at a VERY EARLY stage, use it at your own risk.PFund is currently under active development, the framework design will be prioritized first over
stability and scalability.Please note that the available version is adevversion, not astableone.You are encouraged to play with thedevversion, but only use it when astableversion is released.PFund for the time beingonly supports vectorized backtestingusingBybitand Yahoo Finance data for testing purpose.MissionAs an algo-trader, if you aim to quickly try out some trading ideas to see if they work, and if they do, deploy them for live traidng, it is actually not a trivial task since it involves multiple stages:IdeationStrategy developmentBacktestingModel development (if using machine learning)Model training (if using machine learning)Parameter training / hyperparameter tuningStrategy deploymentPortfolio monitoringThis overview already omits some intricate steps, such as data handling and API integration.PFund's mission is toenable traders to concentrate solely on strategy formulationwhile the framework manages the rest. With PFund serving as the core trade engine, it empowers retail traders to have a fund management experience onPFund.aias if they are operating their personal hedge fund, hence the namePFund.Core FeaturesEasily switch environments with just one line of code, transitioning from backtesting to live tradingSupports machine learning models, features, technical analysis indicatorsBoth Strategy() and Model() are treated as first-class citizensOffers LEGO-style strategy and model building, allowing strategies to add other strategies, models to add other modelsStreamlines the algo-trading flow, from vectorized backtesting for strategy prototyping and event-driven backtesting for strategy development, to live trading for strategy deploymentEnables parallel data processing, e.g. Interactive Brokers and Binance each have their own process for receiving data feedsAllows choosing your preferred data tool, e.g. pandas, polars, pyspark etc.Features a modern frontend usingMantine UIand TradingView's Charts libraryInstallationUsingPoetry(Recommended)poetryaddpfundUsing PippipinstallpfundQuick StartBacktestingimportpfundaspf# NOTE: for more exciting strategies, please visit pfund.aiclassYourStrategy(pf.Strategy):# triggered by bar/kline data (e.g. 1-minute data)defon_bar(self):# write your trading logic herepassengine=pf.BacktestEngine(...)strategy=engine.add_strategy(YourStrategy())strategy.add_data(...)strategy.add_model(...)engine.run()Live TradingJust change one line of code, from 'BacktestEngine' to 'TradeEngine'. BOOM! you can now start live trading.importpfundaspfengine=pf.TradeEngine(env='LIVE')strategy=engine.add_strategy(YourStrategy())strategy.add_data(...)strategy.add_model(...)engine.run()Parameter Training / Hyperparameter TuningThe 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".importpfundaspfengine=pf.TrainEngine()strategy=engine.add_strategy(...)strategy.add_data(...)strategy.add_indicator(...)engine.run()Building LEGO-Style Strategy and Modelimportpfundaspfengine=pf.TradeEngine(env='LIVE')strategy=engine.add_strategy(...)strategy.add_data(...)model=strategy.add_model(...)model.add_data(...)# using different data than strategy'ssub_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()Model HubImagine a space where algo-traders can share their 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.Model Hub is coming soon inPFund.ai, Stay Tuned!Supported Trading VenuesTrading VenueVectorized BacktestingEvent-Driven BacktestingPaper TradingLive TradingBybit🟢🟡🟡🟡*Interactive Brokers (IB)🟡🟡🟡🟡Binance🔴🔴🔴🔴OKX🔴🔴🔴🔴*Alpaca🔴🔴🔴🔴*Futu🔴🔴🔴🔴dYdX🔴🔴🔴🔴🟢 = finished🟡 = in progress🔴 = todo* = use aseparate data source(e.g.FirstRate Data) for backtestingRelated ProjectsPFeed— 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.DisclaimerTHE 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.