Skip to content

vtx100/pdformance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊 Pdformance

"Because nothing beats data"

An all-in-one Python toolkit that pulls transaction performance data from a venue and builds a highly customizable dynamic PDF containing key performance metrics, statistics, plots, and even a short LLM-generated summary.


🔍 What It Does

  • Generates tables of performance metrics, allowing for quick asset-group performance analysis.
  • Generates plots: line, histogram, pie, density, violin, 2-D histogram, box plot.
  • Fully configurable via .env and easily extendable to suit your needs.
  • Allows for customization of the PDF layout.

🚀 Features

Feature Capability
Data Collection Pull transaction logs either locally or from a provider (using a simple connector).
Metric Engine Calculate key performance metrics with a plug-and-play approach, allowing easy extensibility.
Asset-by-Asset Comparison Generate tables of performance metrics, enabling quick analysis by asset group.
Layout Customization Flexible PDF layout customization—build it once for your needs and never touch it again!
LLM Integration Generate quick performance reviews using any Ollama compatible model.
Extensible Easily add new metric functions and data columns for instant use in plots.

⚡ Quick Start

# 1️⃣ Clone the repo
git clone https://github.com/vtx100/pdformance.git
cd pdformance

# 2️⃣ Setup venv
python -m venv .
# Run /Scripts/activate.bat

# 3️⃣ Install dependencies
pip install -r requirements.txt

# 4️⃣(Optional) Create a .env file (see Configuration) and fill in your API keys and LLM settings
# OR generate a sample input file by using `data/random_generator.ipynb`

# 5️⃣ Run the demo
python -m templates.all_features
# → generates example.pdf in the `generations/` folder

👀 See Example Output

You can view a sample generated report here:
generations/example.pdf

This PDF demonstrates the full capabilities of Pdformance, including tables, plots, and LLM-generated summaries.


⚙️ Configuration

Sensitive data and configs live in a .env file.

Variable Purpose
BYBIT_API_KEY Your Bybit API key
BYBIT_API_SECRET Your Bybit API secret
LLM_BASE_URL Base URL for your LLM provider
LLM_MODEL The model name (use ollama list for local models)

📦 Usage

The base functionality is demonstrated in templates/all_features.py.
You can also generate example data using random_generator.ipynb.

📥 Data Retrieval & Sanitization

Local retrieval:

# Read and sanitize logs from file
df = client.read_and_sanitize_logs(data_path)

Provider retrieval:

# Fetch Bybit logs and store the data
logs = client.get_closed_pnl_logs(Interval.WEEK)
client.save_pnl_logs_to_csv(logs, data_path)

# Format logs for further use
formatted_logs = client.sanitize_logs(logs)

📈 Metrics & Statistics

ctx = Context(...)
custom_metrics = get_metrics_from_header_symbols(
    ctx=ctx,
    header_symbols=..., 
    metrics=['all']  # add custom metric names here
)

📊 Plotting

plots_list = [
    (get_plot, (ctx.df, ..., ...), {...}),
    (get_hist, (ctx.df, ...), {...}),
    # Add additional plot types as needed
]

fig = plot_grid(plots=plots_list, cols=2)
pdf.add_plt(fig)

📄 PDF Generation

pdf = PdfGenerator(...)
pdf.add_doc_info(...)
pdf.add_section(...)
pdf.add_llm_response(...)
pdf.add_stats_table(...)
pdf.add_plt(...)
pdf.add_baseline_data(...)
pdf.add_empty_line(...)

🤖 LLM Summary

llm = LLMAgent(
    base_url=os.getenv("LLM_BASE_URL"),
    model=os.getenv("LLM_MODEL"),
)

report = llm.generate_completion(
    prompt=...,
    data=...
)

pdf.add_llm_response(response=report)

🔧 Extending the Tool

✅ Custom Metrics

Define a function in src/metrics.py that accepts a Context and returns a Stat.

def my_custom_metric(ctx: Context) -> Stat:
    # Your implementation here
    return Stat(...)

📈 Custom Plots

Follow the schema of functions inside src/plots.py.

🗣 Add Your Own LLM Prompt

The prompt string in ai_agent.generate_completion() is fully free-form.
You can also overwrite the context parameter to ask for sentiment analysis, trading strategy overview, or other insights.


🤝 Closure

This project was originally built for personal use, as I couldn't find anything similar on the market.
I use it frequently to generate simple performance reports and decided to release it publicly.
Feel free to build on it further if you find it useful.

Happy reporting! 🎉


📜 Licenses

Due to Unicode rendering of LLM output, this project uses Noto Sans.

About

Visualize, evaluate, and share your trading performance with dynamic PDF reports

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors