Documentation

Applications

Last updated on 12. 10. 2021 by Mark Fric

Working with ResultsGroup

ResultsGroup is the object that SQX uses to store:

  • strategy code/XML
  • backtest results
  • other results from optimizations and cross checks
  • settings used in the last backtests
  • other useful custom values in its key-value store

Each strategy you see in the databank is in fact a ResultsGroup object containing the strategy + results that are then displayed in the databank columns or in trades list, equity chart, etc.

 

Getting individual results from group

There can be multiple backtests or optimizations performed for one strategy – you can have main backtest + backtests on additional markets, or additional WF optimizations.

The results of these separate backtests are stored as separate Result objects in the ResultsGroup, so ResultsGroup object is in fact a group of Result objects plus few other things.

 

Individual results in the ResultsGroup are accessible by calling subResult(resultKey) method, where resultKey is the name (key) of the subresult you want to get.

You can get a list of all result keys by calling getResultKeys(), which will return an array of all the keys the ResultGroup contains.

You can also use a special method getMainResultKey() to get key of the main backtest result.

Result mainResult = resultsGroup.subResult( resultsGroup.getMainResultKey() ) // will return the main backtest result.

 

ResultsGroup object name is the strategy name you see in databank, so calling resultsGroup.getName() will return “Strategy 1.2.3” for example

 

Portfolio

There is also a special portfolio result that is added automatically if ResultsGroup contains more than one result. You can get portfolio result by simply calling ResultsGroup.portfolio()

Result portfolioResult = resultsGroup.portfolio().

If there is just one result this call will return the main backtest result.

 

Getting metrics from a Result

When you have a Result you can easily get the metrics such as Net profit, SharpeRatio etc. that were computed for this result.

All computed metrics are stored in SQStats object that you can get by calling Result.stats(Direction, PLType, SampelType). Note that the stats() method has three parameters – the stats are computed separately for:

 

SQStats statsIS = result.stats(Directions.Both, PlTypes.Money, SampleTypes.InSample);

SQStats statsOOS = result.stats(Directions.Both, PlTypes.Money, SampleTypes.OutOfSample);

SQStats statsLong = result.stats(Directions.Long, PlTypes.Money, SampleTypes.FullSample);

 

The SQStats object is a simple key-value map that contains the computed metrics for the given stats combination. The metrics are stored under the keys that correspond to the class names of Java snippets, for example “NetProfit”, “Drawdown”, etc.

Once you have SQStats object you can get the value of the metric by simply calling:

double netProfit = stats.getDouble("NetProfit");

int noOfTradest = stats.getInt("NumberOfTrades");

 

Was this article helpful? The article was useful The article was not useful

Subscribe
Notify of
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Oliver
17. 11. 2021 8:29 pm

Hi before I study this in detail….. does this allow me to select specific walk forward runs to build an optimized portfolio? I had posted a request below so that the trades from a specific run can be used in quant analyzer. Does this do the same? thanks

https://roadmap.strategyquant.com/tasks/sq4_8403

Emmanuel
25. 11. 2021 8:43 pm

This is very helpful, I am testing it. Thank you Mark

Emmanuel
26. 11. 2021 1:18 pm

where can I find example of Result objects ? 
, subResult(resultKey) method ?, 
getResultKeys(), getMainResultKey()
SQStats statsIS = result.stats(Directions.Both, PLTypes.Money, SampleTypes.InSample);

I search in the code editor with getResultKey, and other key word but I didn’t find any example.

tomas262
Admin
Reply to  Emmanuel
1. 12. 2021 7:51 pm
Emmanuel
Reply to  tomas262
4. 1. 2022 1:52 pm

thank you