Skip to main content

13 posts tagged with "Strategy Library"

Strategy Library

View All Tags

Boxcar-NG: An optimized Boxcar Trade

· 11 min read
Boxcar-NG Logo

Introduction

In the previous post, we analyzed the Boxcar trade’s entry and identified a set of optimization opportunities. In this episode, we will investigate the opportunities outlined: We will use IV Rank, the underlying price’s relations to previous day and the position Greeks at initiation and throughout the trade.


Overfitting: The Danger of Optimization

info

The critical challenge of trading system development is to avoid optimizing on random noise, which is called overfitting. By including too many optimizable parameters we will find a set of parameters that provides excellent in-sample performance but it will fail on unseen data as noise does not repeat by definition.

Our way of tackling overfitting is to set away Out of Sample data to validate our final model. We will be using the 2017 - 2018 timeframe only once, to validate our best model.


 Baseline for optimization

A baseline for optimization should contain the structure and its basic trade rules (such as entry time, exit time and max days in trade). The baseline, however, should not contain any Profit Target and Stop Loss or any optimizable parameter so we can study the trade in its purest form.

The Optimization Baseline for Boxcar looks as follows: https://portal.deltaray.io/backtests/f3cf64be-62af-4005-b43e-f2618b62d97f

Boxcar Optimization Baseline Full

During the optimization process, we will be tracking the following metrics and comparing them to the baseline:

  • Trade Count
  • Alpha
  • Beta
  • Sharpe
  • CAGR %
  • Max Drawdown %
Boxcar Optimization Baseline Metrics

Optimization

Approach

info

Optimization starts by identifying the parameters that might profoundly affect the strategy performance. In the previous article, we identified that market states and greeks are good targets for optimization.

To reduce the chances of overfitting, we are not brute-forcing (i.e., not trying out all combinations) the parameter set. Instead, we are studying how the various parameters are affecting strategy performance by creating experiments where we try multiple values for the respective parameter.

Our parameters for the experiments of the Boxcar trade are:

  • IV Rank
  • Price relation to the previous day’s price (filter for up or down days)
  • Delta
  • Theta

Then we define a valid set of values for each parameter and execute the backtest by combining the baseline with each value of the given parameter. For example, for IV Rank, enter when:

  • IV Rank < 90
  • IV Rank < 80
  • IV Rank < 70
  • Initial Delta = 0
  • Initial Delta = 10
  • Initial Delta = 20

Once we obtain all the performance metrics for each run, we analyze which parameter helps to achieve better performance. If we find that specific parameters are helping our strategy to perform better, we blend them and validate that the combined parameter set works better together than any of the individual parameters alone.

IV Rank Filter

info

IV Rank (Implied Volatility Rank, sometimes also referred to as IVR) is an options trading metric that identifies the implied volatility compared to the IV history of the last 365 days. It’s measured on a scale of 0 to 100, where options with a higher IV Rank are more expensive.

In MesoSim, we use IV Rank as an Entry Filter (via the Entry.Conditions field). IV Rank in our experiment is scaled from 10 to 90 with a step of 10.  For more specific information, please see our documentation's Job Definition Reference section. IV Rank in MesoSim is listed in the underlying variables section.

We have collected all the runs in the following table:

Boxcar Optimization IV Rank Table

Notice the following:

  • The trade count is decreasing as we filter out more and more trades based on the IV Rank
  • Alpha steadily increases until we reach IVRank=60
  • Beta continuously decreases throughout the scaling exercise
  • Sharpe increases until IVRank=50, then starts to decline.
  • An outlier Sharpe is present at IVRank=30
info

Alpha - Alpha is a measure for reporting how much an investment returned compared to an index or other benchmark. The higher the better.

Beta - Beta shows how volatile a security’s performance is compared to the market as a whole. The closer to 0 the better.

Sharpe - The Sharpe ratio compares the return of an investment to its risk. The higher the better, above 1.5 it is considered good.

