READ-ONLY

The forum is now a read-only archive.

For bug reports & platform questions → [email protected]

Our community lives on Discord and YouTube — come join us!

SQX Custom Project – Databank Filter

3 replies

Raul Franquet

Customer, bbp_participant, sq-ultimate, community, 15 replies.

Visit profile

1 year ago #288555

Good morning and happy new year.

Does anyone know how I can filter a Databank by a specific column in a custom project (not in a builder)?

Personally, I am interested in obtaining the 200 strategies with the highest Net profit after applying Monte Carlo and before applying Walk Forward Matrix within a Custom project.
When applying Monte Carlo, I cannot filter the maximum number of strategies in the Databank as I would do with the builder in the Ranking tab, and Filtering does not allow me to do so either.

Thank you very much

<!–a=1–>

0

Tomas Matejka

Administrator, sq-ultimate, 2 replies.

Visit profile

1 year ago #288614

Hi,

could be done using the Custom Analysis feature. You can check how it works here https://strategyquant.com/doc/programming-for-sq/example-per-databank-custom-analysis/

0

Raul Franquet

Customer, bbp_participant, sq-ultimate, community, 15 replies.

Visit profile

1 year ago #288638

Thanks Thomas

I don’t know how to create it, as I haven’t found any documentation about the Code Editor libraries, just some examples.
I can’t sort the ResultGroup by net profit

<!–a=1–>

0

Theo Gottwald

Subscriber, bbp_participant, customer, community, sq-ultimate, 60 replies.

Visit profile

1 year ago #288657

To filter a Databank by a specific column in a custom project (not in a builder) and obtain the 200 strategies with the highest Net Profit after applying Monte Carlo and before applying Walk Forward Matrix, you can modify the filterStrategy method in your custom analysis class. This method is called for each strategy in the Databank, and you can use it to filter strategies based on specific criteria.

Here’s how you can modify the filterStrategy method to achieve your goal:

  1. Filter by Net Profit: You need to access the Net Profit value for each strategy and filter based on that.
  2. Sort and Limit: After filtering, you can sort the strategies by Net Profit and limit the results to the top 200.

Below is an example of how you can modify the filterStrategy method to filter and sort strategies by Net Profit:

import com.strategyquant.lib.*;
import com.strategyquant.tradinglib.*;
import com.strategyquant.tradinglib.project.ProjectEngine;
import com.strategyquant.tradinglib.results.SpecialValues;
import com.strategyquant.tradinglib.results.stats.comparator.OrderComparatorByOpenTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class WFPortfolio extends CustomAnalysisMethod {
    private List<ResultsGroup> filteredStrategies = new ArrayList<>();
    public WFPortfolio() {
        super(“WFPortfolio”, TYPE_PROCESS_DATABANK);
    }
    @Override
    public boolean filterStrategy(String project, String task, String databankName, ResultsGroup rg) throws Exception {
        // Get the Net Profit value from the strategy’s results
        double netProfit = rg.getSpecialValues().getDouble(SpecialValues.NetProfit, 0);
        // Add the strategy to the filtered list if it meets your criteria
        // For example, you might want to filter strategies with a Net Profit greater than a certain value
        if (netProfit > 0) { // Adjust the condition as needed
            filteredStrategies.add(rg);
        }
        // Return true to include the strategy in the databank, or false to exclude it
        return true;
    }
    @Override
    public ArrayList<ResultsGroup> processDatabank(String project, String task, String databankName, ArrayList<ResultsGroup> databankRG) throws Exception {
        // Sort the filtered strategies by Net Profit in descending order
        filteredStrategies.sort((rg1, rg2) -> {
            double netProfit1 = rg1.getSpecialValues().getDouble(SpecialValues.NetProfit, 0);
            double netProfit2 = rg2.getSpecialValues().getDouble(SpecialValues.NetProfit, 0);
            return Double.compare(netProfit2, netProfit1); // Sort in descending order
        });
        // Limit the results to the top 200 strategies
        int limit = Math.min(200, filteredStrategies.size());
        List<ResultsGroup> topStrategies = filteredStrategies.subList(0, limit);
        // Create a new ResultsGroup for the top strategies
        ResultsGroup portfolioRG = new ResultsGroup(“Top 200 Strategies by Net Profit”);
        // Add the top strategies to the new ResultsGroup
        for (ResultsGroup strategyRG : topStrategies) {
            portfolioRG.addSubresult(strategyRG.getName(), strategyRG.getSettings(), strategyRG);
        }
        // Add the new ResultsGroup to the databank
        Databank databank = ProjectEngine.get(project).getDatabanks().get(databankName);
        databank.add(portfolioRG, true);
        return databankRG;
    }
    // Other methods remain unchanged…
}

<h3>Explanation:</h3>

  1. filterStrategy Method:
    • This method is called for each strategy in the Databank.
    • It checks the Net Profit value of each strategy and adds it to the filteredStrategies list if it meets the criteria (e.g., Net Profit > 0).
  2. processDatabank Method:
    • After filtering, the strategies are sorted by Net Profit in descending order.
    • The top 200 strategies are selected and added to a new ResultsGroup.
    • The new ResultsGroup is then added to the Databank.

<h3>Notes:</h3>

  • SpecialValues.NetProfit: This is a placeholder for the actual key used to access the Net Profit value in your ResultsGroup. You may need to adjust this based on the actual key used in your environment.
  • Condition: The condition if (netProfit > 0) is just an example. You can adjust this condition based on your specific filtering criteria.
  • Sorting: The strategies are sorted by Net Profit in descending order, so the highest Net Profit strategies come first.

This approach allows you to filter and sort strategies based on Net Profit and limit the results to the top 200 strategies, which can then be processed further as needed.

**Mit besten Grüßen | With best regards | Cordiali saluti**

**Theo Gottwald**
*Leading Expert in SPR & Visual Automation*

???? **What's New in the Q4 Update?**
1️⃣ Open AI Vision: Empower your SPR with cutting-edge visual recognition. See the unseen. ????????
2️⃣ Open AI TTS: Seamlessly transform text into natural, lifelike speech. Hear the difference. ????️????
3️⃣ GPT-4 with 128k Token Context Window by OpenAI: Dive into unparalleled depth in AI conversations. Think deeper. ????????
4️⃣ DALLE-3 by OpenAI: Command revolutionary AI to generate stunning images. Imagine more. ????️????
5️⃣ ElevenLabs Text to Speech: Experience text-to-speech so lifelike, it speaks to you. ????️
6️⃣ Stable Diffusion Local & Online via Automatic1111: Unlock creativity with both local and cloud-based image generation. Create anywhere. ☁️????
7️⃣ GPT4All & LM Studio: Harness powerful offline AI capabilities. Your studio, smarter. ????️????
8️⃣ DeepL Translator with SPR Integration: Achieve real-time, accurate translations. Speak the world's language. ????????
9️⃣ ChatGPT by OpenAI: Engage with your SPR through natural, dynamic conversations. Connect genuinely. ????️
???? WHISPER by OpenAI: Convert voice to text with effortless precision. Listen, transcribe, act. ????️????
???? Mistral AI: Scale your AI integration with seamless efficiency. Elevate your AI journey. ????????
???? Claude 3 by Anthropic: Experience next-level AI understanding and interactivity. Discover AI with a human touch. ????????

???? **Address:**
Herrenstr. 11, 76706 Dettenheim, Germany

???? **Phone:**
Office: +49 (7247) 9851112
Mobile: +49 160 6688 222
Fax: +49 (7247) 9851113

???? **Email:**
[[email protected]](mailto:[email protected])

???? **Websites:**
[IT-Berater](http://www.it-berater.org) | [Smart Package](http://www.smart-package.com)

0

Viewing 3 replies - 1 through 3 (of 3 total)