Documentation
Applications
Dernière mise à jour le 22. 12. 2021 par Mark Fric
Reconnaissance des résultats dans la matrice WF autour d'un champ personnalisé
La demande initiale :
Existe-t-il un moyen de choisir une cellule spécifique dans WFM pour laquelle un certain nombre de cellules environnantes doivent avoir Pass ?
Par exemple, je veux que la WFM soit réussie si 4 cellules entourant la cellule 10 Runs et 20%OOS ont un résultat positif. Je ne veux pas que SQX choisisse la meilleure cellule en fonction des résultats environnants, mais je veux définir quelle cellule doit être entourée de cellules réussies.
Oui, c'est possible, la façon la plus simple de le faire est d'utiliser l'extrait d'analyse personnalisé qui peut être lancé juste après l'optimisation.
Code commenté du snippet CustomAnalysis :
package SQ.CustomAnalysis ; import org.slf4j.Logger ; import org.slf4j.LoggerFactory ; import com.strategyquant.tradinglib.* ; import com.strategyquant.tradinglib.optimization.WalkForwardMatrixResult ; public class CAWFMCheck extends CustomAnalysisMethod { public static final Logger Log = LoggerFactory.getLogger("CAWFMCheck") ; //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ public CAWFMCheck() { super("CA WFM check", TYPE_FILTER_STRATEGY) ; } //------------------------------------------------------------------------ @Override public boolean filterStrategy(String project, String task, String databankName, ResultsGroup rg) throws Exception { // combien de voisins doivent passer pour que la matrice WF passe ? int neighboursToPass = 3 ; // trouver le résultat WF souhaité dans la stratégie ResultsGroup - dans notre cas 10 Runs et 20% OOS Résultat de la marche en avant wfResult ; try { wfResult = findWFResult(rg, 20, 10) ; // 10 Runs et 20%OOS catch(Exception e) { Log.info("WFResult introuvable : " + e.getMessage()) ; return true ; } // créer la matrice WFM en tant que tableau à deux dimensions WalkForwardMatrixResult wfm = (WalkForwardMatrixResult) rg.mainResult().get(SettingsKeys.WalkForwardResult) ; WalkForwardResult[][] wfMatrix = createMatrix(wfm) ; int matrixRows = wfMatrix.length ; int matrixColumns = wfMatrix[0].length ; // parcourons maintenant ce tableau bidimensionnel et recherchons les voisins du résultat WF que nous avons choisi for(int rowIndex=0 ; rowIndex<matrixRows ; rowIndex++) { for(int colIndex=0 ; colIndex<matrixColumns ; colIndex++) { if(wfMatrix[rowIndex][colIndex].param1 == wfResult.param1 && wfMatrix[rowIndex][colIndex].param2 == wfResult.param2) { //La position du résultat wf est trouvée dans la matrice, vérifier les voisins int neighboursPassed = 0 ; int neighboursChecked = 0 ; for(int neighbourRowIndex=rowIndex-1 ; neighbourRowIndex<=rowIndex+1 ; neighbourRowIndex++) { if(neighbourRowIndex=matrixRows) { continue ; } for(int neighbourColIndex=colIndex-1 ; neighbourColIndex<=colIndex+1 ; neighbourColIndex++) { if(neighbourColIndex=matrixColumns) { continuer ; } if(neighbourRowIndex==rowIndex && neighbourColIndex==colIndex) { continue ; } WalkForwardResult wfResultNeighbour = wfMatrix[neighbourRowIndex][neighbourColIndex] ; if(wfResultNeighbour.passed) { neighboursPassed++ ; } neighboursChecked++ ; } } Log.info(String.format("Neighbours checked %d / passed %d", neighboursChecked, neighboursPassed)) ; // a trouvé le résultat WF, a passé les voisins vérifiés. Comparer à la valeur seuil return neighboursPassed >= neighboursToPass ; } } } return false ; } //------------------------------------------------------------------------ private WalkForwardResult findWFResult(ResultsGroup rg, int param1, int param2) throws Exception { WalkForwardMatrixResult wfm = (WalkForwardMatrixResult) rg.mainResult().get(SettingsKeys.WalkForwardResult) ; if(wfm==null) { throw new Exception("WFMatrixResult not found.") ; } return wfm.getWFResult(param1, param2) ; } //------------------------------------------------------------------------ private WalkForwardResult[][] createMatrix(WalkForwardMatrixResult wfm) throws Exception { int rows = 0 ; int columns = 0 ; for(int j=wfm.start2 ; j<=wfm.stop2 ; j+=wfm.increment2) rows++ ; for(int i=wfm.start1 ; i<=wfm.stop1 ; i+=wfm.increment1) columns++ ; WalkForwardResult[][] wfMatrix = new WalkForwardResult[rows][columns] ; int param1Index = 0 ; int param2Index = 0 ; for(int j=wfm.start2 ; j<=wfm.stop2 ; j+=wfm.increment2) { for(int i=wfm.start1 ; i<=wfm.stop1 ; i+=wfm.increment1) { WalkForwardResult wfResult = wfm.getWFResult(i, j) ; wfMatrix[param2Index][param1Index] = wfResult ; param1Index++ ; } param2Index++ ; param1Index=0 ; } return wfMatrix ; } }
Cet article a-t-il été utile ? L'article était utile L'article n'était pas utile
excellent ! merci