It is tempting to pick a run where Sharpe is maximized (IVRank=30), but we must proceed with caution: The number of trades is significantly reduced (by 30%), and the run’s Alpha (0.29) is smaller than our baseline run.

We pick the run where IVRank=60, which maximizes our alpha and has a positive impact on Sharpe.

Comparing the IVRank=60 run with our baseline run, we confirm that the IV Rank filter mitigates both COVID Crash and the 2022 Sideways market.

Boxcar Optimization IV Rank 60

Up and Down Day Filter

Sometimes people suggest that a particular strategy works better when opened on “up days” (where the opening price is higher than the previous day’s closing price) or on “down days” (where the opening price is less than the previous day’s closing price).

Our experience with Theta harvesting income strategies is that it is not really relevant. Nevertheless, it is easy to validate by creating an Entry Filter (via Entry.Conditions) field to enter only when we observe the following:

Down Day:

underlying_today_open < underlying_prevday_close

Very Down Day:

underlying_today_open < underlying_prevday_close and underlying_price < underlying_today_open

Up Day:

underlying_today_open > underlying_prevday_close

Very Up Day:

underlying_today_open > underlying_prevday_close and underlying_price > underlying_today_open

The collected results in the table below show that these filters didn't improve the strategy’s performance. We did notice that the “Down Days” and “Very Down Days” scenarios worsened the performance. Therefore we included a filter that only enters when those conditions are not true: NotDownDay, NotVeryDownDay.

Unfortunately, neither of these test scenarios provides any meaningful improvement on the strategy; therefore, we will not use these filters in the combined run.

Boxcar Optimization Up and Down Days Table

Delta at Initiation

info

Delta plays a vital role in strategy development.Simply put, it describes the directionality of the trade.

A delta of 100 for a 1-lot trade follows exactly the underlying, while a delta of -100 moves in the opposite direction. With income trades, delta neutrality (delta=0) is often targeted; however, with the Boxcar trade, the author specifies delta=10 as the initial target for the 10-lot trade.

Given that too much directionality exposes the trade to the underlying movement, we suspect this isn’t ideal. To avoid too much directionality, we create an Exit Condition that closes the trade once Delta reaches 15, 20, 25, … 100 for the 10 lot position (MaxDelta-15, … MaxDelta-100). Running these experiments, we do not observe any reasonable improvement in the overall trade.

Modifying the trade such that the position that it becomes delta neutral at initiation (DeltaNeutral-Start: delta=0 at initiation) shows significant improvement both for Alpha and Beta statistical measures. We will use this modification in the combined run along with the previously selected IV Rank filter.

Boxcar Optimization Delta Table

Theta Filter

We observed in the original trade that Theta could become negative, which is counterproductive for an income trade where we are getting paid (as Theta is positive) by Selling Options. We suspect that positive theta at initiation (ThetaFilter-Positive) has a positive effect on the trade. It might also be helpful to exit trades early when the position theta becomes too low (ThetaFilter-Decay-*) compared to the position theta at the initiation.

The Theta Positivity Check at initiation is done via Entry.AbortCondition which is evaluated immediately after the legs for the position is selected but before the trade is entered. Using this construct, we can abort trade entries if the conditions aren’t ideal (such as position theta being negative).

For the Theta Decay Filter, we are recording the Position Theta at initiation to the initial_theta variable and setting an Exit.Condition statement which validates that the current position theta is still greater than 50%, 33%, or 25% of the initial_theta value.

Boxcar Optimization Theta Table

After execution, we conclude that Positive Theta at initiation helps somewhat the Risk-Adjusted Return (Sharpe), but it degrades both Alpha and Beta. Similarly, the Theta Decay filters are proven ineffective - likely since we are exiting trades early and not entering before the following Thursday or Friday.

Due to the lack of improved performance, we will not consider Theta-based filters in our combined runs.

Combined Run

We went through a series of optimization attempts and identified IVRank=60 and DeltaNeutralStart cases which had a positive impact on the strategy performance. We expect that if we combine the two, we will see further improvements as the two optimizations target different weaknesses of the strategy.

