19. 9. 2022

5 0

ストラテジー設定からストラテジーの初期化(Strategy Init)時にトリガーされたルール内で変数値を読み取る

In a rule triggered on Strategy Init, for each Assign function, StrategyQuant assign a “AssignVrbVleEntMlt” variable to your variable instead of a value.

Then, during initialization, it will give back the AssignVrbVleEntMlt value to your variable

From a strategy produced by the “H1388 Test Variable Template“, we can read in the code :

AssignVrbVleEntMlt = 210

AssignVrbVleEntMlt is receiving the value at the place MALength

それでは AssignVrbVleEntMlt give back the value to MALength at Inialization.

1/ This Custom Analysis Code example show you how to get a value of your variable in a rule triggered on strategy Init

We get the value from a function “toInitValue“, from a 結果グループ, 、および Rule name “Init“, and a variable name : MALength  (In this example)

Then we are using rg.specialValues() function to set the value in “CA_MALength”

 

package SQ.CustomAnalysis;

import com.strategyquant.lib.*;
import java.util.ArrayList;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;
import SQ.Utils.Bouillant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*; 

// Created in France by Emmanuel Bouillant-Evrard
public class CA_InitStratsSettings extends CustomAnalysisMethod 
{
    public static final Logger Log = LoggerFactory.getLogger(CA_InitStratsSettings.class);

    public CA_InitStratsSettings() 
    {
        super("CA MALength Settings", TYPE_FILTER_STRATEGY);
    }
    
    //------------------------------------------------------------------------
    
    @Override
    public boolean filterStrategy(String project, String task, String databankName, ResultsGroup rg) throws Exception 
    {
        try 
        {
            Bouillant BouilltParaObj1 = new Bouillant();
            
            String IntTemp = BouilltParaObj1.toInitValue(rg, false,"Init", "MALength", 100); 
            rg.specialValues().set("CA_MALength", Double.parseDouble(IntTemp));

            return true;
      	} catch(Exception e)
        {
            Log.error("Error CA_InitStratsSettings", e);
            return false;																																							       // "Error: " + e.getMessage();
        }
    }
    
    
    //------------------------------------------------------------------------
    
    @Override
    public ArrayList<ResultsGroup> processDatabank(String project, String task, String databankName, ArrayList<ResultsGroup> databankRG) throws Exception {
        return databankRG;
    }
}

 

2 / Then the DatabankColumn code retrieve the value of the Custom Analysis

We are using rg.specialValues to retrive the value from CA_MALength
package SQ.Columns.Databanks;
import com.strategyquant.lib.*;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// Created in France by Emmanuel Bouillant-Evrard 
public class StratSettingsMALength extends DatabankColumn 
{
  public static final Logger Log = LoggerFactory.getLogger(StratSettingsMALength.class);
  public StratSettingsMALength()
  {
    super("MALength Settings", DatabankColumn.Decimal2, ValueTypes.Maximize, 0, 0, 100); 
  }
  
  //------------------------------------------------------------------------
  /**
   * This method should return computed value of this new column. You should typically compute it from the list of orders 
   * or from some already computed statistical values (other databank columns). 
   */
  @Override
  public String getValue(ResultsGroup rg, String resultKey, byte direction, byte plType, byte sampleType) throws Exception 
  {   
    try 
    {
      double value = rg.specialValues().getDouble("CA_MALength", -1);

      if(value == -1) 
      {
        // this means value was not set
        return NOT_AVAILABLE;
      } else 
      {
        // return value converted to String
        return java.lang.Double.toString(value);
      }
    } catch(Exception e)
    {
      Log.error("Error StratSettingsMALength", e);
      return "";																																							       // "Error: " + e.getMessage();
    }
  }
}

 

3/ How to install it

  • Import the snippets in the コードエディタ
  • Compile All
  • Restart StrategyQuant 
  • それから select the Custom Analysis in the Builder :

 

 

それでは we add this new column to a Databank and read the value of our Init rules

If the Custom Analysis is not used anymore, the Column Databank must be removed to avoid any error in the log

私の名前はエマニュエル・ブイアルン=エヴァルドで、金融分野のエンジニアです。私は米国、カナダ、フランスで24年間、金融分野の研究開発に従事してきました。.

 

 

0 コメント
最古の
最新 最も投票された

関連記事