Trend-following strategy that dynamically adjusts for changing volatility

Let's use STDEV as a measure of volatility and adjust the trend-following strategy to adapt to changing market volatility. We will use an identical approach to the one we used when adjusting the mean reversion trading strategy for market volatility.

The main trading logic for the trend-following strategy adjusted for market volatility looks like the following. Let's start with the trading logic that controls sell trades first:

  # This section checks trading signal against trading parameters/thresholds and positions, to trade.
# We will perform a sell trade at close_price if the following conditions are met:
# 1. The APO trading signal value is below Sell-Entry threshold and the difference between last trade-price and current-price is different enough.
# 2. We are long( positive position ) and either APO trading signal value is at or below 0 or current position is profitable enough to lock profit.
if ((apo < APO_VALUE_FOR_SELL_ENTRY/stdev_factor and abs(close_price - last_sell_price) > MIN_PRICE_MOVE_FROM_LAST_TRADE*stdev_factor) # APO below sell entry threshold, we should sell
or
(position > 0 and (apo <= 0 or open_pnl > MIN_PROFIT_TO_CLOSE/stdev_factor))): # long from positive APO and APO has gone negative or position is profitable, sell to close position
orders.append(-1) # mark the sell trade
last_sell_price = close_price
position -= NUM_SHARES_PER_TRADE # reduce position by the size of this trade
sell_sum_price_qty += (close_price*NUM_SHARES_PER_TRADE) # update vwap sell-price
sell_sum_qty += NUM_SHARES_PER_TRADE
print( "Sell ", NUM_SHARES_PER_TRADE, " @ ", close_price, "Position: ", position )

Now, let's look at the trading logic code that handles buy trades:

  # We will perform a buy trade at close_price if the following conditions are met:
# 1. The APO trading signal value is above Buy-Entry threshold and the difference between last trade-price and current-price is different enough.
# 2. We are short( negative position ) and either APO trading signal value is at or above 0 or current position is profitable enough to lock profit.
elif ((apo > APO_VALUE_FOR_BUY_ENTRY/stdev_factor and abs(close_price - last_buy_price) > MIN_PRICE_MOVE_FROM_LAST_TRADE*stdev_factor) # APO above buy entry threshold, we should buy
or
(position < 0 and (apo >= 0 or open_pnl > MIN_PROFIT_TO_CLOSE/stdev_factor))): # short from negative APO and APO has gone positive or position is profitable, buy to close position
orders.append(+1) # mark the buy trade
last_buy_price = close_price
position += NUM_SHARES_PER_TRADE # increase position by the size of this trade
buy_sum_price_qty += (close_price*NUM_SHARES_PER_TRADE) # update the vwap buy-price
buy_sum_qty += NUM_SHARES_PER_TRADE
print( "Buy ", NUM_SHARES_PER_TRADE, " @ ", close_price, "Position: ", position )
else:
# No trade since none of the conditions were met to buy or sell
orders.append(0)

Finally, let's compare trend-following strategy performance with and without accounting for volatility changes:

So, for trend-following strategies, having dynamic trading thresholds degrades strategy performance. We can explore tweaking the application of the volatility measure to see whether there are variants that actually improve performance compared to static trend-following.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.113.188