The combined run of the two parameters can be found here: https://portal.deltaray.io/backtests/8cf8b3ea-5f02-4c2d-8e85-440ccdd07b4c

Boxcar Optimization Combined Without Stop Loss

The run confirms that the performance is indeed better than the original setup, the IVRank=60 filter, and the Delta Neutral setup.

Both the strategy’s Alpha and Beta improved, while the Sharpe ratio (our risk-adjusted return metric) substantially improved. However, we note that the Max Drawdown is still too much: 25%. To recover from a 25% loss, we need to gain over 30%.

To address the Max Drawdown, we still have one final parameter to optimize: The Stop Loss of the strategy. MesoSim’s Intra-trade drawdown chart helps to set a reasonable price target for StopLoss: 

Boxcar Optimization Combined Intra-Trade PnL

The graph displays each trade's maximum (unrealized) profit, maximum (unrealized) loss, and realized loss. From the graph, we notice that around $2k loss would be considered normal or acceptable for the majority of 2020 and 2021. A fixed dollar amount (such as $2000) works for some time, but it will be skewed as the underlying changes over time. Therefore, we are instead defining the StopLoss based on the Underlying Price:

For 2019, ^SPX was trading at around $2500 - $3000. If we take 70% of the underlying, we will end up at around the $2k mark, which looks like a reasonable target for Stop Loss. Alternatively, we could consider the overall structure’s price as a basis for our calculation.

Adding underlying_price * 0.7 as Exit.StopLoss results in the following run: https://portal.deltaray.io/backtests/21ae1a3d-c146-40d2-bed4-fb8d1c13c026

Boxcar-NG With Stop Loss

Looking at the metrics, we can confirm that the trade’s metric is now in the respectable range both in terms of Alpha, CAGR, Max Drawdown, and Sharpe.

Boxcar Optimization Combined Table

Validation

info

As a final step, we need to validate our optimization using Out of Sample (OOS) data. To quote Timothy Masters: “Out Of Sample data is precious. Use it once. Or very few times”.

We will use the 2017-2018 time frame for our validation as it covers a grind-up and sideways market. We expect the OOS run to degrade somewhat regarding algo performance (Alpha, Beta, Sharpe). Our acceptance criteria will be that the overall performance Sharpe-wise (risk-adjusted return) outperforms the ^SPX buy-and-hold strategy.

The resulting run looks as follows: https://portal.deltaray.io/backtests/a7bb0205-dbf4-453b-9882-23b1de6f836e

Boxcar Optimization Out Of Sample

Summary

success

We have taken the Boxcar trade modeled in MesoSim and optimized it using market state and greeks. We identified that the IV Rank filter and Delta Neutral setup positively impact strategy performance. We combined the two optimizations and validated them using OOS data.

The resulting run seems promising regarding risk-adjusted return: Sharpe being 1.32 on Out of Sample data.

As the trade setup rules are now deviating from the original one, we name this trade Boxcar-NG.

The trades performance for the 2017 - 2022 period looks as follows:

Boxcar-NG Full Performance

The associated run is available here: https://portal.deltaray.io/backtests/1c8fffc3-f463-4736-9ec7-e4c88658aa94

The collected measurements, including the individual runs, are available via this sheet.

Thank you for reading through this long article, we hope you enjoyed the journey!

Boxcar Trade

· 8 min read
Boxcar Trade

Introduction

We want to present the Boxcar trade, which we consider a good starting point for income strategy development. The trade was originally developed by Dan Harvey and presented multiple times by various lecturers at Aeromir Corporation.  

This article summarizes the trade specifics shown in the video. Some trade rules seem to be slightly different in the Example Trade vs. on the Trade Guidelines slides (both are presented in the video). In such cases, our analysis is based on the Example Trade.

Full disclosure: We are not affiliated, associated, authorized, or endorsed by Aeromir. The information shown in this blog post is for informational purposes only and shouldn’t be taken as investment advice.


Trade rules

Boxcar Trade Guidelines 1
Boxcar Trade Guidelines 3

Based on the entry rules shown in the video, we came up with the following trade plan:

We will be trading SPX options and entering every Thursday or Friday and keep the position open for 7 days at most. Our planned capital is $25k per 10 lot trade, and we backtest more than 3.5 years to ensure that multiple market conditions are covered: grind up (2019 and 2021), crashing (2020), and sideways (2022).

As described in the guidelines, the Boxcar trade consists of a Put Credit Spread (pcs) and a Put Debit Spread (pds) at 8 DTE expiration. The four legs of the trade are defined as follows:

pcs_short

-10 @ Strike located at 10-12 delta. (First slide, third bullet)

In MesoSim we define this with the Delta StrikeSelector:

 "Delta": "10"

pcs_long

+10 @ Strike 25 points below the pcs_short. (First slide, fourth bullet)

The relative strike can be specified using the Statement StrikeSelector:

"Statement": "leg_pcs_short_strike - 25" 

pds_long

+1 @ 1 to 3 strikes Out Of the Money. (Second slide, fourth bullet)

To calculate N strike out of the money, we need to consider that SPX has strikes defined every $5. To find the nearest strike, we divide the current SPX Price (underlying_price variable) with $5, then round it down to the nearest integer with the floor() function. Then, multiply it back by five to end up at a valid strike. Going one strike out of the money means simply subtracting the strike increment (5) from the calculation:

"Statement": "floor(underlying_price/5)*5 - 1 * 5"

pds_short

-1 @ Strike selected so that the overall position delta equals the number of lots traded (10).

To specify a strike based on Delta, we use the same strike Delta-based Strike Selector that we have used at pcs_short leg. MesoSim provides the pos_delta variable, representing the position we have built so far. At the point of evaluation, we have the pcs_short, pcs_long, and pds_long legs in the position. Therefore pos_delta represents their cumulative delta. If we would like to end up at 10 delta, we need to take the current delta accumulated so far (pos_delta), multiply it by -1 to end up at 0 delta, and add 10:

 -1 * pos_delta + 10 = 10 - pos_delta
"Delta": "10 - pos_delta"

To better understand how pds_short is calculated please refer to the Delta Hedging section of our documentation.

The full definition of the trade can be studied via the Run’s Job Definition tab.

Please refer to our documentation to get a better understanding of what each section and field represents.


Adjustments

The Boxcar trade comes with a handful of adjustment rules which are not too exact (or, in other words: somewhat discretionary). It's our experience that trades with numerous adjustment rules are much more complex to manage than slap-on/slap-off types of trades.

Therefore, we are not aiming to replicate the adjustment rules in this article fully but to develop a baseline that correctly replicates the entry. Then we will use this baseline in follow-up posts to tune and optimize the trade.


Backtest Results

Putting the trade rules into MesoSim results in the following run: https://portal.deltaray.io/backtests/b736250e-ab35-4e92-835f-47e763cc460c

Boxcar Baseline MesoSim Screenshot

Using MesoSim’s Export to OptionNet Explorer functionality, it is easy to load the run into OptionNetExplorer and validate that the simulated trade matches the original structure described in the video:

Boxcar Structure in OptionNet Explorer

Analysis

This section will analyze the backtest result and identify optimization opportunities to improve performance and reduce downside risk. On the OptionNet Explorer’s chart, we can see that we have relatively flat T+x lines if the price of the underlying remains the same or goes higher. In case of a large down move, the structure will gain a significant amount of delta.

Equity Graph

The (log-based) equity graph shows that the strategy outperforms the SPX buy-and-hold strategy. It is easy to notice that this strategy suffers during the COVID crash and doesn’t perform well when the market moves sideways (2022). 

Boxcar Equity Graph
Potential optimization

Certain market regimes can be identified (and therefore filtered) using the underlyings’ IV Rank or Percentile.

Metrics

Based on the Sharpe ratio of 0.97, we can conclude that the trade performs better than the simple buy and hold of SPX for the given period in terms of risk-adjusted return. Note that a Sharpe ratio above 1 can be considered adequate; above 1.5 is good, while above 2.5 can be considered excellent.

The CAGR and the Max Drawdown are higher than the buy and hold strategy. The Max Drawdown for this slap-on/slap-off version of Boxcar is almost -50%. We believe that with proper adjustments, the Max Drawdown would improve.

Boxcar Metrics

Greeks

Delta

Delta describes the rate of change between the underlying and the option’s price.

The Account Greeks chart confirms that the 10 lot trade is opened at 10 delta, which the video suggests. The delta values deviating far from the initial value are happening due to notable moves on the underlying. The more SPX moves in one direction, the further it drives our delta from the starting point.

Boxcar Delta
Potential optimization

A delta-neutral strategy is beneficial as the underlying price moves will not affect the options trade.

Gamma

Gamma (the second-order greek describing the rate of change of Delta as a function of the underlying moves) shows that we are moderately exposed to price changes in the underlying. It would benefit us to keep Gamma under control and as close to 0 as possible. 

Boxcar Gamma
Potential optimization

Having Gamma closer to zero would help our strategy to keep its delta close to the initiation range.

Theta

Theta describes the dollar amount we are receiving (or paying) on a daily basis to keep the structure open. Positive Theta means that we are getting paid by holding the position.

This is the core of every income trade.

In the case of Boxcar, we see that the majority of the time, we have positive Theta, but there are times when Theta turns negative. 

Boxcar Theta
Potential optimization

It is not beneficial to have negative Theta in an income trade. We should consider closing the trade as soon as it goes into negative Theta.

Vega

Vega represents how the option price changes as a function of the underlying volatility. Generally, income trades are negative vega (and positive theta), and that’s exactly what we see here. 

Boxcar Vega

Summary

success

We have taken Boxcar, an income trade that can be modeled in MesoSim using its powerful ScriptEngine. At the time of writing, other option-focused backtesters (from alpha to omega) are not flexible enough to model this trade.

We analyzed the trade using OptionNet Explorer, MesoSim’s Equity Graph, Portfolio metrics, and Greeks charts and identified optimization opportunities, which we will cover in the next episode of the series.

Due to the large drawdowns we do not recommend trading the Boxcar trade as described in this post.

In the follow-up post, we optimized the trade; please find the Boxcar-NG review here.

Theta Engine

· 2 min read
Screenshot-2022-10-03-at-8.53.36
success

We have been working closely with David Sun, the Host of the famous The Trade Busters Podcast (and notably a TastyTrade RisingStar), to bring his trade to MesoSim. 

So far, his unique approach of credit targeted dynamic sizing was impossible to model in the current backtesting offerings. With a tiny tweak in MesoSim’s ScriptEngine, we enabled David to bring his strategy to MesoSim.

David’s ThetaEngine is well described in his podcasts, and the trade details can also be studied via his Companion website.

You can find the backtest results of Theta Engine for 2021 here: https://portal.deltaray.io/backtests/d8e6c6e8-8654-4c8e-85b1-af0bf4e21b27

Please note that the above implementation is a limited version compared to what David has shared with us in Slack:

  • He is creating a series of backtests in his studies, each targeting a different day of the week for trading. With such an approach, he can blend all the results and better model his live trading approach.
  • We have limited our backtest period to 2021 for faster iteration. His shared backtests are running from 2014 - 2021.
  • We increased the expected annual target credit percent to 25% as the volatility was relatively low for the given period.
note

The target was increased for illustrative purposes only, and it might be unrealistic to expect all years to reach that level of return. Unless you understand the risk, we recommend you go with David’s suggested 10% (or lower) target.

To access his backtest results, please head to our Slack via this invite link.

Thanks David for collaborating with us and bringing your trade to our simulator.

What will happen next

We are going to add the hedging parts of the Trinity System (Bomb Shelter and Vibranium Shield) to MesoSim and share the results similarly.