PyTCA is a Python package for transaction cost analysis in financial markets, supporting both stock and forex data at the tick level.
pip install -U pytca
import pytca
# Load tick data
tick_data = pytca.load_tick_data('path/to/tick_data.csv', data_type='stock')
# Analyze tick data
analysis_results = pytca.analyze_tick_data(tick_data)
print("Tick Data Analysis Results:", analysis_results)
# Visualize tick data
fig = pytca.plot_tick_data(tick_data, plot_type='summary')
fig.write_html('tick_data_summary.html')
import pytca
# Load data from CSV
csv_data = pytca.load_tick_data('path/to/tick_data.csv', data_type='stock')
# Load data from Excel
excel_data = pytca.read_excel('path/to/tick_data.xlsx', sheet_name='Tick Data')
# Load data from KDB
kdb_handler = pytca.KDBHandler(host='localhost', port=5000)
kdb_data = kdb_handler.load_tick_data('tickdata', '2023.07.15T09:30:00.000', '2023.07.15T16:00:00.000')
import pytca
# Load data
stock_data = pytca.load_tick_data('path/to/stock_data.csv', data_type='stock')
forex_data = pytca.load_tick_data('path/to/forex_data.csv', data_type='forex')
# Analyze stock data
stock_analysis = pytca.analyze_stock_trade(stock_data, benchmark_data)
print("Stock Analysis Results:", stock_analysis)
# Analyze forex data
forex_analysis = pytca.analyze_forex_trade(forex_data, benchmark_data)
print("Forex Analysis Results:", forex_analysis)
# Calculate slippage
slippage = pytca.calculate_slippage(executed_price=100.05, benchmark_price=100.00)
print("Slippage:", slippage)
# Calculate VWAP
vwap = pytca.calculate_vwap(prices=[100.00, 100.05, 100.10], volumes=[1000, 2000, 1500])
print("VWAP:", vwap)
import pytca
# Load data
tick_data = pytca.load_tick_data('path/to/tick_data.csv', data_type='stock')
# Create basic plot
basic_fig = pytca.plot_tick_data(tick_data, plot_type='basic')
basic_fig.savefig('basic_plot.png')
# Create candlestick chart
candlestick_fig = pytca.plot_tick_data(tick_data, plot_type='candlestick', interval='5min')
candlestick_fig.write_html('candlestick.html')
# Create order book depth chart
depth_fig = pytca.plot_tick_data(tick_data, plot_type='depth')
depth_fig.write_html('depth_chart.html')
# Create trade flow chart
trade_flow_fig = pytca.plot_tick_data(tick_data, plot_type='trade_flow', window='5min')
trade_flow_fig.write_html('trade_flow.html')
# Create summary dashboard
summary_fig = pytca.plot_tick_data(tick_data, plot_type='summary')
summary_fig.write_html('summary_dashboard.html')
import pytca
# Start the API server
pytca.run_api(host='localhost', port=5000)
# Now you can make HTTP requests to the API endpoints, for example:
# POST http://localhost:5000/analyze_tick_data
# with JSON body: {"table_name": "tickdata", "start_time": "2023.07.15T09:30:00.000", "end_time": "2023.07.15T16:00:00.000", "symbols": ["AAPL", "GOOGL"]}
Q4 2024: Implement an order flow simulator which can generate large-scale alpha-less orders,i.e., unbiased trades from randomized interventional experiments.
We welcome contributions! Please see our Contributing Guide for more details.
This project is licensed under the BSD-2-Clause License - see the LICENSE file for details.