The Logic Behind the Market

What is LucraQuant?

LucraQuant is a fully custom-built backtesting engine that lets you simulate, evaluate, and refine your trading strategies using real market data — all in a Python-based Jupyter Notebook environment.

See it in Action

Key Features

Custom Strategy Testing

Develop and test Python-based trading strategies using historical market data

Performance Metrics

Analyze your strategy with key metrics like Sharpe ratio and maximum drawdown

Jupyter Integration

Work in a familiar notebook environment with interactive visualizations

Modular Design

Easily extend and customize the engine to fit your specific trading needs

Get Started

LucraQuant User Manual

1. Introduction

LucraQuant is a modular Python backtesting engine for simulating, evaluating, and visualizing custom trading strategies. This manual will guide you through installation, project structure, usage, and customization.

2. Requirements

  • Python 3.7+
  • Virtualenv (recommended)
  • Libraries (installed via requirements.txt):
pandas
numpy
matplotlib
jupyter

3. Installation

3.1 Download & unzip

unzip lucraquant_full_project_with_requirements.zip
cd lucraquant_full_project

3.2 Create & activate virtual environment

(optional but recommended)

python3 -m venv venv
source venv/bin/activate    # macOS/Linux
venv\Scripts\activate     # Windows

3.3 Install dependencies

pip install -r requirements.txt

4. Project Structure

lucraquant_full_project/
├── strategies/
│   └── my_strategy.py         ← Define your trading logic here
├── engine/
│   ├── backtest_engine.py     ← Core backtest loop & orchestration
│   ├── portfolio.py           ← Cash/position management
│   └── metrics.py             ← Performance metric calculations
├── data/
│   └── AAPL.csv               ← Drop your CSV here (must have a 'Close' column)
├── notebooks/
│   └── run_backtest.ipynb     ← User-facing Jupyter notebook
├── utils/
│   └── visualizations.py      ← Plotting helper (equity curve, trades)
├── README.md                  ← User manual (this file)
└── requirements.txt           ← Python dependencies

5. Usage

5.1 Drop in Historical Data

  • Place any CSV file with at least a Close column (and date index) into data/.
  • Rename it AAPL.csv or update its path in the notebook.

5.2 Define Your Strategy

  • Edit or replace strategies/my_strategy.py.
  • The file must define:
def strategy(data):
    # data: pd.DataFrame of past prices
    # return: 'buy', 'sell', or None

5.3 Run the Notebook

  1. Launch Jupyter:
    jupyter notebook
  2. Open notebooks/run_backtest.ipynb.
  3. Run cells in order:
    • Imports and data load
    • Instantiate BacktestEngine and run
    • Plot results and print metrics

6. Core API (Python Script)

import pandas as pd
from engine.backtest_engine import BacktestEngine
from strategies.my_strategy import strategy

# Load data
data = pd.read_csv("data/AAPL.csv", index_col=0, parse_dates=True)

# Backtest
bt = BacktestEngine(data)
results = bt.run(strategy)

# Plot & metrics
bt.plot()
metrics = bt.get_metrics()
print(metrics)

7. Performance Metrics

  • Total Return
  • Sharpe Ratio (annualized)
  • Max Drawdown

Metrics are computed in engine/metrics.py and returned as a dict.

8. Visualization

  • Equity curve vs. price
  • Trade markers (green = buy, red = sell)

Generated by utils/visualizations.py.

9. Customization & Extensions

  • Fees & slippage: adjust in BacktestEngine init (fee parameter).
  • Additional metrics: extend Metrics.calculate().
  • Alternate plotting: modify or replace utils/visualizations.py.
  • Multiple strategies: duplicate strategies/ files and import in your own scripts or notebooks.

10. Troubleshooting

  • "Module not found": ensure you're in the project root and using the correct import paths.
  • Data errors: verify your CSV has a Close column and properly parsed datetime index.
  • Environment issues: recreate the virtualenv and rerun pip install -r requirements.txt.

11. License & Support

This project is released under the MIT License.

For questions or contributions, please open an issue on the GitHub repo or email me at [email protected].

Enjoy building and testing your quant strategies with LucraQuant!