Lost in Translation of a Rotation Strategy
Author: Sammy_G
Creation Date: 8/12/2010 4:32 PM
profile picture

Sammy_G

#1
I am trying to translate a symbol rotation strategy from WL4 to WL5, and I am stuck. The general overview of the script is like this: In step 1, it loops through the watchlist symbols, and at each appropriate bar it collects a specific value (if the symbol was trading on that bar) and stores it in a date list (the bar is stored by its date).

Here's the relevant code in WL4 format:
CODE:
Please log in to see this code.



Here is where I am in WL5; I used existing rotation scripts as a base to build on:
CODE:
Please log in to see this code.


I am stuck where indicated. When I Compile, I get the following errors:
1. error CS1502...The best overload method match for 'System.Collections.Generic.List<WealthLab.Strategies.iHolder>.IndexOf(WealthLab.Strategies.iHolder)' has some invalid arguments [when I click this error, it highlights dateLst]
2. error CS1503...Argument "1": cannot convert from 'string' to 'WealthLab.Strategies.iHolder' {when I click on this it highlights dte].

In summary, I am stuck on the first line of this 3-line WL4 code:
CODE:
Please log in to see this code.

Can you help me with creating WL5 code for all 3 lines?
profile picture

Eugene

#2
The problem is that you're trying to search for a string in the list of iHolder objects.

You could use a delegate to search, for example:
CODE:
Please log in to see this code.
profile picture

Sammy_G

#3
Thanks, Eugene.
That takes care of the first line, but I am stuck at the next two. Can you help out?
profile picture

Eugene

#4
If we rewrite the iHolder class:
CODE:
Please log in to see this code.

Then your 2nd line becomes:
CODE:
Please log in to see this code.

(Though I'd suggest using type DateTime instead of string for 'dte'.)

No idea what RankLst is about; that's up to you.
profile picture

Sammy_G

#5
Thank you again for your patience and assistance.

This is complicated stuff but if I can get the 3rd line right I think I can translate the rest of the script. So I ask for your indulgence again:
In WL4, RankLst was a TList that was either just created at 'bar' (if j < 0), or the one that was already there (j >= 0). The purpose of the list is to store symbol names and Value, later used for sorting. Thus, there would be one RankLst for each bar.
In WL5 (not shown in the code above but its been created just below the dateLst) it is:
CODE:
Please log in to see this code.

So it would be the object that was either just created (j < 0) or existed at that bar (j >= 0). Looking at the code above, I guess it would be the iHolder.
But I am not getting the syntax right:
CODE:
Please log in to see this code.

or
CODE:
Please log in to see this code.

throw errors like 'WealthLab.Strategies.iHolder' is a type but is used like a variable.
(BTW, dte is not really needed inside rankLst)

It would be immensely helpful if I can get over this 1-line hurdle.
profile picture

Eugene

#6
I don't have the complete code so am coding on-the-fly, but most likely, you started getting these errors because the iHolder was modified by adding a constructor when fixing your 2nd line.

I believe that if you add another, parameterless constructor to the iHolder, they should be gone:
CODE:
Please log in to see this code.

...enabling you again to use:
CODE:
Please log in to see this code.
profile picture

Sammy_G

#7
No, I am getting even more errors when I use the parameterless iHolder. Don't know how to proceed forward.
I don't mind posting the code so far. What would you like me to do?
profile picture

Eugene

#8
Why were you using this?
CODE:
Please log in to see this code.

This is incorrect. You already created the rankLst, and then need to create as many iHolder objects as you need, set their properties, and add them to the rankLst.
profile picture

Sammy_G

#9
Because that was the 3rd step in 3-step process I used in WL4 [the object created at 'bar' (j < 0) or that exists b/c it was created by another symbol (j >=0) is a Tlist that will store (sym,Value) pairs for all symbols for that 'bar'). I was just trying to duplicate it step-by-step.

I guess you will be going offline soon. Can you suggest some *really* good sites for understanding Lists. I find msdn quite dense.
profile picture

Eugene

#10
If 'dte' isn't required inside 'rankLst', you may set up another class to hold the data.
CODE:
Please log in to see this code.
profile picture

Sammy_G

#11
I am not comprehending much of this, I am afraid.
I had thought converting 3 lines of WL4 code wouldn't be too difficult, but...

Part of the problem is that I don't understand too much about Lists as yet. But I still need to convert WL4 to WL5 equivalents; time is very short...

Can you suggest some *really* good sites for understanding Lists. msdn is 2 dense.
profile picture

Sammy_G

#12
Actually, I think the last line's equivalent ought to be the object at index j; thus:
CODE:
Please log in to see this code.

I don't get a compile error with this, but I need to check it out further.
But it seems logical; after all, that's what we were trying to get the value of 'j' for.
So it boils down to:
CODE:
Please log in to see this code.

If this seems balderdash to you, do comment...
profile picture

Eugene

#13
QUOTE:
But it seems logical; after all, that's what we were trying to get the value of 'j' for.

This is now starting to make sense; your earlier phrase was confusing: "Thus, there would be one RankLst for each bar." Actually, there would only be one rankLst which has an iHolder for each bar.
profile picture

Sammy_G

#14
[At the risk of exposing my ignorance of List<T> yet again, here goes...]

This is where the code stands currently:
CODE:
Please log in to see this code.


You will notice that for j < 0, I am now inserting an iHolder object ih2 that will hold (symbol, Value) pairs, like Tlists used to do in WL4.
But I have hit a mental block: I am unable to recall the syntax to use for populating the rankLst with the iHolder object (ih2, at index j) for each bar. Somehow, [[rankLst.Add(dateLst[j]);]] doesn't seem right.

If you are confused, just think about me!
profile picture

Eugene

#15
I don't see how is rankLst used. Describe your algorithm clearly, post the relevant V4 code. Sometimes it's easier to create an example from scratch.
profile picture

Sammy_G

#16
Here's the essence of the WL4 code. You can ignore the cosmetic stuff. I usually run it on weekly bars.
CODE:
Please log in to see this code.
profile picture

Eugene

#17
I don't find this design optimal. Instead of reinventing the wheel and translating this, it's better taking Robert's rotation strategy pattern (e.g. 'RSI rotation' or 'Weak stock rotation') and adding your overlay of data series etc. The pattern is simply more clear than creating a list for each date, then another one for ranking etc.

What about getting back to doing your preprocessing first (i.e. adding the reverse-adjusted series to a list of DataSeries) and then extracting them in the DataSetSymbols loop? This way, no need to recreate series in the bar loop. Example added:

Using custom series in a rotation Strategy
profile picture

Sammy_G

#18
I will study what you wrote. May take time to sink in.

I, however, find the pattern of my script OK - if for no other reason that I have used it that way for long and have grown comfortable with it (we are all creatures of habit, I guess). The main reason for porting stuff over to rankLst was that o/w the custom series (some not shown in code above) would be created again and again for each symbol for every bar, creating memory issues; also, it facilitated further processing of the rankLst from different perspectives.

[If you don't need the code below
// Step2. Trdaing rules

can you please delete it? Thanks]
profile picture

Eugene

#19
Trading rules code deleted.

I understand re: memory issues, that's why the example of creating the custom series and caching them in a List, and adding it on top of the strategy rotation pattern for accessing those series later on w/o creating an overhead.
profile picture

Sammy_G

#20
While I study what you wrote in the other thread (may take a loooooong time), can you explain why the iHolder class and its methods are placed at the bottom of the rotation scripts? Does it really matter whether they are near the top - as most classes are in most scripts - or near the bottom?
profile picture

Eugene

#21
Placement of a class matters when it becomes "nested" i.e. contained inside the body of another class. Otherwise it's not important. Try placing the iHolder class at the top - if moved correctly, it won't affect the result.
profile picture

Sammy_G

#22
I had already experimented with moving the class "upstairs" and found no change in results. So I was curious to know why its at the bottom. But thanks for the info.
*/

I forgot to mention above that the main reason why I used the DateLst the way I did in that script was that I could run the script by clicking *any* symbol in a watchlist w/o bothering to know which one had the longest history; the DateLst would get correctly populated with symbols & dates every time, independent of the clicked symbol. This was very convenient for me as I would often run the script against existing or randomly created watchlists.
I sacrificed some performance for the convenience.
profile picture

Eugene

#23
In the other thread, just left an example per Robert's suggestion re: formalizing an indicator. Hope this one is easier.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).