Python project designed to develop and implement backtesting for moving average crossover strategies applied to commodities underlyings
Project description
commomacrossoverbacktest
commomacrossoverbacktest is a Python library designed to facilitate the development and implementation of backtesting for moving average crossover strategies applied to commodity underlyings. The library provides robust tools to simulate and evaluate trading strategies, enabling users to refine their approaches based on historical data.
Features
- Backtesting Framework: Simulate and evaluate trading strategies based on exponential moving average crossovers, with short medium and long MA.
- Commodity Trading: Focused specifically on commodities like gold (
GC=F), crude oil (CL=F), and others. - Customizable Signals: Easily extend or modify signal generation logic using Exponential Moving Averages (EMAs).
- Transaction Logs: Automatic generation of detailed transaction logs and portfolio evolution files.
- Visualization: Plot portfolio value evolution over time for comprehensive strategy evaluation.
- Configurable Parameters: Adjust initial cash, trading universe, and backtesting periods.
- Strategy: Buy when MA_short > MA_medium > MA_long et sell if MA_short < MA_medium < MA_long.
Installation
Install the package using pip:
pip install commomacrossoverbacktest
Usage
Basic Example
Below is an example of running a backtest using a moving average crossover strategy.
from datetime import datetime
from commomacrossoverbacktest.commo_backtest import Backtest
# Define backtest parameters
backtest = Backtest(
initial_date=datetime(2022, 1, 1),
final_date=datetime(2023, 1, 1),
universe=['GC=F', 'CL=F', 'CT=F', 'OJ=F', 'SB=F', 'ZS=F', 'ZC=F'],
initial_cash=1000000
)
# Run the backtest
pnl_df = backtest.run_backtest()
# Visualize the portfolio value evolution
pnl_df.plot(x='Date', y='Portfolio Value', title="Portfolio Value Over Time")
Contributing
Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.
License
commomacrossovernacktest was created by Alexandre Cohen-Skalli as part of a project for the course Python Programming for M2 203 at Paris Dauphine University - PSL.
. It is licensed under the terms of the MIT license.
Credits
commomacrossoverbacktest was created with cookiecutter and the py-pkgs-cookiecutter template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file commomacrossoverbacktest-0.2.0.tar.gz.
File metadata
- Download URL: commomacrossoverbacktest-0.2.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54049a5f3c5aa0c06936da015e183d31c3631bde77459d1400d2cbce0c54a5e6
|
|
| MD5 |
7bc58970ad2927dd79e73979973c8b69
|
|
| BLAKE2b-256 |
1d76d07593ccedd131ae5841732e8ab7ed9f3bf37053e9cdac9c4f954fbe511c
|
File details
Details for the file commomacrossoverbacktest-0.2.0-py3-none-any.whl.
File metadata
- Download URL: commomacrossoverbacktest-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d047a46531c9946808290b29c1207887f31ff1cb9a5a3f4325294f702b2339e5
|
|
| MD5 |
9b57c81212a0d0633e2a748b6dfef04a
|
|
| BLAKE2b-256 |
a1efb0fb475a135df8a0820826b9ba65a11691203cf5d364a76c0b97c4727a81
|