Extracting part of a DataSeries
Author: sedelstein
Creation Date: 12/16/2013 12:12 PM
profile picture

sedelstein

#1
This is likely more of a C# question than a WL question but I think they're related

If I have a DataSeries of length n say, and I want to extract some middle portion of it (say, from the 4th element to the n-5th element) and treat it as a new DataSeries is there a way to do it.

My readings of C# inform me there is an Array.Copy method. Is there anything similar for a DataSeries?

Thanks for the help.
profile picture

Eugene

#2
Why would one want to do it?
profile picture

sedelstein

#3
Why am I not surprised that you ask! ;->)

I am working with the EquityCurve. I have some methods which operate on it to give me some statistics I like.
These methods work on the entire series. I'd like to do some subsampling and rather than rewrite the methods to accommodate specific start and end dates, I thought I could "trick" the methods by passing along a reduced series.

Is that fair?

profile picture

Eugene

#4
Well, there probably is no native WealthScript analogue of Array.Copy but you can devise an own method that loops through the EquityCurve and extracts the dates in between specific start/end dates into a new blank DataSeries. Or you could "convert" the EquityCurve into a double array first and then apply Array.Copy to this array.
profile picture

sedelstein

#5
Ok, Food for thought.

Thanks Eugene
profile picture

sedelstein

#6



QUOTE:
Or you could "convert" the EquityCurve into a double array first and then apply Array.Copy to this array.




Hello Eugene

May I ask what you meant by "convert"? in the post above and how it could be accomplished?
I gather it is not simply a cast

So for example if I needed the Close DataSeries into a C# array of type double, can it be done without a for loop
Array.Copy can do the copy of only part of the array for me.

Thank you
profile picture

Cone

#7
Here's the function. Now you can do it without your own for loop.

CODE:
Please log in to see this code.
profile picture

sedelstein

#8
Thanks Cone

Of course this will work. I had thought from Eugene's post there was some way to do it without a for loop.
I guess there isn't. The "convert" in quotes led me to believe there was some "other" way.

Thanks again

p.s. woud you need Bars.Count to be replaced by ds.Bars.Count because conceivably you might be passing a DataSeries other than the current symbol? perhaps some external symbol (or a different time scale) that might not have the same number of bars as the current
profile picture

Cone

#9
You're right. I've replaced it with ds.Count.
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).