Skip to main content

A backtesting framework for the trading strategies developed by Quant Illinois.

Project description

kronos_backtester

Installation

$ pip3 install kronos-backtester

Requirements


Quick Start

from kronos_backtester import Backtester

# Example strategy to be backtested
def momentumStrategy(df, short_window=50, long_window=200, entry_threshold=0.02, exit_threshold=0.01):
    # Strategy code here
    # Inputs: Pandas Dataframe of price data, any relevant parameters for the strategy
        # The Dataframe will have columns 'Close', 'Open', 'High', 'Low', and 'Volume'
    # Output: Pandas Series of signals which are integers -1, 0, 1
        # -1 : Sell, 0 : Hold, 1 : Buy
        # Index of Series should be dates

# The wrapper should only take in a DataFrame and output a Series of signals
# This is essentially one version of the strategy with a specific set of parameters.
def testWrapper(df): 
    return momentumStrategy(df, long_window=100)

bt = Backtester(testWrapper)

# This backtests on a particular ticker with given start and end date
bt.testTickerReport('AAPL', '2010-01-01', '2020-01-01')

# You can also backtest on a custom DataFrame of price data
bt.testCustomReport(customDF)

Backtesting report output (dictionary)

Start 2010-01-01
End 2020-01-01
Duration 2516
Exposure Time 470.5
Net Worth [1000000, ... ,8166774.230371475]
Equity Final 8166774.230371475
Equity Peak 8166774.230371475
Return 7.166774230371475
Buy and Hold Return 10.038871419853216
Max Drawdown -0.1029208755830342
Avg Drawdown -0.09627259509420738
Max Drawdown Duration 19
Avg Drawdown Duration 8.857142857142858
# Trades 4
Win Rate 1.0
Best Trade 0.984095270845883
Worst Trade 0.48189821881601236
Max Trade Duration 669
Avg Trade Duration 470.5
Sharpe Ratio 33.99413578326285
Sortino Ratio nan
Calmar Ratio 69.11692296006356

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kronos_backtester-0.1.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

kronos_backtester-0.1.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file kronos_backtester-0.1.2.tar.gz.

File metadata

  • Download URL: kronos_backtester-0.1.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for kronos_backtester-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3ef197fcb04537e099bf86668354f160ddf8f97b90364beecc6efa087b7ab674
MD5 6af02428f1a1953f57366e3efb310fe6
BLAKE2b-256 66e3e31ff4e136bdbd0fc581ab8b861f472b9d4cb74c4b732f9f8a76f70f8147

See more details on using hashes here.

File details

Details for the file kronos_backtester-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for kronos_backtester-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc926e7a27754e2d873e95753e4337d2476c95ce80c9fbf5a450735ba8f4d43f
MD5 9162b3180332cb948428550d878e2ab5
BLAKE2b-256 d1808b407cb23dbfccd5b4f6c4361fe4da83351c5abce309cc4c72933da6f0ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page