I have been looking for Time Series models over in SO, but I figured this place was the best site to actually ask the question.

I am wondering what is the "best" way to handle Time Series in .Net.

First, I would define a Time Series as a mapping of different DateTime with a single value of type T.

The value can possibly be null.

Several methods should be available so that the series can be manipulated easily. For example, you want to be able to Filter the data (based on criteria on dates and/or on values). You would also like to have an Apply method, which applies a given function to all the values. Ideally, you would be willing to run some of these functions in parallel to increase performance.

Several data structures already implement such features, such as a Dictionary<DateTime,T>, possibly even a SortedDictionary<DateTime,T>. However, these are mutable structures, which can be an issue if there are some closure effects.

Which model would/did you use?

Do you know an existing library already widely used for this matter?


When I implemented a History<T> class (a sorted list of date values associated with some data of type T, allowing for old values to be dropped when new one's come in and a maximum size was reached etc.) I did it as a wrapper class around SortedDictionary<DateTime, T>.

Because this collection implements IEnumerable, you can use LINQ's extension methods to do the filtering, applying a function and so on. If you want to parallelize these operations, there is PLINQ.

If you worry about the structure being mutable, you will just have to make sure that all access to it is synchronized (e.g. via a lock in the wrapper class). If you add elements to the class only once, there shouldn't even be a need for such a lock, as the class "becomes immutable" if your wrapper does not allow it to be modified later on.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.