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.
- 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
- Python 3.x
- Pandas
- Numpy
- Matplotlib
-
Clone the repository:
git clone https://github.com/saurabh4269/alpha.git cd alpha
-
Install the required packages:
pip install pandas numpy matplotlib
-
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.
-
Run the script:
python backtest.py
-
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
- Initialization: Accepts build and liquidate thresholds.
- Method:
apply_strategy(data)
applies the trading strategy to the dataset.
- Initialization: Accepts a strategy and dataset.
- Method:
run_backtest()
applies the strategy, calculates returns and PnL, and generates a cumulative PnL.
- Optimizes the build and liquidate thresholds to maximize PnL.
- Visualizes the asset price, position over time, and cumulative PnL.
- 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.
Below are example plots generated by the script: