Home > Technology > Strategy Example C

EXAMPLE C : Intraday Trading with Multi Leg Positions

With Time Series API (TSA), positions and trades can be composed of any number of 'legs', some of which increase the size of the position, whereas others decrease the size of the position. Trades are only considered 'closed out' when the position goes 'flat' or 'reverses'. Strategies are thus free to adjust position size to current market conditions, either via 'add on' orders, or 'partial exists'. Once the simulation has completed, the various available logs and report can then help analyze what exactly happened during the simulation. Trades, transactions, orders, drawdowns and bars can all be logged and reported independently. 

Such multi-leg trades can for example be used by a 'market making' strategy that continuously places both buy and sell limit orders throughout the trading session, and grows and decreases its 'inventory' as the market moves up and down. As long as a market is range bound such an approach can be very profitable, but as soon as the market pushes through major support or resistance, 'inventory' needs to be reduced quickly.

The following is a simple implementation of a market-making strategy trading the SP500 e-mini constract:

 

     Strategy s("intraday_demo");     //1

     s.SetPerSideCommission(2.0);     //2

     s.SetPerSideSlippage(12.5);      //3

 

     s.SetBigPointValue(50.0);        //5

     s.SetPyramidingEnabled(true);    //6

 

     Tuple data = IRecord(db, "sp500.U03.mini.cme.ohlcv.1000tick",

                                         PRICE_MASTER | TIME_MASTER );  //7

 

     Double position = Position();  //8

 

     LongVector positionChgCount(0); //10

     positionChgCount[0] = If(position != Prev(position), 0, positionChgCount[1] + 1); //11

     Bool barIntervalOk = positionChgCount > 10; //12

     Double lastTransactPrice = TransactPrice(data("close")); //13

           

     Double priceOffset = If( PositionSize() < 4, 1, PositionSize() / 2); //15

 

     double TICK_SIZE = 0.25; //17

     Double sellLimitPrice = MRound(lastTransactPrice + priceOffset, TICK_SIZE); //18

     Double buyLimitPrice  = MRound(lastTransactPrice - priceOffset, TICK_SIZE); //19

 

     Bool daySession = HHMM() >= 900 && HHMM() < 1550; //20

 

     LimitOrder(BUY, 1, barIntervalOk && daySession, buyLimitPrice, NEXT_BAR);    //21

     LimitOrder(SELL, 1, barIntervalOk && daySession, sellLimitPrice, NEXT_BAR);  //22

 

     s.Log( db, TRADES | DRAWDOWNS | TRANSACTIONS | BARS | ORDERS);  //23

 

     s.SetStart( DT( 2003, JUL, 8,   H9,  M30, 0) ); //24

     s.SetEnd(   DT( 2003, JUL, 18,  H16, M15, 0) ); //25

 

     s.Evaluate();   //26

     

     s.PrintEquityGraph( file );        //27

     s.PrintPerformanceReport( file );  //28

     s.PrintTradeReport( file );        //29

     s.PrintTransactionReport( file );  //30

     s.PrintOrderReport( file );        //31


The strategy continuously places limit orders, slightly above and below the current market price. Limit orders are placed by calling the LimitOrder() function in line //21 and //22.

     LimitOrder(BUY, 1,  barIntervalOk && daySession, buyLimitPrice, NEXT_BAR);    //21

     LimitOrder(SELL, 1, barIntervalOk && daySession, sellLimitPrice, NEXT_BAR);  //22

Each purchase or sale is for just 1 contract, the second argument. The third argument is the signal, which in this case checks that at least 10 bars have passed since last fill (more on this later), to avoid overtrading, and whether the time of day corresponds to the day session, and not overnight trading.

     Bool daySession = HHMM() >= 900 && HHMM() < 1550; //20

The fourth argument to the LimitOrder() function is the limit price. This involves a slightly longer calculation:

     Double lastTransactPrice = TransactPrice(data("close")); //13

     

     Double priceOffset = If( PositionSize() < 4, 1, PositionSize() / 2); //15

 

     double TICK_SIZE = 0.25; //17

     Double sellLimitPrice = MRound(lastTransactPrice + priceOffset, TICK_SIZE); //18

     Double buyLimitPrice  = MRound(lastTransactPrice - priceOffset, TICK_SIZE); //19

Line //13 fetches the price of the previous transaction. A default value is returned in case no transaction has yet taken place, in this case this default value is the current bar's closing price.

Line //15 calculates a price offset which determines how far the new limit orders will be placed from the previous transaction price. If the size of the current position is smaller than 4 contracts, then this offset is 1. I all other cases, the offset is set to half the position size, see line //15. This makes the strategy somewhat adaptive, as the larger the existing position the further away new orders are placed, to avoid growing the position too quickly.

Probably a better scheme to determine limit prices would have been to take into account whether a position is long or short so that new orders can be placed assymetrically. If the position is very long, short limit orders should be place more closely than long limit orders, and vice versa, to bias the strategy to reduce the size of its position!

The MRound() function in //18  and //19 is used round the limit prices to the nearest tick (muliple), which in the case of the SP500 e-mini is 0.25 points.

     s.Log( db, TRADES | DRAWDOWNS | TRANSACTIONS | BARS | ORDERS);  //23

 

     s.SetStart( 2003, JUL, 8,   H9,  M30 ); //24

     s.SetEnd(   2003, JUL, 18,  H16, M15 ); //25

 

     s.Evaluate();   //26

In //23 the strategy enables various logs that are necessary for printing reports after the simulation has been completed. The start and end datetimes are set via the strategy's SetStart() and SetEnd() members, since they also involve a time of day, and thus require more arguments. The JUL, H9 and M30 arguments are enumerations used for more easily differentiate the time arguments (plain numbers can also be used).

//26 then runs the simulations.

Sequences

Before analyzing the strategy's performance, a closer look at line //11 is helpful as it highlights another feature of vector types which is their ability to define 'sequences'.  A 'sequence' help maintain 'state' in formula code.

     LongVector positionChgCount(0); //10

     positionChgCount[0] = If(position != Prev(position), 0, positionChgCount[1] + 1); //11


Line //11 counts the number of bars since the last change in the position, and is self-referential in the sense that the same vector is used on both sides of the formula equation. However, upon closer inspection it is apparent that the left side of the equation uses the 'current value' of the vector (via operator[0]) and the right side uses the 'previous' value of the vector ( via operator[1] ). Since on the first strategy interval, there is not yet a 'previous' value, the vector needs to be 'seeded'. A seed value is given as argument to the constructor in //10, which in this case was 0. It is possible to pass up to three seed values, if the equations looks back more than one bar.

Strategy Performance

Performance over the 10 days from July 8 2003 to July 18 2003 was positive as can be seen on the end-of-day (EOD) equity graph.  The EOD equity graph is always available and does not require any logs to be enabled. It only shows the value of strategy equity at the end of each day however, and hence does not show intraday highs and lows. (A more precise equity graph could be drawn from the Bar Log which does however require bars to be logged during the simulation)

   _____________________________________________________________________

  | Net Equity Graph (EOD)                                              |

  |                                      *******                        | H: 6542.0

  |                                      *     *                        |

  |                               ********     *                        | 5013

  |                               *            *                        |

  |                               *            *                        | 4139

  |                               *            *                        |

  |                               *            *                        | 3266

  |                         *******            *           ************+|

  |                   *******                  *           *            | 2392

  |                   *                        *           *            |

  |                   *                        *******     *            | 1518

  |       *******     *                              *     *            |

  |       *     *     *                              *     *            | 645

  |       *     *     *                              *     *            |

  |********-----*-----*------------------------------*-----*------------| (0.0)

  |             *     *                              *     *            |

  |             *     *                              *     *            | -1103

  |             *     *                              *     *            |

  |             *******                              *******            | L: -1758.0

  |08-Jul-2003                                              18-Jul-2003 |

  |_____________________________________________________________________|

What is more interesting than the equity graph itself is to look at the composition of each trade, and the maximum exposure that the strategy had during this period, a topic to be covered when analyzing the performance report. It also helps to look at the price graph to understand the kind or market the strategy encountered during the given period.

 ______________________________________________________________________

| sp500.U03.mini.cme.ohlcv.1000tick [close]                            |

|                                ****                                  | H: 1014.8

|                                ****                                  |

|         *                     ** *** *                               | 1008

|       * **                   ***   ******                            |

|    * *****   *               **    ******    **                      | 1005

|   ** *****  **               *     *******   **                      |

| * ********* **               *     ********  ***                     | 1001

|*******   ******              *      ** * *** ***                     |

|****      **** *         * ** *      *     **** *                     | 998

|  *         *  *         ******            **** *                     |

|            *  **       *******            ***   *    *               | 994

|               ****     *** **                   *  * **              |

|               *****   ***  **                   *******            **| 990

|                 ***   **                        *********          *+|

|                  **  **                         *** *****      *   * | 987

|                   ** **                               *** *    ** ** |

|                   *****                               * ****   ***** | 983

|                    ***                                * ***** *****  |

|                     *                                      ********  | 979

|                                                            ****  *   |

|                                                              **      | L: 976.8

|8.Jul.2003-08:40:00:037                       18.Jul.2003-16:15:00:003|

|______________________________________________________________________|

 

Prices moved in a range between 1115 and 970. It should be noted that TSA, as a stand alone simulation engine does not feature charting/graphing functionality (functionality that is already available from numerous commercial vendors and open source projects), other than ascii based charts as pictured above, which are convenient because they do not need to be embedded in a file and can coexist with text. They can also be printed to terminal windows easily and only require a' fixed width' font to display properly. Any numeric column in a database table can be printed as a graph using class Database's PrintGraph() member! Data is aggregated into as many bars as can fit on the ascii graph itself, and so each visible bar does not correspond to a database record!

Performance Report

The following shows the strategy's Performance Report. The various values highlighted in color will be discussed in more detail below:

  _______________________________________________ 

 |                                               |

 |          Strategy Performance Report          |

 |_______________________________________________|

 

   Strategy Name:               'intraday_demo'

 

   Operational Bar:             8.Jul.2003-09:30:00:302

   Last Bar:                    18.Jul.2003-16:14:00:147

   Bars Processed:              2963

   Simulation Length (Years):   0.03

   Bars per Year:               108150

   Last Trade was Open:         true  {automatically closed out at-market}

 

   Risk Free Rate Of Return:    3.5

  __________________________________________________________________________________

 | SUMMARY                           |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Net Profit                        |  [ccy] |   3,231.00 |  1,202.00 |  2,029.00 |

 | Gross Profit                      |  [ccy] |   3,575.00 |  1,450.00 |  2,125.00 |

 | Total Costs                       |  [ccy] |     344.00 |    248.00 |     96.00 |

 |  * Commission                     |  [ccy] |     244.00 |    148.00 |     96.00 |

 |  * Slippage                       |  [ccy] |     100.00 |    100.00 |      0.00 |

 | Winners Net                       |  [ccy] |   5,662.00 |  3,633.00 |  2,029.00 |

 | Losers Net                        |  [ccy] |  -2,431.00 | -2,431.00 |      0.00 |

 | Profit Factor                     |  [rat] |       2.33 |      1.49 |      0.00 |

 |___________________________________|________|____________|___________|___________|

 | Largest Drawdown                  |  [ccy] | -11,476.50 |           |           |

 |___________________________________|________|____________|___________|___________|

 | Number Of Trades                  | [trad] |      15    |      7    |      8    |

 | Percent Winners                   |  [pct] |      93.33 |     85.71 |    100.00 |

 |___________________________________|________|____________|___________|___________|

 | Sum Bars - All Trades             | [bars] |   2,760    |  2,074    |    686    |

 | Perc. Bars with Position          |  [pct] |      93.15 |     70.00 |     23.15 |

 |                                   |        |            |           |           |

 |___________________________________|________|____________|___________|___________|

 | RISK / RETURN (ALL TRADES)        |        |  Account A | Account B | Account C |

 |___________________________________|________|____________|___________|___________|

 | Start Account Balance             |  [ccy] |  12,100.00 | 24,200.00 | 36,300.00 |

 | End  Account Balance              |  [ccy] |  15,331.00 | 27,431.00 | 39,531.00 |

 | Percent Return                    |  [pct] |      26.70 |     13.35 |      8.90 |

 | Annualized Rate Of Return (Comp.) |  [pct] | 567,740.37 |  9,625.67 |  2,151.98 |

 | Annualized Volatility (StDev)     |  [pct] |   8,161.05 |  4,228.72 |  2,862.28 |

 | Sharpe Ratio                      |  [rat] |      69.57 |      2.28 |      0.75 |

 |___________________________________|________|____________|___________|___________|

 | Max Account Balance               |  [ccy] |  19,767.00 | 31,867.00 | 43,967.00 |

 | Min Account Balance               |  [ccy] |   8,194.00 | 20,294.00 | 32,394.00 |

 |                                   |        |            |           |           |

 |___________________________________|________|____________|___________|___________|

 | TRADES                            |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Number Of Trades                  | [trad] |      15    |      7    |      8    |

 | Ave Net Profit                    |  [ccy] |     215.40 |    171.71 |    253.63 |

 | Ave Gross Profit                  |  [ccy] |     238.33 |    207.14 |    265.63 |

 | Ave Costs                         |  [ccy] |      22.93 |     35.43 |     12.00 |

 |  * Ave Slippage                   |  [ccy] |       6.67 |     14.29 |      0.00 |

 |  * Ave Commission                 |  [ccy] |      16.27 |     21.14 |     12.00 |

 | Ave Winner / Ave Loser            |  [rat] |       0.17 |      0.25 |      0.00 |

 | Ave Num Transactions              | [tran] |       7.67 |      9.57 |      6.00 |

 | Ave (Max) Position                | [unit] |       3.20 |      4.14 |      2.38 |

 | Ave Length                        | [bars] |     184.00 |    296.29 |     85.75 |

 | Ave Positive Excursion            |  [ccy] |     770.00 |  1,041.07 |    532.81 |

 | Ave Negative Excursion            |  [ccy] |  -1,215.00 | -2,217.86 |   -337.50 |

 |___________________________________|________|____________|___________|___________|

 | Max Positive Excursion            |  [ccy] |   4,225.00 |  4,225.00 |  1,525.00 |

 | Max Negative Excursion            |  [ccy] |  -9,437.50 | -9,437.50 | -1,050.00 |

 | Max Num Transactions              | [tran] |      26    |     26    |     16    |

 | Max Position Size                 | [unit] |      11.00 |     11.00 |      5.00 |

 | StDev Net Profit                  |  [ccy] |   1,055.05 |  1,503.43 |    325.94 |

 |                                   |        |            |           |           |

 |___________________________________|________|____________|___________|___________|

 | WINNERS vs LOSERS                 |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Number of Winners                 | [trad] |      14    |      6    |      8    |

 | Number of Losers                  | [trad] |       1    |      1    |      0    |

 | Average Winner                    |  [ccy] |     404.43 |    605.50 |    253.63 |

 | Average Loser                     |  [ccy] |  -2,431.00 | -2,431.00 |      0.00 |

 | Largest Winner                    |  [ccy] |   3,173.00 |  3,173.00 |    918.00 |

 | Largest Loser                     |  [ccy] |  -2,431.00 | -2,431.00 |      0.00 |

 | Max Consecutive Winners           | [trad] |      14    |      6    |      8    |

 | Max Consecutive Losers            | [trad] |       0    |      0    |      0    |

 | Ave Winner Length                 | [bars] |     111.21 |    145.17 |     85.75 |

 | Ave Loser Length                  | [bars] |   1,203.00 |  1,203.00 |      0.00 |

 |                                   |        |            |           |           |

 |___________________________________|________|____________|___________|___________|

 | UNITS                             |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Ave Net Profit                    |  [ccy] |    26.4836 |   16.2432 |   42.2708 |

 | Ave Gross Profit                  |  [ccy] |    29.3033 |   19.5946 |   44.2708 |

 | Ave Costs (Slipp. + Comm.)        |  [ccy] |     2.8197 |    3.3514 |    2.0000 |

 | Ave Slippage                      |  [ccy] |     0.8197 |    1.3514 |    0.0000 |

 |___________________________________|________|____________|___________|___________|

 | Num Units Traded                  | [unit] |     122.00 |     74.00 |     48.00 |

 |  * At-Market                      | [unit] |       8.00 |      8.00 |      0.00 |

 |  * On-Stop                        | [unit] |       0.00 |      0.00 |      0.00 |

 |  * At-Limit                       | [unit] |     114.00 |     66.00 |     48.00 |

 | Perc. Units w/o Slippage          |  [pct] |      93.44 |     89.19 |    100.00 |

 |                                   |        |            |           |           |

 |___________________________________|________|____________|___________|___________|

 | TRANSACTIONS                      |        |        ALL |           |           |

 |___________________________________|________|____________|___________|___________|

 | Number of Transactions            | [tran] |      115   |           |           |

 |  * At-Market                      | [tran] |        1   |           |           |

 |  * On-Stop                        | [tran] |        0   |           |           |

 |  * At-Limit                       | [tran] |      114   |           |           |

 | Average Size                      | [unit] |       1.06 |           |           |

 |                                   |        |            |           |           |

 |___________________________________|________|____________|___________|___________|

 | DRAWDOWNS                         |        |        ALL |           |           |

 |___________________________________|________|____________|___________|___________|

 | Largest Drawdown                  |  [ccy] | -11,476.50 |           |           |

 | Longest Drawdown                  | [bars] |     972    |           |           |

 | Number of Drawdowns               |  [ddn] |     111    |           |           |

 | Ave Length                        | [bars] |      28.22 |           |           |

 | Ave Drawdown                      |  [ccy] |    -420.40 |           |           |

 | Current Drawdown                  |  [ccy] | -11,476.50 |           |           |

 |___________________________________|________|____________|___________|___________|

 

A closer look at some of these numbers shows that the strategy made 3231 dollars net, after 244 dollars of commission and 100 dollars in slippage.

 | SUMMARY                           |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Net Profit                        |  [ccy] |   3,231.00 |  1,202.00 |  2,029.00 |

 | Gross Profit                      |  [ccy] |   3,575.00 |  1,450.00 |  2,125.00 |

 | Total Costs                       |  [ccy] |     344.00 |    248.00 |     96.00 |

 |  * Commission                     |  [ccy] |     244.00 |    148.00 |     96.00 |

 |  * Slippage                       |  [ccy] |     100.00 |    100.00 |      0.00 |

The reason why there was slippage at all, in light of the fact that the strategy only used limit orders, is because the strategy object automatically exits any position that is still open at the end of a simulation. It does so with a market order which causes the reported slippage.

 |___________________________________|________|____________|___________|___________|

 | TRANSACTIONS                      |        |        ALL |           |           |

 |___________________________________|________|____________|___________|___________|

 | Number of Transactions            | [tran] |      115   |           |           |

 |  * At-Market                      | [tran] |        1   |           |           |

 |  * On-Stop                        | [tran] |        0   |           |           |

 |  * At-Limit                       | [tran] |      114   |           |           |

This is why the section listing metrics by transaction shows 114 transactions with 'at-limit' orders, and a single transaction 'at-market'.

Recall that since TSA supports multi-leg trades, a transaction does not equal a trade. A trade can be composed of many transactions and is only considered closed out once the position goes flat or reverses. Multi leg trades are apparent in the following metrics:

 |___________________________________|________|____________|___________|___________|

 | TRADES                            |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Number Of Trades                  | [trad] |      15    |      7    |      8    |

 | Ave Net Profit                    |  [ccy] |     215.40 |    171.71 |    253.63 |

 | Ave Gross Profit                  |  [ccy] |     238.33 |    207.14 |    265.63 |

 | Ave Costs                         |  [ccy] |      22.93 |     35.43 |     12.00 |

 |  * Ave Slippage                   |  [ccy] |       6.67 |     14.29 |      0.00 |

 |  * Ave Commission                 |  [ccy] |      16.27 |     21.14 |     12.00 |

 | Ave Winner / Ave Loser            |  [rat] |       0.17 |      0.25 |      0.00 |

 | Ave Num Transactions              | [tran] |       7.67 |      9.57 |      6.00 |

 | Ave (Max) Position                | [unit] |       3.20 |      4.14 |      2.38 |

 | Ave Length                        | [bars] |     184.00 |    296.29 |     85.75 |

 | Ave Positive Excursion            |  [ccy] |     770.00 |  1,041.07 |    532.81 |

 | Ave Negative Excursion            |  [ccy] |  -1,215.00 | -2,217.86 |   -337.50 |

 |___________________________________|________|____________|___________|___________|

 | Max Positive Excursion            |  [ccy] |   4,225.00 |  4,225.00 |  1,525.00 |

 | Max Negative Excursion            |  [ccy] |  -9,437.50 | -9,437.50 | -1,050.00 |

 | Max Num Transactions              | [tran] |      26    |     26    |     16    |

 | Max Position Size                 | [unit] |      11.00 |     11.00 |      5.00 |

 | StDev Net Profit                  |  [ccy] |   1,055.05 |  1,503.43 |    325.94 |

 

There were only 15 trades, compared to 115 transactions, which gives us 7.67 transactions per trade. The 'Ave (Max) Position' field shows the average, over all trades, of the maximum position of each individual trade. This compares to a 'Max Position Size' of 11, which is the largest position attained by any one trade, an important measure of risk, since the largest position is sometimes much larger than the average position, and the associated risk can quickly get out of hand unless the model finds ways to reduce the position quickly.

The Trade Report provides a list of all trades:

  ________________________________ 

 |                                |

 |          Trade Report          |

 |________________________________|

 

   Strategy Name: 'intraday_demo'

   Table Name:    'INTRADAY_DEMO_TRADE_LOG'

   Number of Trades: 15

 

  ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

 | NUM| DIRECTION| MAX_POSITION| ENTRY_PRICE| EXIT_PRICE| PL_BEFORE_SC| PL_AFTER_SC| CUMM_PL_AFTER_SC| NUM_BARS| ENTRY_BAR_DATETIME       | ENTRY_INTERVAL| EXIT_BAR_DATETIME        | EXIT_INTERVAL| COMMISSION| SLIPPAGE| NUM_TRANSACTIONS| NUM_TRANSACT_WO_SLIPPAGE| EXIT_ORDER_REF_NUM| POS_EXCURSION| NEG_EXCURSION| IS_OPEN| TOTAL_NUM_UNITS| NUM_UNITS_WO_SLIPPAGE|

 |____|__________|_____________|____________|___________|_____________|____________|_________________|_________|__________________________|_______________|__________________________|______________|___________|_________|_________________|_________________________|___________________|______________|______________|________|________________|______________________|

 |   1|      LONG|        3.000|   1,002.000|  1,003.000|      150.000|     138.000|          138.000|       66| 08-Jul-2003  09:55:00:048|            NIL| 08-Jul-2003  10:43:00:046|           NIL|     12.000|    0.000|                6|                        6|                 70|       250.000|      -487.500|   false|           6.000|                 6.000|

 |   2|     SHORT|        1.000|   1,004.000|  1,003.000|       50.000|      46.000|          184.000|       12| 08-Jul-2003  10:57:00:107|            NIL| 08-Jul-2003  11:14:00:103|           NIL|      4.000|    0.000|                2|                        2|                 73|        62.500|       -37.500|   false|           2.000|                 2.000|

 |   3|     SHORT|        2.000|   1,004.000|  1,003.000|      100.000|      92.000|          276.000|       41| 08-Jul-2003  11:25:00:144|            NIL| 08-Jul-2003  12:50:00:057|           NIL|      8.000|    0.000|                4|                        4|                 91|       350.000|      -100.000|   false|           4.000|                 4.000|

 |   4|      LONG|        1.000|   1,002.000|  1,003.000|       50.000|      46.000|          322.000|       12| 08-Jul-2003  13:17:00:035|            NIL| 08-Jul-2003  13:58:00:034|           NIL|      4.000|    0.000|                2|                        2|                 96|       112.500|       -25.000|   false|           2.000|                 2.000|

 |   5|      LONG|        1.000|   1,002.000|  1,003.000|       50.000|      46.000|          368.000|       12| 08-Jul-2003  14:23:00:092|            NIL| 08-Jul-2003  14:50:00:013|           NIL|      4.000|    0.000|                2|                        2|                100|       112.500|       -12.500|   false|           2.000|                 2.000|

 |____|__________|_____________|____________|___________|_____________|____________|_________________|_________|__________________________|_______________|__________________________|______________|___________|_________|_________________|_________________________|___________________|______________|______________|________|________________|______________________|

 |   6|     SHORT|        5.000|   1,004.000|  1,001.500|      725.000|     697.000|        1,065.000|      203| 08-Jul-2003  15:09:00:061|            NIL| 09-Jul-2003  11:13:00:133|           NIL|     28.000|    0.000|               14|                       14|                175|       950.000|      -850.000|   false|          14.000|                14.000|

 |   7|     SHORT|        1.000|   1,002.500|  1,001.500|       50.000|      46.000|        1,111.000|       12| 09-Jul-2003  11:33:00:188|            NIL| 09-Jul-2003  11:58:00:088|           NIL|      4.000|    0.000|                2|                        2|                181|       125.000|       -25.000|   false|           2.000|                 2.000|

 |   8|      LONG|        2.000|   1,000.500|  1,001.500|      150.000|     138.000|        1,249.000|       61| 09-Jul-2003  12:05:00:074|            NIL| 09-Jul-2003  14:33:00:269|           NIL|     12.000|    0.000|                6|                        6|                196|       300.000|      -162.500|   false|           6.000|                 6.000|

 |   9|     SHORT|        3.000|   1,002.500|  1,001.500|      150.000|     138.000|        1,387.000|       91| 09-Jul-2003  14:52:00:135|            NIL| 10-Jul-2003  09:38:00:120|           NIL|     12.000|    0.000|                6|                        6|                207|     1,025.000|      -487.500|   false|           6.000|                 6.000|

 |  10|      LONG|        9.000|   1,000.500|  1,007.000|    3,225.000|   3,173.000|        4,560.000|      684| 10-Jul-2003  09:44:00:229|            NIL| 14-Jul-2003  10:12:00:008|           NIL|     52.000|    0.000|               26|                       26|                902|     4,225.000|    -5,275.000|   false|          26.000|                26.000|

 |____|__________|_____________|____________|___________|_____________|____________|_________________|_________|__________________________|_______________|__________________________|______________|___________|_________|_________________|_________________________|___________________|______________|______________|________|________________|______________________|

 |  11|     SHORT|        5.000|   1,008.000|  1,005.000|      950.000|     918.000|        5,478.000|      297| 14-Jul-2003  10:19:00:169|            NIL| 15-Jul-2003  09:54:00:125|           NIL|     32.000|    0.000|               16|                       16|               1097|     1,525.000|    -1,050.000|   false|          16.000|                16.000|

 |  12|     SHORT|        1.000|   1,006.000|  1,005.000|       50.000|      46.000|        5,524.000|       12| 15-Jul-2003  10:03:00:007|            NIL| 15-Jul-2003  10:09:00:117|           NIL|      4.000|    0.000|                2|                        2|               1101|       175.000|       -50.000|   false|           2.000|                 2.000|

 |  13|      LONG|        2.000|   1,004.000|  1,005.000|      100.000|      92.000|        5,616.000|       36| 15-Jul-2003  10:15:00:401|            NIL| 15-Jul-2003  10:40:00:101|           NIL|      8.000|    0.000|                4|                        4|               1110|       262.500|      -125.000|   false|           4.000|                 4.000|

 |  14|     SHORT|        1.000|   1,006.000|  1,005.000|       50.000|      46.000|        5,662.000|       18| 15-Jul-2003  10:50:00:053|            NIL| 15-Jul-2003  11:10:00:200|           NIL|      4.000|    0.000|                2|                        2|               1125|        50.000|      -100.000|   false|           2.000|                 2.000|

 |  15|      LONG|       11.000|   1,004.000|    990.500|   -2,275.000|  -2,431.000|        3,231.000|     1203| 15-Jul-2003  11:26:00:050|            NIL| 18-Jul-2003  16:14:00:147|           NIL|     56.000|  100.000|               21|                       20|                  0|     2,025.000|    -9,437.500|    true|          28.000|                20.000|

 |____|__________|_____________|____________|___________|_____________|____________|_________________|_________|__________________________|_______________|__________________________|______________|___________|_________|_________________|_________________________|___________________|______________|______________|________|________________|______________________|

 | NUM| DIRECTION| MAX_POSITION| ENTRY_PRICE| EXIT_PRICE| PL_BEFORE_SC| PL_AFTER_SC| CUMM_PL_AFTER_SC| NUM_BARS| ENTRY_BAR_DATETIME       | ENTRY_INTERVAL| EXIT_BAR_DATETIME        | EXIT_INTERVAL| COMMISSION| SLIPPAGE| NUM_TRANSACTIONS| NUM_TRANSACT_WO_SLIPPAGE| EXIT_ORDER_REF_NUM| POS_EXCURSION| NEG_EXCURSION| IS_OPEN| TOTAL_NUM_UNITS| NUM_UNITS_WO_SLIPPAGE|

 

The Trade Report provides numerous helpful statistics. The MAX_POSITION column shows that the largest position of 11 contracts was attained by trade #15. Recall that TSA supports 'fractional units' which is why the numbers in this column are floating point numbers. The precision of floating point numbers on reports can usually be controlled, and is 3 by default.

The TOTAL_NUM_UNITS column, which is the second to last column, shows the number of units traded, both long or short, before the trade was closed out! In this case, trade #15 shows 28 units traded.

Sometimes it is more helpful to look at 'per unit' profitability, especially with such a 'market making' approach, since costs are usually charged on a 'per unit' basis by the broker. Such 'Per Unit' metrics are also part of the Performance Report:

 | UNITS                             |        |        ALL |      LONG |     SHORT |

 |___________________________________|________|____________|___________|___________|

 | Ave Net Profit                    |  [ccy] |    26.4836 |   16.2432 |   42.2708 |

 | Ave Gross Profit                  |  [ccy] |    29.3033 |   19.5946 |   44.2708 |

 | Ave Costs (Slipp. + Comm.)        |  [ccy] |     2.8197 |    3.3514 |    2.0000 |

 | Ave Slippage                      |  [ccy] |     0.8197 |    1.3514 |    0.0000 |

 |___________________________________|________|____________|___________|___________|

 | Num Units Traded                  | [unit] |     122.00 |     74.00 |     48.00 |

 |  * At-Market                      | [unit] |       8.00 |      8.00 |      0.00 |

 |  * On-Stop                        | [unit] |       0.00 |      0.00 |      0.00 |

 |  * At-Limit                       | [unit] |     114.00 |     66.00 |     48.00 |

 | Perc. Units w/o Slippage          |  [pct] |      93.44 |     89.19 |    100.00 |

The average net gain, per contract (unit), was a gain of 26.48 dollars. This compares to a total cost of 2.81 dollars per contract, which is the sum of the 'per side commission' of 2.0 and slippage per contract of 81 cent. Recall that the slippage was caused by the strategy's automatic closing of the open position with a 'market order' at the end of the simulation, which, as can be seen in the 'at-market' line was an open position of 8 contracts. The percent of contracts traded withouth slippage was 93.4 percent.

