Skip to content

quantillinois/kronos

Repository files navigation

kronos-backtester

Overview

"Kronos-Backtester" is a Python-based toolkit for financial data analysis and backtesting of trading strategies. It provides an effective platform for simulating trading strategies using historical data to evaluate their performance and potential profitability.

Preview

graph-example

Installation

$ pip 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

Troubleshooting & FAQ

Common Questions and Issues

● Q: What if I encounter an error regarding missing data?

● A: Ensure that all required data fields are present in your dataset. Missing data can often lead to errors during the backtesting process.

● Q: How do I handle a strategy that requires multiple stock tickers?

● A: Modify your strategy function to accept and process multiple tickers. Ensure that your backtester is provided with the correct data format.

● Q: The backtester is running very slow. How can I improve its performance?

● A: Performance can be improved by optimizing your strategy code. Consider reducing the complexity of calculations or using efficient data structures.

About

Backtesting framework for Quant Illinois

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •