- ago
Hi,
I would like to realize a more sophisticated rotation strategy. According to your examples, one would do something like the following. I have tried it and it works if you have only one variable for making your selection.
Now, I would like to use more than variable to do that, like this:

CODE:
   public override void PreExecute(DateTime dt, List<BarHistory> participants)       {          int idx;          //store the symbols' AvgROC value in their BarHistory instances          foreach (BarHistory bh in participants)          {             TimeSeries symbolRoc = (TimeSeries)bh.Cache[seriesKey];             idx = GetCurrentIndex(bh); //this returns the index of the BarHistory for the bar currently being processed             double rocVal = symbolRoc[idx];             //if the indicator isn't valid set a very low value to avoid selection in rotation             if (idx < symbolRoc.FirstValidIndex)                rocVal = -01.0e6;             bh.UserData = rocVal; //save the current AvgROC value along with the BarHistory instance                          // CALCULATE SOME 2nd VARIABLE             bh.UserData_2 = ...          }          participants = participants.Where(x=>x.UserData_2AsDouble < 40)    // Use 2nd var                             .OrderByDescending(x=>x.UserDataAsDouble)   // Use 1st var                             .Take(noOfRotationAssets)                             .ToList();


How could I do that, please?
0
330
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
Your question isn't clear. Aren't we talking about using some linear combination to create a composite merit metric so we simply sort by that composite metric?
CODE:
compositeMeritMetric = wt1*var1 + wt2*var2 + wt3*var3;
If you're worried about the variance(var1) >> variance(var2 or 3) prior to taking the above inner product (and yes, that would be a concern ...), then I would normalize them (divide each var by their variances) so all their variances are the same before you take their inner product to compute the composite sort metric.

Now if you're thinking about using some nonlinear methodology (say weight the Rank(varX) of each variable like a robust statistician would do) to compute your composite sort metric, then that's way over my head. I would post your question to a statistics forum. The problem is the variances of each varX could be unstable, but addressing those stability issues is way beyond the scope of this forum.

I would keep it simple until something blows up.
0
Cone8
 ( 27.64% )
- ago
#2
QUOTE:
realize a more sophisticated rotation strategy
With what sophistication exactly?

You simply that need to assign a number to each participant/symbol.
If you don't want the symbol to be included, give it a very low number, otherwise a higher one. How you come up with the number is only limited by your imagination.
0
- ago
#3
@superticker, @cone
thx for the replies

Sorry, I thought my example would make it clear,

More sophistication just means using more than parameter to get my ranking. E.g. I would like to select every symbol with a RSI below x, and then, order this selection by the highest ROC of the individual symbols.

As far as I understand your template (which I already used a couple of times when only one parameter was sufficient), I can save the value of interest (e.g. RSI) in bh.userdata. My question is now, where could I save more than one value for each participant (e.g. the value of RSI and ROC). Hope that makes it clearer...

Thx for your help
0
- ago
#4
If you wish, the BarHistory.UserData can be used to hold entities more complex (objects) than double/int values. What if you wrap your set of values in a Tuple or other .NET collection and then unwrap and process?
1
Best Answer
- ago
#5
Hello Eugene,
as a matter of fact, I briefly thought about this, but was note sure how to access the wrapped object then...
But you are right, I just have to cast it, like this

CODE:
   participants = participants.Where(x=>((Asset) x.UserData).rsi < 40)                             .OrderByDescending(x=>((Asset) x.UserData).sma)                             .Take(noOfRotationAssets)                             .ToList();


Perfect! Manx thx
1
- ago
#6
You can declare Asset as either a class (has a constructor) or a struct (doesn't have a constructor) depending on how/when you want to fill it. Since Reply# 5 directly addresses its values as "public", I would use a struct; a class would not make them public, but would use "double Rsi {get; set;}" properties instead (which is contrary to my example below).
CODE:
   public class Asset    {       public double rsi;       public double roc;       public Asset(double rsi, double roc)       {          this.rsi = rsi; //copy temporary "stack" storage into "heap" storage          this.roc = roc;       }    }
Just be sure you initially call Asset with the "new" operator (for each instance) so you're allocated heap storage for your variables; otherwise, you'll just have pointers (references) without any heap storage. The rsi and roc can be stored by Value (as shown) in the heap.
0

Reply

Bookmark

Sort