Limit Order Properties

With this model, all limit orders were filled at the limit price. These fills are realistic because the strategy actually requires market prices to move beyond the limit price for a limit order to be considered filled! How far traded prices need to move beyond the limit price can be controlled via the strategy's SetLimitExecutionFactor() member.

TSA  also supports 'smart' limit orders, as controlled by the strategy's SetUsingSmartLimitOrders() member. Smart limit orders are useful when there is a time break between the close of one bar and the open of the next bar. For intraday strategies, this is not the case as trading is continuous, expecially in the more liquid markets. Smart limit orders are used by Example B.

Transaction Report

There exists no one to one correspondence between trades and transactions, and a trade can be composed of any number of legs / transactions, and a single transaction may simultaneously close one trade while opening a new trade. The transaction report, as shown below, can shed light on what actually happened during the simulation. The POSITION_DIR_POST column shows the direction of the strategy position after each transaction was completed. Note how the position can still be long after a transaction that effectively sold.

  ______________________________________ 

 |                                      |

 |          Transaction Report          |

 |______________________________________|

 

   Strategy Name: 'intraday_demo'

   Table Name:    'INTRADAY_DEMO_TRANSACTION_LOG'

   Number of Transactions: 115

 

  ______________________________________________________________________________________________________________________________________________________________________________________________

 | NUM| ORDER_REF_NUM| ORDER_USER_MSG| ORDER_TYPE| EXEC_DATETIME            | ORDER_DIR| SIZE | POSITION_DIR_POST| POSITION_SIZE_POST| PRICE    | SLIPPAGE| COMMISSION| EXEC_INTERVAL| EFFECT  |

 |____|______________|_______________|___________|__________________________|__________|______|__________________|___________________|__________|_________|___________|______________|_________|

 |   1|            47|               |      LIMIT| 08-Jul-2003  09:55:00:048|       BUY| 1.000|              LONG|              1.000| 1,002.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   2|            49|               |      LIMIT| 08-Jul-2003  10:01:00:302|       BUY| 1.000|              LONG|              2.000| 1,001.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   3|            51|               |      LIMIT| 08-Jul-2003  10:08:00:011|       BUY| 1.000|              LONG|              3.000| 1,000.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   4|            66|               |      LIMIT| 08-Jul-2003  10:23:00:327|      SELL| 1.000|              LONG|              2.000| 1,001.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   5|            68|               |      LIMIT| 08-Jul-2003  10:35:00:109|      SELL| 1.000|              LONG|              1.000| 1,002.000|    0.000|      2.000|           BAR| BUY_SELL|

 |____|______________|_______________|___________|__________________________|__________|______|__________________|___________________|__________|_________|___________|______________|_________|

 |   6|            70|               |      LIMIT| 08-Jul-2003  10:43:00:046|      SELL| 1.000|              FLAT|              0.000| 1,003.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   7|            72|               |      LIMIT| 08-Jul-2003  10:57:00:107|      SELL| 1.000|             SHORT|              1.000| 1,004.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   8|            73|               |      LIMIT| 08-Jul-2003  11:14:00:103|       BUY| 1.000|              FLAT|              0.000| 1,003.000|    0.000|      2.000|           BAR| BUY_SELL|

 |   9|            76|               |      LIMIT| 08-Jul-2003  11:25:00:144|      SELL| 1.000|             SHORT|              1.000| 1,004.000|    0.000|      2.000|           BAR| BUY_SELL|

 |  10|            88|               |      LIMIT| 08-Jul-2003  11:59:00:094|      SELL| 1.000|             SHORT|              2.000| 1,005.000|    0.000|      2.000|           BAR| BUY_SELL|

 |____|______________|_______________|___________|__________________________|__________|______|__________________|___________________|__________|_________|___________|______________|_________|

 |  11|            89|               |      LIMIT| 08-Jul-2003  12:16:00:084|       BUY| 1.000|             SHORT|              1.000| 1,004.000|    0.000|      2.000|           BAR| BUY_SELL|

 |  12|            91|               |      LIMIT| 08-Jul-2003  12:50:00:057|       BUY| 1.000|              FLAT|              0.000| 1,003.000|    0.000|      2.000|           BAR| BUY_SELL|

 |  13|            93|               |      LIMIT| 08-Jul-2003  13:17:00:035|       BUY| 1.000|              LONG|              1.000| 1,002.000|    0.000|      2.000|           BAR| BUY_SELL|

 

 


     Copyright (c) 2008 PERITECH. All Rights Reserved.