Skip to content

ashutosh691/FinTrade-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FinTrade Engine (C++)

A modular algorithmic trading backtesting system written in C++ that simulates trading strategies on historical price data and evaluates their performance using financial metrics.

This project demonstrates how quantitative trading strategies can be tested before deploying them in real markets.


Overview

FinTrade Engine reads historical market price data, applies a trading strategy, executes simulated trades, tracks portfolio performance, and produces analytics such as profit, win rate, drawdown, and equity curves.

The system replicates the typical research pipeline used in algorithmic trading and quantitative finance.


Key Features

  • Historical market data ingestion
  • Moving Average Crossover trading strategy
  • Simulated portfolio and trade execution
  • Backtesting framework
  • Strategy performance analytics
  • Maximum drawdown calculation
  • Equity curve tracking
  • Export of performance data to CSV
  • Equity curve visualization using Python

System Workflow

Historical Price Data
        ↓
Trading Strategy Evaluation
        ↓
Buy / Sell Signal Generation
        ↓
Trade Execution Simulation
        ↓
Portfolio Update
        ↓
Performance Analytics
        ↓
Equity Curve Generation

Trading Strategy

This project implements a Moving Average Crossover Strategy.

Signal Rules

Short MA > Long MA → BUY
Short MA < Long MA → SELL
Short MA = Long MA → HOLD

Where:

  • Short MA = Moving average of the last 3 prices
  • Long MA = Moving average of the last 5 prices

The crossover of these averages helps detect market trends.


Example Trading Output

BUY EXECUTED
TEST x 5 @ ₹187

SELL EXECUTED
TEST x 5 @ ₹200
Final Trade Profit: ₹65

------ Portfolio ------
Balance: ₹100065

Positions:
TEST : 0 shares
-----------------------

------ Strategy Report ------
Total Trades : 1
Total Profit : ₹65
Win Rate     : 100%
Avg Profit   : ₹65
Max Drawdown : ₹10
-----------------------------

Screenshots

Trading Simulation Output

Terminal Output 1 Terminal Output 2


Strategy Equity Curve

Equity Curve

Performance Metrics

The system evaluates strategies using several metrics:

Metric Description
Total Trades Number of completed trades
Total Profit Overall strategy profit
Win Rate Percentage of profitable trades
Average Profit Mean profit per trade
Max Drawdown Largest drop from peak equity

These metrics help assess strategy profitability and risk.


Equity Curve

The system tracks portfolio value over time and exports it to:

equity_curve.csv

Example:

Step,Equity
1,100000
2,100000
3,100000
4,100000
5,100000
6,100015
7,100005
8,100020
9,100040
10,100065

This data can be visualized to analyze strategy performance over time.


Equity Curve Visualization

A Python script is included to plot the equity curve.

Install dependencies

pip3 install pandas matplotlib

Run visualization

python3 scripts/plot_equity.py

This generates a performance chart of the trading strategy.


Project Architecture

FinTrade Engine
│
├── BacktestEngine
│   Loads historical price data
│
├── TradingEngine
│   Generates buy/sell signals using strategy logic
│
├── PortfolioManager
│   Simulates portfolio trades and tracks balance
│
├── AnalyticsEngine
│   Calculates performance metrics and equity curves
│
└── Main Program
    Orchestrates the full workflow

Project Structure

FinTrade-Engine
│
|__ Screenshots
|   Includes demo screenshots
|
├── src
│   ├── main.cpp
│   ├── MarketDataEngine.cpp
│   ├── TradingEngine.cpp
│   ├── PortfolioManager.cpp
│   ├── BacktestEngine.cpp
│   └── AnalyticsEngine.cpp
│
├── include
│   ├── MarketDataEngine.h
│   ├── TradingEngine.h
│   ├── PortfolioManager.h
│   ├── BacktestEngine.h
│   └── AnalyticsEngine.h
│
├── scripts
│   └── plot_equity.py
│
├── prices.csv
├── equity_curve.csv
└── README.md

Build Instructions

Compile the project:

g++ -std=c++17 src/*.cpp -o fintrade -lcurl -pthread

Run the program:

./fintrade

Technologies Used

  • C++17
  • Standard Template Library (STL)
  • File I/O for historical data processing
  • Python (Matplotlib & Pandas) for visualization

Future Improvements

Possible extensions of the project include:

  • Sharpe ratio calculation
  • Support for multiple trading strategies
  • Real-time market data integration
  • Strategy parameter optimization
  • Strategy comparison framework
  • GUI-based visualization
  • Machine learning based trading signals

Learning Outcomes

This project demonstrates:

  • System design in C++
  • Algorithmic trading concepts
  • Financial data analysis
  • Backtesting framework development
  • Portfolio simulation
  • Risk and performance evaluation

Author

Ashutosh Upreti

Computer Science Student Interested in C++, system design, and quantitative trading systems.

About

C++ algorithmic trading backtesting engine with moving average strategy, portfolio simulation, and performance analytics.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors