jialuechen
flowpylib
Python

Algo Library for Order Flow Inference and TCA

Last updated Jun 29, 2026
138
Stars
10
Forks
4
Issues
0
Stars/day
Attention Score
50
Language breakdown
No language data available.
Files click to expand
README

FlowPylib: Python Library for Order Flow Inference and Transaction Cost Analytics

PyPI - Version Python Versions PyPI Downloads License

FlowPylib is a Python package for transaction cost analysis in financial markets, supporting both stock and forex data at the tick level. The library assists traders and market makers by enabling detailed analysis of market data, reconstruction of metaorders, and simulation of order flows. It also provides various visualization tools and a RESTful API to integrate the analytics into your systems.

Features

  • Tick Data Processing:
Process high-frequency tick data for stocks and forex.
  • MetaOrder Reconstruction:
Reconstruct realistic metaorders using public tick data as ground truth, enabling offline pre-trade cost estimation and execution optimization.
  • Bayesian Change-Point Detection:
Detect regime shifts in order flow to help market makers adjust quoting skew and manage inventory exposure in real time.
  • Buy-Side Order Flow Simulation:
Simulate buy-side order flow to estimate the number of trades required to detect directional alpha in client order flow.
  • Rich Visualizations & Reporting:
Generate interactive charts and dashboards, including candlestick charts, trade flow visualizations, and summary dashboards.
  • RESTful API Integration:
Run an API server to provide analysis as a service, making it easy to integrate with other systems.
  • Multi-Source Data Loading:
Supports CSV, Excel, SQL, KDB+, and other RDBMS data sources.

Installation and Quick Start

pip install -U flowpylib
import flowpylib

Load tick data (supports stocks, forex, etc.)

tickdata = flowpylib.loadtickdata('path/to/tickdata.csv', data_type='stock')

Analyze the tick data

analysisresults = flowpylib.analyzetickdata(tickdata) print("Tick Data Analysis Results:", analysis_results)

Visualize tick data with a summary dashboard

summaryfig = flowpylib.plottickdata(tickdata, plot_type='summary') summaryfig.writehtml('summary_dashboard.html')

More Examples

Loading Data from Different Sources

import flowpylib

From CSV

csvdata = flowpylib.loadtickdata('path/to/tickdata.csv', data_type='stock')

From Excel

exceldata = flowpylib.readexcel('path/to/tickdata.xlsx', sheetname='Tick Data')

Using KDBHandler for KDB+ source

kdb_handler = flowpylib.KDBHandler(host='localhost', port=5000) kdbdata = kdbhandler.loadtickdata('tickdata', '2023.07.15T09:30:00.000', '2023.07.15T16:00:00.000')

Performing Analysis

import flowpylib

Load data for stocks and forex

stockdata = flowpylib.loadtickdata('path/to/stockdata.csv', data_type='stock') forexdata = flowpylib.loadtickdata('path/to/forexdata.csv', data_type='forex')

Analyze stock data

stockanalysis = flowpylib.analyzestocktrade(stockdata, benchmark_data) print("Stock Analysis Results:", stock_analysis)

Analyze forex data

forexanalysis = flowpylib.analyzeforextrade(forexdata, benchmark_data) print("Forex Analysis Results:", forex_analysis)

Calculate slippage and VWAP as examples

slippage = flowpylib.calculateslippage(executedprice=100.05, benchmark_price=100.00) print("Slippage:", slippage)

vwap = flowpylib.calculate_vwap(prices=[100.00, 100.05, 100.10], volumes=[1000, 2000, 1500]) print("VWAP:", vwap)

Generating Visualizations

import flowpylib

Load tick data

tickdata = flowpylib.loadtickdata('path/to/tickdata.csv', data_type='stock')

Create a basic plot

basicfig = flowpylib.plottickdata(tickdata, plot_type='basic') basicfig.savefig('basicplot.png')

Create a candlestick chart

candlestickfig = flowpylib.plottickdata(tickdata, plot_type='candlestick', interval='5min') candlestickfig.writehtml('candlestick.html')

Create an order book depth chart

depthfig = flowpylib.plottickdata(tickdata, plot_type='depth') depthfig.writehtml('depth_chart.html')

Create a trade flow chart

tradeflowfig = flowpylib.plottickdata(tickdata, plottype='trade_flow', window='5min') tradeflowfig.writehtml('tradeflow.html')

Create a summary dashboard

summaryfig = flowpylib.plottickdata(tickdata, plot_type='summary') summaryfig.writehtml('summary_dashboard.html')

Using the RESTful API

import flowpylib

Start the API server

flowpylib.run_api(host='localhost', port=5000)

Now you can make HTTP requests to the API endpoints, for example:

POST http://localhost:5000/analyzetickdata

with JSON body: {"tablename": "tickdata", "starttime": "2023.07.15T09:30:00.000", "end_time": "2023.07.15T16:00:00.000", "symbols": ["AAPL", "GOOGL"]}

Roadmap

  • Q3 2025:
- Expand API capabilities to support advanced query parameters and data aggregation functions. - Add a comprehensive backtesting framework for systematic strategy simulations and scenario analysis.
  • Q4 2025:
- Optimize performance and scalability for handling high-frequency tick data. - Incorporate advanced risk management tools focusing on inventory and market exposure mitigation.

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

This project is licensed under the BSD-2-Clause License - see the LICENSE file for details.

🔗 More in this category

© 2026 GitRepoTrend · jialuechen/flowpylib · Updated daily from GitHub