Colonne de databank qui calcule le nombre de transactions sur l'ensemble des combinaisons de résultats de la Walk Forward Matrix, très pratique pour analyser la fréquence des transactions et la robustesse de la stratégie à travers les paramètres.
Remarque – il existe une version mise à jour pour SQX Build 140 et versions ultérieures – voir le snippet joint.
Ce snippet Java ajoute une nouvelle fonctionnalité de colonne de databank et vous permet de calculer le nombre de transactions de toutes les combinaisons d'une matrice WF.
/*
* Copyright (c) 2017-2018, StrategyQuant - All rights reserved.
*
* Code in this file was made in a good faith that it is correct and does what it should.
* If you found a bug in this code OR you have an improvement suggestion OR you want to include
* your own code snippet into our standard library please contact us at:
* https://roadmap.strategyquant.com
*
* This code can be used only within StrategyQuant products.
* Every owner of valid (free, trial or commercial) license of any StrategyQuant product
* is allowed to freely use, copy, modify or make derivative work of this code without limitations,
* to be used in all StrategyQuant products and share his/her modifications or derivative work
* with the StrategyQuant community.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package SQ.Columns.Databanks;
import com.strategyquant.lib.L;
import com.strategyquant.tradinglib.DatabankColumn;
import com.strategyquant.tradinglib.ResultsGroup;
import com.strategyquant.tradinglib.SettingsKeys;
import com.strategyquant.tradinglib.ValueTypes;
import com.strategyquant.tradinglib.WalkForwardResult;
import com.strategyquant.tradinglib.optimization.WalkForwardMatrixResult;
public class NumberOfTradeWF extends DatabankColumn {
public NumberOfTradeWF() {
super(L.tsq("# of trades WF"), DatabankColumn.Integer, ValueTypes.Aproximate, 0, 0, 100);
setWidth(70);
setTooltip(L.tsq("Number of trades WF"));
// this means that value depends on number of trading days
// and has to be normalized by days when comparing with another
// result with different number of trading days
setDependentOnTradingPeriod(true);
}
//------------------------------------------------------------------------
@Override
public String getValue(ResultsGroup results, String resultKey, byte direction, byte plType, byte sampleType) throws Exception {
/*
* Sample code to obtain the stat value of the WF result
* ----------------------------------------------------
* ----------------------------------------------------
* ----------------------------------------------------
*/
//Retrieve the WF matrix results
WalkForwardMatrixResult mwfResult = (WalkForwardMatrixResult) results.mainResult().get(SettingsKeys.WalkForwardResult);
if(mwfResult==null) {
return "NA";
}
/*
* WalkForwardMatrixResult opt params
* public int start1;
public int stop1;
public int increment1;
public int start2;
public int stop2;
public int increment2;
for(int j=mwfResult.start2; j<=mwfResult.stop2; j+=mwfResult.increment2) {
for(int i=mwfResult.start1; i<=mwfResult.stop1; i+=mwfResult.increment1) {
WalkForwardResult wfResult = mwfResult.getWFResult(i, j);
}
}
*/
int param1 = mwfResult.start1; //oos
int param2 = mwfResult.start2; //run
//Obtain a specific WF result from the matrix
WalkForwardResult wfResult = mwfResult.getWFResult(param1, param2);
/*
* WalkForwardResult calculated stats
* public SQStats stats = null; //Full Sample stats
* public SQStats statsOOS = null; //OOS stats
* public SQStats statsStability = null; //The stats stability
* public SQStats statsScore = null; //The stats score
* public SQStats statsSpecial = null; //The stats special
*/
//Return the calculated value of stats
return wfResult.stats.getInt("NumberOfTrades")+"";
}
}