Giter VIP home page Giter VIP logo

alpha's Introduction

Quantitative Trading Strategy Backtest

This project develops and tests trading alphas for the Indian and US equity markets, focusing on medium to high-frequency trading strategies. The objective is to create, backtest, and optimize these alphas to enhance trading performance.

Project Overview

Features

  • Develop trading strategies based on given alphas
  • Backtest strategies using historical market data
  • Optimize trading thresholds to maximize profit and loss (PnL)
  • Visualize the performance of the trading strategies

Getting Started

Prerequisites

  • Python 3.x
  • Pandas
  • Numpy
  • Matplotlib

Installation

  1. Clone the repository:

    git clone https://github.com/saurabh4269/alpha.git
    cd alpha
  2. Install the required packages:

    pip install pandas numpy matplotlib
  3. Download the dataset from the provided link and place it in the project directory:

    • Dataset
    • Rename the downloaded file to asset_1.csv and place it in the project directory.

Usage

  1. Run the script:

    python backtest.py
  2. The script will:

    • Load the dataset
    • Optimize the trading thresholds
    • Apply the optimal strategy
    • Backtest the strategy
    • Save the results to backtest_results.csv
    • Visualize the performance

Script Overview

Classes

TradingStrategy

  • Initialization: Accepts build and liquidate thresholds.
  • Method: apply_strategy(data) applies the trading strategy to the dataset.

BacktestEngine

  • Initialization: Accepts a strategy and dataset.
  • Method: run_backtest() applies the strategy, calculates returns and PnL, and generates a cumulative PnL.

Functions

optimize_thresholds(data)

  • Optimizes the build and liquidate thresholds to maximize PnL.

visualize_backtest_results(data)

  • Visualizes the asset price, position over time, and cumulative PnL.

Script Execution

  • The script first optimizes the thresholds.
  • It then applies the optimal strategy and runs the backtest.
  • Finally, it visualizes the results and saves them to a CSV file.

Visualization

Below are example plots generated by the script:

Asset Price and Position Over Time

Price and Position

Cumulative PnL Over Time

Cumulative PnL

alpha's People

Contributors

saurabh4269 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.