QuantDynamics is a Python-based project that facilitates the backtesting of forex trading strategies using historical data from the Oanda API. The project focuses on fetching and storing forex data in an SQLite database and provides a framework for implementing and evaluating various trading strategies.
- Fetches historical forex data from the Oanda API for a specified instrument, granularity, and date range.
- Stores the fetched data in an SQLite database for efficient access and management.
- Implements a modular and reusable design, separating data ingestion, database operations, and backtesting logic.
- Provides a flexible framework for defining and backtesting trading strategies.
- Includes error handling and data validation to ensure data integrity and reliability.
- Utilizes parameterized queries to prevent SQL injection vulnerabilities.
- Offers command-line arguments for easy configuration and customization of data ingestion parameters.
Before running the project, ensure that you have the following prerequisites installed:
- Python 3.7 or higher
- Oanda API key (sign up at Oanda to obtain an API key)
- Clone the repository:
git clone https://github.com/your-username/ForexBacktesterOanda.git
- Navigate to the project directory:
cd ForexBacktesterOanda
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Create a
config
directory in the project root:
mkdir config
- Create a
keys.py
file inside theconfig
directory:
touch config/keys.py
- Open the
keys.py
file and add your Oanda API key:
OANDA_API_KEY = 'YOUR_OANDA_API_KEY'
Replace 'YOUR_OANDA_API_KEY'
with your actual Oanda API key.
To fetch historical forex data and store it in the database, run the following command:
python src/data/data_ingestion.py --instrument EUR_USD --granularity H1 --days 180
This command fetches historical data for the EUR/USD instrument with an hourly granularity (H1) for the last 180 days and stores it in the SQLite database.
You can customize the instrument, granularity, and date range by modifying the command-line arguments.
To backtest a trading strategy, follow these steps:
-
Implement your trading strategy in the
src/strategies
directory, following the provided template. -
Update the
src/backtester/backtester.py
file to include your trading strategy and specify the desired backtesting parameters. -
Run the backtester:
python src/backtester/backtester.py
The backtester will execute your trading strategy on the historical data stored in the database and generate performance metrics and visualizations.
To run the test suite, execute the following command:
pytest tests/
This will run all the test cases defined in the tests/
directory and provide a report of the test results.
Contributions to the ForexBacktesterOanda project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
When contributing, please adhere to the existing code style and follow the project's guidelines for commit messages and pull request descriptions.
This project is licensed under the MIT License.
Forex trading involves substantial risk, and past performance is not indicative of future results. The ForexBacktesterOanda project is provided for educational and informational purposes only. It is not intended as financial advice or a recommendation to engage in forex trading. Always consult with a qualified financial professional before making any trading decisions.
If you have any questions or inquiries about the ForexBacktesterOanda project, please contact the project maintainer.