Hi Eugene!
I seem to be having a caching issue with the TASC Spearman indicator during an Optimization. My strategy has the following line
CODE:
Please log in to see this code.
The Value for SCPeriod can only be five different values (20, 40, 60, 80, & 100). The WL that I am using has several hundred symbols.
The optimization takes about 7 minutes per single evaluation with the calculation of DataSeries "sc" (since it is very computationally intensive) but only 18 seconds when I comment out this calculation.
Since the DataSeries "sc" can only have 5 possible values for the period, this DataSeries should be cached rather quickly, and computation times should speed up dramatically as the optimization run proceeds. But that is not happening.
I looked at the code for Spearman and it shows (to my VERY untrained eye) that it should be caching the DataSeries but it is obviously not doing so.
1) Is there any issue with the code for the calculation of the Spearman?
2) Is there any way that I can verify that the caching is actually taking place?
Thanks!
Vince
Size:
Color:
Hi Vince,
There are nested loops making the code computationally intensive. Spearman is free from caching issues. As you can see, code below instantiates 5 series and extracts them from Bars.Cache instead of plotting them directly:
CODE:
Please log in to see this code.
Size:
Color:
P.S. Comment out this line to see for yourself:
CODE:
Please log in to see this code.
Size:
Color:
Thanks Eugene for the quick reply. I see that what you coded shows that it is indeed being cached in that application.
Could it be that the caching in not occurring in the optimization? As you pointed out, the calculation of the Spearman series is extremely intensive. Therefore I would expect that the first calculation of it with a given period would take time, but any future need for the series would grab the cache near instantaneously. I am not seeing that. Is there any way for me to test if caching is indeed occuring in an optimization?
As a side note, I have always expected that each iteration of an optimization to progress faster than previous ones since more of the potential DataSeries would have been previously cached, obviating the need for their calculation. I have not observed that.
Vince
Size:
Color:
Hi Eugene!
Here is a script that demonstrates the issue.
CODE:
Please log in to see this code.
I am optimizing it using PSO with the Dow 30 as the WL, from 1/1/1995 to 6/1/2010.
When I time the calculations the results are attached.
The times are dominated by the calculation of the Spearman. If the cache was supplying the results after all the possible periods had been calculated the time for each instance would drop back to 3 seconds, but it doesn't.
Vince
Size:
Color:
Vince, I don't find any "issues" here. Each optimization run is a fresh new run. Simply put, Bars.Cache exists for that single run and then it's rebuilt. You're probably confusing it with some sort of global memory. The good news is that Wealth-Lab has it so you could put it to use to cache the DataSeries between runs if its calculation time is a concern. Check out SetGlobal and GetGlobal in the QuickRef. There are examples in forum posts, too.
Size:
Color:
Hi Eugene!
Do I understand correctly that WLP clears the cache memory after each run? If that is the case, then why does my memory usage balloon during an optimization run?
Vince
Size:
Color:
Garbage collection is controlled by .NET framework. It's a more intricate process than simply clearing after a run.
Size:
Color:
Hi Eugene!
I have read the info on Get/Set Global in the Help and the few items here on the forum. From what I see there does not appear to be a method to cache all of the computationally intensive DataSeries for all of the period values and all of the symbols of a WL in a portfolio simulation in a manner to allow their retrieval for subsequent use in an optimization run.
Am I missing something?
Furthermore, if it is indeed possible, if there are two scripts running there seems to be a need to prevent using the same Global series names for what could potentially be different computations. Is that correct?
Vince
Size:
Color:
Hi Vince,
When caching a series via SetGlobal, define a unique string which based on combination of Bars, .BarScale and .BarInterval, and Spearman's period. That's the point of using global memory across different tools in WLP.
Size:
Color:
Hi Eugene!
When you suggest "Bars" am I to assume that the Symbol name will be included?
Can you give me a few lines of code which I can use as the starting point for the Set and Get of these series? (Yes, I know, I need to learn how to program in C# much better! ;) )
Vince
Size:
Color:
QUOTE:
When you suggest "Bars" am I to assume that the Symbol name will be included?
Right, this is what I mean.
On second thought, just the Spearman period won't be enough because it doesn't reflect the symbol name. So your string has to include key parameters like the following:
1)
sc.Description [where sc. is the Spearman DataSeries - just the period won't be enough], and
2) three properties of the Bars object:
.Symbol,
.Scale and
.BarInterval.
How to dress that string is up to you, just be sure that it's correctly parsed by Strategies that retrieve using GetGlobal.
QUOTE:
Can you give me a few lines of code which I can use as the starting point for the Set and Get of these series?
For example, check out Cone's post #55 in this thread:
How to generate orders in real time during the trading day?
Size:
Color:
Hi Eugene!
Here is my (poor) attempt to do it. It does not Compile. All sorts of errors.
CODE:
Please log in to see this code.
What am I doing wrong?
Vince
Size:
Color:
Vince, here's a quick example:
CODE:
Please log in to see this code.
Size:
Color:
Thanks Eugene! That answers my question.
BTW, is there a way to access the "Data Range" for the Portfolio simulation so that I can include that in the identifier?
Vince
Size:
Color:
Fortunately for you, there is:
GetDataRange in C.Components. But I'm not sure why is it required?
Size:
Color:
Thanks Eugene!
QUOTE:
But I'm not sure why is it required?
I need to separate the Training Range (with the cached series for the Spearman) from the Testing Range (where the cached series would be incorrect).
Vince
Size:
Color: