在F#和/或OCaml中表示时间序列的最标准和最有效的方法是什么

时间:2012-10-21 21:50:06

标签: f# ocaml time-series

我想知道在F#中表示时间序列的最标准和最有效的方法是什么,包括稀疏/非稀疏情况和常规间隔/非常规间隔情况。

是否有人有使用此语言或OCaml表示这些内容的标准方法的经验?

我首先通过数组表示它们,但意识到数组不能包含采样频率等信息。

2 个答案:

答案 0 :(得分:3)

这取决于您最有可能与这些时间序列一起使用的常见操作。

  • 如果您只进行顺序访问,那么将时间序列作为一系列时间值公开可能会很好。

喜欢这样

type TimedValue<'T> = { ts : DateTime; value: 'T}
type TimeSerie<'T> = TimedValue<'T> seq
  • 如果您打算进行一些精确搜索,可以使用Map
  • 进行包装

喜欢这样

type TimeSerie (vals : TimedValue<double> seq) = 
   let mdata = Map.ofSeq (vals |> Seq.map(fun x -> x.ts, x ))

   static member inline LinearReturn vb  ve = ve / vb - 1.
   static member inline LogReturn vb ve = log ve - log vb

   member x.toReturns(times : TimeCollection, f) =
         times |> Seq.pairwise |> Seq.map(fun (l,n) -> {tfrom = l; tto= n; value= f (mdata.[l].value) (mdata.[n].value) } )

   member x.toLinReturns(times : TimeCollection) = x.toReturns(times, TimeSerie.LinearReturn)
   member x.toLogReturns(times : TimeCollection) = x.toReturns(times, TimeSerie.LogReturn)

答案 1 :(得分:1)

也许功能反应式编程就是答案:它是一种范式,在这种范式中,您可以将事件绑定到函数并定义“行为”和始终发展的信号。

时间和事件以精心设计的方式呈现。

要启动的一些链接: http://erratique.ch/talks/react-ocamlum-2010.pdf http://erratique.ch/software/react

另一个lib:https://github.com/jaked/froc

相关问题