TradersEdgeSystems.com

Consulting | Custom Trading Systems
Built-In Indicators | Custom Indicators

June 2013 Stocks and Commodities Traders Tips


Using Four Levels of Risk

AIQ Version:

Original article by Oscar G. Cagigas
AIQ Code by Richard Denning

For this month’s issue, I did not do the selected article on the wave count, but instead I provided code and a methodology to do the position sizing for the August 2012 article, “Using Four Levels Of Risk”, by Oscar G. Cagigas.

I was impressed by this new approach to positions sizing that is based on a “fixed” fraction but varies the fraction that is used in the sizing formula based on the most recent trade result. The approach is antimartingale and uses the standard deviation of the last four trades to determine whether to increase the fraction or to decrease it. His article is also interesting in that he applies the sizing to stocks and addresses the margin limitations that are encountered in the fixed fractional method when applied to stocks. To code the position sizing method, I created a simple trend following system with these rules:

  • Long only
  • Trend is up=close greater than a long term (200 bar) simple moving average and the short term (20 bar) moving average is higher today than it was 10 bars ago.
  • A dip in the price has occurred=three bar RSI is less than 10
  • Sell if the close drops below the long term moving average or
  • If the short term moving average is lower than it was 10 bars ago

I modified the risk levels to three due to issues with coding the author’s four-level approach. My formula uses 5% as the default but if the last trade’s number of standard deviations is negative by more than one standard deviation, then the sizing is moved to the minimum of 2.5%. If it is positive by more than one standard deviation, then the maximum sizing is used of 10%. When it is within +- one standard deviation then the 5% default is used. The position sizing formula also limits the size to the smaller of maximum leverage or the computed size using the fractional formula. The maximum leverage is one of the inputs that I set to 2 for a stock account to mirror the current margin requirements for stocks. The procedure to use the sizing code requires creating special data files that contain the percent return for each trade. To create the files requires the following steps:

  • For each stock or ETF that is to be traded, run a back-test of the system that will be sized
  • Export the detailed back-test results to a csv file
  • Edit the csv file so that it can be imported into the volume field using the DTU utility program to a new data file (only the “profit%” field is used)
  • The format must have all dates from the start of the back-test and have zeros between the trades with the percent return on the date the trade is closed. Add 100 to the returns to eliminate negative values then multiply by 100. Tell DTU that the volume data is in 100s (see Figure 1 for the csv import format)
  • Import this along with the price data into a new file with the return data in the volume field

I used the SPY in my example and the new file’s symbol is SPYTTF. In my example, I am assuming that I will only be trading the SPY with the account so I set the parameters for number of stocks to trade to 1. On the days when a buy signal is generated, the “Buy” tab on the EDS report will show the SPY with the sizing to use for the next day’s entry. In Figure 2, I show several signals from different dates. Note that the sizing cannot be back-tested with the AIQ software. My code only will provide the sizing for the next trade on a going forward basis.

To use this EDS for sizing more than one stock, save the EDS file under a different name so as to have two EDS files, then edit the inputs in both files. Repeat this for the number of stocks that will be traded for the system. Run all of these EDS files each night to generate signals and get the sizing for the next trade. Be sure to create the required data file for each stock that will be traded. After each new trade is closed, update the special data file that holds the profit% data. This can be done in the data manager by editing the data file directly and manually inputting the profit%+100 into the volume field.

Captions:

Figure 1 – Portion of csv import file after reformatting the trade return data from the back-test and adding it to the price data from the stock to be traded and sized. This file is imported to a new stock data file that has been added to the database using the Datamanager.

Figure 2 – Several Buy signals from different dates illustrating the sizing computation and the leverage limitation.

EDS Code:
TF Sys1.EDS
PositionsSPY.CSV
SPYTTF.dta
(right click and choose Save As)

 

Traders Studio Version :

Original article by Oscar G. Cagigas
Traders Studio Code by Richard Denning

For this month’s issue, I did not do the selected article on the wave count, but instead I provide code to do the position sizing for the August 2012 article, “Using Four Levels Of Risk”, by Oscar G. Cagigas.

The approach is antimartingale and uses the standard deviation of the last four trades to determine whether to increase the fraction or to decrease it. His article is also interesting in that he applies the sizing to stocks and addresses the margin limitations that are encountered in the fixed fractional method when applied to stocks. To code the position sizing method, I created a simple trend following system with these rules:

  • Long only
  • Trend is up=close greater than a long term (200 bar) simple moving average and the short term (20 bar) moving average is higher today than it was 10 bars ago.
  • A dip in the price has occurred=three bar RSI is less than 10
  • Sell if the close drops below the long term moving average or
  • If the short term moving average is lower than it was 10 bars ago

The following code files are contained in the download from the websites:

  • System: “FOUR_RISK_LVLS” a system that I devised to use for testing the position sizing described in the article
  • TradePlan: “FOUR_RISK_LVLS_SIZING” computes the size of each trade using the method of four risk levels
In Figure 1, I show the Equity curve and underwater equity curve with the position sizing varying the risk from 2.5% up to 20% on the NASDAQ 100 stocks. In Figure 2, I show the same system run on the same data over the same time period but with the risk fixed at 5% for all trades. Although the return is slightly less with the variable risk sizing, the underwater equity curve has a better shape and the profit factor is higher.

Captions:
Figure 1 – Equity and underwater equity for the system trading the NASDAQ 100 stocks from 1995 through 2012 when risk is varied in an antimartingale manor using the last four trades to set the size of the next trade.

Figure 2 – Equity and underwater equity for the system trading the NASDAQ 100 stocks from 1995 through 2012 when risk is held fixed at the initial level of 5% to size all of the trades.

Traders Studio Code:
FOUR_RISK_LVLS_TSZ.zip
(right click and choose Save As)

 

 

 

 

 

 

 

 

 

 

 

 

 

Disclaimer | Privacy Policy | Contact Us | Spam Blocker | ©2013 Traders Edge Systems