Larry Williams Volatility Breakout: Vectorised & Iterative Backtester Engine
Larry Williams' famous volatility breakout strategy that was been incorporated in my own proprietary vectorised backtesting, iterative backtesting and optimization engines in Python.
Features
Custom Indicator Integration: Supports the inclusion of complex indicators such as the LW Large Trade Index, Donchian Channels, and volume-based signals.
Multiple Strategies: Tests a buy-and-hold strategy alongside the main strategy so we have direct comparisons.
Dynamic Trade Management: Provides functionalities for opening, closing, and managing long and short positions dynamically based on real-time market data.
Advanced Risk Management: Incorporates take profit and stop loss mechanisms to manage risk effectively.
Performance Metrics: Calculates detailed performance metrics including Sharpe ratio, Sortino ratio, maximum drawdown, and Calmar ratio.
Parameter Optimization: Facilitates optimization of key parameters such as take profit, stop loss, and indicator lookback periods to enhance strategy performance.
Functionality
This backtesting engine operates on the following principles:
Custom Indicator Integration:
LW Large Trade Index (LWLTI): Measures large trade activities and smooths the index using various smoothing techniques (e.g., SMA, EMA).
Volume Indicator: Confirms bullish or bearish volume based on moving averages and current volume levels.
Donchian Channels: Identifies potential breakouts using upper and lower channel boundaries.
Dynamic Trade Management:
Long and Short Entries: Executes long and short trades based on custom signals derived from integrated indicators.
Take Profit and Stop Loss: Automatically closes positions when predefined profit or loss levels are reached.
Position Management: Adjusts the number of units held and manages trade entries and exits based on real-time data.
Performance Metrics:
Net Asset Value (NAV): Tracks the overall value of the trading account over time.
Returns Calculation: Computes log returns for each trading period.
Sharpe Ratio: Measures risk-adjusted returns, both annualized and non-annualized.
Sortino Ratio: Focuses on downside risk and adjusts returns accordingly.
Maximum Drawdown: Assesses the largest peak-to-trough decline in the NAV.
Calmar Ratio: Calculates the risk-adjusted return based on the maximum drawdown.
Optimization
The following parameters can be adjusted to optimize the performance of the trading strategies:
Take Profit Pips: Defines the number of pips at which to take profit for each trade.
Stop Loss Pips: Sets the number of pips at which to stop loss for each trade.
Lookback Periods:
LW Large Trade Index Lookback Period: Determines the period for calculating the LW Large Trade Index.
Volume Indicator Lookback Period: Defines the period for the volume moving average.
Donchian Channel Lookback Period: Sets the period for calculating the Donchian Channels.
Code Snippets & Visualisation
Custom indicators for the strategy
Strategy Performance vs Buy & Hold
Iterative Backtesting Engine Snippet
Performance Metrics
The performance of the trading strategies is evaluated using the following metrics:
Sharpe Ratio:
Annualized Sharpe Ratio: Measures the risk-adjusted return, taking into account annual trading days.
Unannualized Sharpe Ratio: Provides a risk-adjusted return measure without annualization.
Sortino Ratio:
Unannualized Sortino Ratio: Focuses on downside risk to evaluate returns.
Maximum Drawdown:
Max Drawdown: Measures the maximum observed loss from a peak to a trough.
Calmar Ratio:
Calmar Ratio: Assesses the risk-adjusted return by considering the maximum drawdown.
For more information or to discuss your project, shoot me a message on Upwork!