- ago
Is there a way to locate all strategies, including those inside Workspaces/Strategy Monitors, that are using a particular dataset for Portfolio Backtest?
Reason: If a dataset is renamed or deleted then a strategy using it will assign a default or even a "null" dataset which may not be desirable. Knowing beforehand which strategies may be impacted would be helpful.
0
442
Solved
20 Replies

Reply

Bookmark

Sort
Glitch8
 ( 14.34% )
- ago
#1
Yes, but not SM or Workspaces. Replace the "TQQQ AND SQQQ" with the UPPERCASE name of the DataSet you're interested in.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars)       {          foreach(Strategy s in StrategyFactory.Instance.Items)             if (!s.SingleSymbolMode)                if (s.DataSetName.ToUpper() == "TQQQ AND SQQQ")                   WriteToDebugLog(s.QualifiedName); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { } //declare private variables below } }
1
Best Answer
- ago
#2
Tested the code, here's what I found:
- seems to only work with built-in WealthData (WD) datasets; doesn't work with user-created WD datasets or with any non-WD dataset (either built-in or user-created, tested Norgate and ASCII)
- even when I assigned a built-in WD dataset ("DOW 30") to a number of new strategies... saved... closed and restarted WLab it often didn't pick up the new assignments, don't know what's going on... am I required to include certain Assembly References for this to work correctly?
0
Glitch8
 ( 14.34% )
- ago
#3
I don't know why it isn't working for you, it's working perfectly for me. Are you sure the Strategies you think it did not match are in portfolio backtest mode and not single symbol?

Here's my output showing it finding all my strategies set to portfolio backtest on my custom DataSet "TQQQ and SQQQ".

0
- ago
#4
I took a Sample Strategy "A Seventeen Liner", set it to use WD dataset "DAX" under Portfolio Backtest mode... saved... closed and restarted WLab to allow directories to be refreshed...opened your code, changed search to "DAX"...


Ran it... nothing found... there's not even a Debug tab


BTW, I see you're using B43, I'm using B42 (public latest) - don't know if that's got anything to do with this.
0
Glitch8
 ( 14.34% )
- ago
#5
I see the issue, in order to cope with different providers using the same name for DataSets, the DataSetName is qualified with the provider name, so use "DAX;WEALTHDATA" instead of just "DAX".
0
- ago
#6
Yup, appending the provider name to DAX correctly identified the strategy.... even though I don't have any other provider's dataset by the name "DAX" (there's a built-in Yahoo dataset bearing the name "Germany - DAX Index" which is not identical).

As if that wasn't strange enough, when I ran your code using "DOW 30" and then again using "DOW 30;WEALTHDATA" I got two completely different set of strategies listed in the debug window!!!

0
Glitch8
 ( 14.34% )
- ago
#7
Some of the strategies might have been saved and not changed since before we made the change to qualify the DataSetName. But since you can never delete DataSets from WealthData this should have no practical impact on the intended use of this script.
0
- ago
#8
Well, thanks for the code. On limited testing, it seems to work only with built-in WealthData datasets, and I guess one has to try with/without the provider name appended to see which one may work.
Perhaps some day it will work with *all* datasets, no matter the provider.
-----------------------------

More intriguingly, I see a glimmer of hope for a solution to vexing problem of identical named datasets from different providers not being visible that I reported over 2 months ago (https://www.wealth-lab.com/Discussion/DataSet-Providers-of-Norgate-and-WealthData-with-identical-names-not-visible-in-Strategy-Portfolio-Backtest-dropdown-9771)... will continue with that tomorrow.
0
Glitch8
 ( 14.34% )
- ago
#9
I’m not sure why it’s not working for you on all DataSets. As you can see in Post #3 it’s working fine at my end.
0
- ago
#10
I use special characters in nearly all of the datasets I create - to separate them from preprogrammed datasets and/or to have them line up in a specific order - as the following pic shows:


Characters I've used have included _, -, [], !, numerals, etc. Maybe that's why?? But I would have thought the input string in your code above would be taken in its entirety including any non-alphabet characters (and also assuming that dataset names are stored including all special characters which may even include leading spaces).
0
Glitch8
 ( 14.34% )
- ago
#11
Can you show an example of one of the failures?

You can also change the script to match on Strategy.Name instead of DataSetName, and then write the DataSetName to the debug log.

Finally, be sure your text matches the DataSetName exactly and then UPCASE it.
0
- ago
#12
Here's a failed example (note: After changing the dataset name I saved the strategy, closed and restarted WL to allow databases to refresh):


No debug tab:
0
Glitch8
 ( 14.34% )
- ago
#13
A linked DataSet will contain the provider name appended to the DataSetName after a semicolon.

So, Try "[2] NAZ100, DOW30;NORGATE DATA"

If you ever want to see the exact DataName for any Strategy you can change the script accordingly:

CODE:
      //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          foreach(Strategy s in StrategyFactory.Instance.Items)             if (!s.SingleSymbolMode)                if (s.Name.Contains("Seventeen"))                //if (s.DataSetName.ToUpper() == "DAX;WEALTHDATA")                   WriteToDebugLog(s.QualifiedName + ", " + s.DataSetName);       }

0
- ago
#14
QUOTE:
I use special characters in [my] datasets [names] ... I've ... included _, -, [], !, numerals,... Maybe that's why?

Why are you making this problem harder than necessary? I would recommend:

1) Renaming your datasets so that there's more consistent usage of the punctuation for matching purposes.

2) Use the String.Contains() method for your matching. See example:
CODE:
      public override void Initialize(BarHistory bars)       {          foreach(Strategy s in StrategyFactory.Instance.Items)             if (!s.SingleSymbolMode)                if (s.DataSetName.Contains("DAX",System.StringComparison.OrdinalIgnoreCase))                //if (s.DataSetName.ToUpper().Contains("DAX"))                   WriteToDebugLog(s.QualifiedName + ": " + s.DataSetName);       }
0
- ago
#15
@Glitch:
Appending ";NORGATE DATA" did the job! I thought since the dataset name is unique that alone would suffice... guess not.

@superticker:
I realize my naming is probably not "good practice" but it is what it is... renaming would not be an easy task especially when I don't know which strategies might be impacted... that's what this ticket is about.. I want to make changes but s-l-o-w-l-y so I don't get "unexpected" results.
BTW, this snippet
CODE:
if (s.DataSetName.Contains("[2] Naz100, Dow30", System.StringComparison.OrdinalIgnoreCase))   

works perfectly!

As a corollary its good to know that the dataset name is stored in its entirety including special characters.

Thank you, all !!
0
- ago
#16
[Tangential observation]
Looking at the Debug window output I see that strategies within the same folder are often separated by intervening other folders... perhaps this has to do with the age of the strategy (i.e. when they got entered into the database)... regardless, it would be nice to have a Sort function for the debug output so that items line up nicely.
0
- ago
#17
For sorting, simply define a collection of List<string> and then sort it. Below I'm selecting datasets for my "Voss Predictor" strategy and then sorting by the first character.
CODE:
using System.Collections.Generic; using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript2 {    public class MyStrategy : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {          List<string> debugOutput = new List<string>();          foreach (Strategy s in StrategyFactory.Instance.Items)          {             if (!s.SingleSymbolMode)                if (s.DataSetName.Contains("Voss", System.StringComparison.OrdinalIgnoreCase))                   debugOutput.Add(s.QualifiedName + ": " + s.DataSetName);          }          debugOutput.Sort();          WriteToDebugLog(debugOutput.ToStringNewLines());       }       public override void Execute(BarHistory bars, int idx) { }    } } ---Symbol by Symbol Debug Logs--- ---SPY--- My Strategies\Darvas Box: Voss Recovery,s My Strategies\Plot lowest RSI stocks2: Voss Recovery,s My Strategies\Voss Predictor RkThres PredictVel DSMA: Voss Recovery,s My Test Strategies\YCharts dividend test: Voss NetProfit,s
In practice, you'll want to pass a delegate procedure that will tell your .Sort(delegate) call what to sort by. See the Microsoft example at https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.sort?view=net-6.0
0
Glitch8
 ( 14.34% )
- ago
#18
This is the way, C# already contains a Sort.
1
- ago
#19
Neat code, superticker - thanks!

I'm aware of List.Sort as well as List.Reverse methods and use them in some of my strategies. I was actually thinking from a broader perspective such that whenever you want to sort something in the debug window you would just access it via, say, a right-click menu option and voila! job done... that way one doesn't have to program sorting inside each strategy.

Ciao!
0
- ago
#20
QUOTE:
I was actually thinking ... whenever you want to sort something in the debug window you would ... right-click menu option

Yes, but no one wants to sort all the lines in the Debug window, and it's unlikely they would want to sort by the first character in each line in the first place. That's why the .NET 6.X framework's String.Sort(delegate) allows you to pass in a delegate procedure.

You can copy the Debug window onto the Windows Clipboard, then use your Windows Clipboard Extender to sort it if you don't want to code it.
0

Reply

Bookmark

Sort