I am designing a simple internal framework for handling time series data. Given that LINQ is my current toy hammer, I want to hit everything with it.
I want to implement methods in class TimeSeries (Select(), Where() and so on) so that I can use LINQ syntax to handle time series data
Some things are straight forward, e.g. (from x in A select x+10), giving a new time series.
What is the best syntax design for combining two or more time series? (from a in A from b in B select a+b) is not great, since it expresses a nested loop. Maybe some join? This should correspond to join on the implicit time variable. (What I have in mind corresponds to the lisp ‘zip’ function)
EDIT: Some clarification is necessary.
A time series is a kind of function depending on time, e.g. stock quotes. A combination of time series could be the difference between two stock prices, as a function of time.
Stock1.MyJoin(Stock2, (a,b)=>a-b)
is possible, but can this be expressed neatly using some LINQ syntax? I am expecting to implement LINQ methods in class MyTimeSeries myself.
If I’m understanding the question correctly, you want to join multiple sequences based on their position within the sequence?
There isn’t anything in the
System.Linq.Enumerableclass to do this as both theJoinandGroupJoinmethods are based on join keys. However, by coincidence I wrote aPositionalJoinmethod for just this purpose a few days back, used as in your example:The semantics of the method shown below is that it does not require the sequences to be of equal length, but it would be trivial to modify it to require this. I also commented out where the argument checking should be as it was using our internal helper classes.
Not sure if this is exactly what you’re looking for, but hopefully of some help.