kazuna8
 ( 44.16% )
- ago
In WL6.9, you can obtain the list of symbols from DataSetSymbols while only one selected symbol being processed.

In WL7, the equivalent is BacktestData but it is for Portfolio backtest mode.

Is there a way to obtain the list of symbols in the DataSet exactly the same way as WL6.9 described as folows?
QUOTE:
Returns a list of strings that contain the symbols in the DataSet that contains the symbol currently being processed by the Strategy.

0
695
Solved
8 Replies

Reply

Bookmark

Sort
- ago
#1
You can use FindDataSet:
https://www.wealth-lab.com/Support/ApiReference/IHost

And then query its SymbolString:
https://www.wealth-lab.com/Support/ApiReference/DataSet
1
Best Answer
- ago
#2
I didn't realize .../ApiReference/DataSet even existed. It's not listed in the API Reference table at the left.
0
Glitch8
 ( 9.89% )
- ago
#3
We don’t list every class, only the most important.
1
- ago
#4
I'm suffering a mental block here. Please tell me why this code fails.

CODE:
DataSet mutualFunds = new DataSet(); //input mutual fund dataset foreach(string symbol in mutualFunds.Symbols) {    WriteToDebugLog(symbol); }
It appears to me mutualFunds.Symbols is empty. Perhaps the DataSet has to be made an instance in the MyStrategy constructor instead of the field variable area?

Why does the expression below always return zero in Intialize()?
CODE:
WriteToDebugLog(mutualFunds.Symbols.Count);
And how do I get the number of symbols in a DataSet?
0
- ago
#5
QUOTE:
It appears to me mutualFunds.Symbols is empty.

Exactly. It is empty because you only initialized this instance. Therefore it will be empty unless you assign something to its properties like Symbols.
0
- ago
#6
So how do I get a list of symbols in the current dataset?

It appears this discussion never answered that question. Or if it did, I can't figure it out. Give me a code example getting the symbols.
0
Glitch8
 ( 9.89% )
- ago
#7
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Data; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) {          //Method One          DataSet ds = DataSetFactory.FindDataSet(ExecutionDataSetName);          if (ds != null)             DrawHeaderText(ds.Symbols.ToStringDelimited(','), Color.Black, 12);          //Method Two     //Returns only the symbols that were in the backtest range     //Dynamic DataSets such as WealthData may exclude many symbols, so strings 1 and 2 might have different results          List<string> symbols = new List<string>();          foreach(BarHistory bh in BacktestData)             symbols.Add(bh.Symbol);     DrawHeaderText(symbols.ToStringDelimited(','), Color.Black, 12); } //Execute public override void Execute(BarHistory bars, int idx) { } } }
2
- ago
#8
Thanks. Method 1 is good enough for me. I want to do an Array.Sort() in PreExecute because it's a more compact (i.e. smaller footprint) sorting approach. Yes, I realize that goes outside the normal WL framework. But for what I'm doing, it's the fastest way.
CODE:
namespace WealthScript1 { public class SelectSectRank : UserStrategyBase {       TextInfo textInfo = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo;       readonly Color[] plotColor = {Color.Blue, Color.LimeGreen, Color.Magenta, Color.DeepSkyBlue,          Color.Black, Color.DarkCyan, Color.DarkOrchid, Color.Coral, Color.Brown};              string[] fundSymbols; //mutual fund symbols       double[] dipBuyMeritScore;       int dipBuyMeritScoreIdxPtr = 0; //input pointer into the next available location       public SelectSectRank()       {          AddParameter("Null pt position", ParameterTypes.Int32, 22, 3, 40, 1);          AddParameter("Gain vs dip effect", ParameterTypes.Double, 1.0, 0.8, 1.8, 0.1);          AddParameter("Recent influence", ParameterTypes.Double, 0.0, 0.0, 0.9, 0.1);          AddParameter("Plot# w/poly fit", ParameterTypes.Int32, 1, 1, 9, 1);       }       public override void Initialize(BarHistory mutFundBars) {          int nullBar = Parameters[0].AsInt; //paramNullBar          double gainVsDip = Parameters[1].AsDouble; //paramGainVsDip          double rcntPerfBoost = Parameters[2].AsDouble; //paramRcntPerfBoost          int plot2highlight = Parameters[3].AsInt; //paramPlot2Highlight          if (fundSymbols == null)          {             fundSymbols = WealthLab.Data.DataSetFactory.FindDataSet(ExecutionDataSetName).Symbols.ToArray(); //input mutual fund dataset             dipBuyMeritScore = new double[fundSymbols.Length];          } ... }       public override void PreExecute(DateTime dt, List<BarHistory> participants)       {          Array.Sort(dipBuyMeritScore,fundSymbols);       }
This strategy doesn't trade, so the Execute block is not used. At some point it might become a rotational strategy, but that's another problem.
0

Reply

Bookmark

Sort