Framework for backtesting quantitative trading algorithims.
Project description
QFIN's Algorithmic Backtester (QFAB)
Setup
To install on your system, use pip:
pip install qfinuwa
API
Strategy
You strategy can be initialised as follows:
class MyCustomStrategy(Strategy):
def __init__(self):
return
def on_data(self, data, indicators, portfolio):
return
Any hyperparameters you want to add to your model you can do in __init__
.
on_data
on_data
takes in data and indicators which are both type dict
, keyed by the stocks. The portfolio class manages buying and selling stocks.
Indicators
To add an indicator to be passed into on_data
during evalutation, define a new function in your strategy class that takes in data and returns a data column of the same length.
# super bad example I need to change this
class MyCustomStrategy(Strategy):
def __init__(self):
return
def on_data(self, data, indicators, portfolio):
return
@Strategy.indicator
def vol_difference(data):
return data['volume'].diff() + addition
In the above example we added an indicator called "vol_difference"
that can be accessed during execution by
def on_data(self, data, indicators, portfolio):
V = indicators["vol_difference"]
return
We can also add parameters to the indicator and strategy itself, but we'll see that later.
Backtester
The Backtester
class runs backtests given the inputs:
- An strategy to test
- Data to test it on
- Hyperparameters for the strategy including
- Strategy Hyperparameters
- Indicator Hyperparameters
- Starting Balance and Fee
- Evaluation time
A backtester can be initialised like so:
backtester = Backtester(['AAPL', 'GOOG'])
You can pass in your strategy when initialising, or later.
backtester = Backtester(['AAPL', 'GOOG'], strategy=MyCustomStrategy)
TODO finish this section.
MIT License
Copyright (c) 2022 Isaac Bergl, QFIN UWA
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.