#### Backtesting: System Results - How are values computed?

Posted By LeftEdge 2 Years Ago

## Backtesting: System Results - How are values computed?

 Message Posted Thursday February 05 2015 I'm familiarizing myself with RE's backtesting (simulation) features, and I wonder if someone can help me understand the "System Results"?First off, here's the "Position List" within the "System Results" tab:I'm looking first at the bottom pane of the above screenshot (let's call it the "detail pane"), where it breaks the position into the two trades that comprise it.  (The same info is also shown in the "Trade List" tab.)  Each trade is either a buy or a sell of a single contract of PA futures, with a commission of \$2.50 per side.  My PA futures symbol has the following settings:So, I understand where most of these values are coming from, but there are a few that I don't.  I exported the two trades in the detail pane to CSV and opened them in Excel:I see how the value in cell G2 is calcuated:  It debits my account capital by the Initial Margin plus the per-side commission, or  -(\$5000.00  + 2.50) = -\$5002.50.  I also see how the profit is computed (contract size * difference in buy and sell prices - round-turn commission).  These make sense.   My questions are:1) What does \$4779.33 in spreadsheet cell G3 represent?  What is the formula for computing it? 2) This simulation was based on 5 minute bars. Why do the fills show times that aren't a multiple of 5 minutes?A: I answered this one myself...  have a look at the bar data editor screenshot below.  There is very sparse data, so I assume RE uses the next available bar after the signal is triggered to generate the fill.3) This symbol has a minimum fluctuation (tick size) of 0.05.  Why are the fill prices not multiples of 0.05?  (Note that this is 1 contract, so there is not an average fill price at work here.)  I checked the bar data editor just to be sure, and all the prices there are divisible by 0.05:Thanks in advance for any help you can provide Posted Friday February 06 2015 1) This is supposed to basically be the entry cost plus the profit.  Based on that you would expect this value to be 4500.43.  I think what is happening here though is that since there were multiple positions open at once, the cost basis used for this is not based on just the entry and exit shown but also on the entries and exits that overlapped this position in time.  Does that make sense?2) Actually, this is because RightEdge breaks each bar into 4 ticks, so the high and low ticks will have timestamps 1/3rd and 2/3rds of the way through the bar.3) This is because these were limit and stop orders, which means that in most cases (ie if there's not a gap situation) that if the price crosses the limit or stop price, the fill price will be what the limit or stop price was.  You can use SystemUtils.RoundToNearestTick to make sure your PT/SL prices land on even tick values.Thanks,Daniel Posted Friday February 06 2015 Thanks Daniel for the quick reply Regarding #3: This makes sense.  In live trading, many brokers will reject resting orders with prices that are not an even multiple of the tick size, so this is something we should do anyway.  Regarding #2: I understand what you are doing.  Thanks.Regarding #1: This sounds like a plausible explanation...  but I have to admit it doesn't make me feel warm and fuzzy.  When doing backtests, I want to understand the assumptions being made, in great detail, so I can be sure I'm just slightly on the side of conservative.  (But not too conservative, because I don't want to throw out good systems due to overly harsh assumptions.)  So I like to be able to re-create every number that produces the equity curve, to be sure it's doing what I think it should.  The "Trade List" seems to be the tab that gets closest to showing the Equity Curve in tabular form, so I'd like to be able to use it to re-produce the EQ.  Would you happen to have any suggestions for how I can do that?  Any tips would be much appreciated... Posted Monday February 09 2015 You should be able to recreate the equity curve from the trade list (unless you are trading on symbols in a different currency than your account - then you have to take into account exchange rate changes).  The position list doesn't work for this directly because the broker doesn't know how different orders for the same symbol are grouped into positions.The RightEdge paper broker uses the weighted average of the entry price as the cost basis.  So if you bought 100 shares at \$100 and then 100 shares at \$110, the cost basis would be \$105.  If you sell shares the cost basis remains the same, but the size is reduced.  So if you sold 50 shares the cost basis of \$105 would be used to calculate the PnL for the trade, and you would be left with 150 shares with a cost basis of \$105.  If you bought another 100 shares at \$110, then the new cost basis would be ((150 * \$105) + (100 * \$110)) / (150 + 100) = \$107.Does this make sense?  How does your broker calculate the cost basis when you have different entries at different prices?Thanks,Daniel Posted Tuesday February 10 2015 To answer your question:Does this make sense?  How does your broker calculate the cost basis when you have different entries at different prices?Our broker can use multiple methods, depending on our instructions.  We typically use the "daily APS" system.  So we use an average price for all of the day's buy orders, and a second average price for all the day's sell orders.  This is part of the post-trade-allocation functionality that is available to CTA's in the futures markets.  I think I have enough info to use the RE Trade List to recreate the equity curve.  I can use the trade price on each row to update the value of  the current position, then compute the changes to cash from buying or selling.But it would be nice to also have a column in the Trade List called "Equity" that matches the values plotted in the "Equity Curve" plot. Posted Wednesday February 11 2015 The trade list has a column for the current account balance or buying power.Do you mean you'd like a number that matches the total "Account Value" in the equity curve, which includes the value of open positions?  That value changes based on the current price of all symbols that you have a position in.  It doesn't seem to me like having that value would help with calculations, because there's not enough other information to calculate it, and because it changes even when you don't make any trades.Thanks,Daniel Posted Wednesday February 11 2015 Yes, that's a good point.  In a single-symbol system with only short-term positions, the trades list can produce a decent approximation of the equity curve.  But if the system trades multiple symbols, and holds them long enough that their positions overlap in time, then synchronous price updates are required to compute a realistic eq curve.  So perhaps the Trades List is not the best place for this.What I'm really looking for is a convenient way to export an accurate equity curve into a portable format.  We've developed a homegrown tool for portfolio analytics, which imports equity curves from multiple systems generated by different backtesting platforms as input.  I'd like to run some RE systems through that process.  I imagine there are some classes in RE I can use to do this?  If you can point me in the right direction, maybe I can figure it out.  If I can save eq curve data to csv or similar, even in a simple format with DateTime in one column and Equity in the second column, that would be a good start.  Bonus points if I can also export a backtest's timeseries of position size per symbol and overall margin utilization.  (Being able to use an arbitrary sample interval would also be nice.) Does this sound doable? Posted Wednesday February 11 2015 The source code for the system results plugins is available here.So you can use that to see how the equity curve chart itself is calculated, and copy or adapt that logic.Thanks,Daniel Posted Wednesday February 11 2015 Thanks Daniel,There is a lot of code there...  and I see the part about needing licenses to libraries from third-party vendors (one of which is no longer issuing new licenses).  I quickly tried to open the .csproj file and got an error about "ImportCommon.targets".  So I wonder, does this sound like a very time-consuming task, since I won't be able to compile this code?  Or will it become apparent how I can do this once I've put in a couple of hours looking at the code?  Is this functionality somehow available via the ISystemResultPlugin, or some other way that does't require me to have these third-party licenses?In two of the other platforms we use, exporting an equity curve to CSV or Excel is a point and click operation, so I was hoping there might be an easy way to do this in RE too? Posted Wednesday February 11 2015 There's a bunch of code there, but it's for all of the different system results plugins that RightEdge has.  What you're interested is in EquityCurve.cs.  That has code to both calculate the equity curve and to display it on the chart.  You're just interested in the calculation code.  Start with the CalculatePointValues() method.For the equity curve, it looks like there's not much actual calculation that you need to do.  It's just pulling the AccountBalance, LongValue, and ShortValue out of the SystemStatistics series.Thanks,Daniel

## Reading This Topic

2005-2017 © RightEdge Systems