我想知道在F#中表示时间序列的最标准和最有效的方法是什么,包括稀疏/非稀疏情况和常规间隔/非常规间隔情况。
是否有人有使用此语言或OCaml表示这些内容的标准方法的经验?
我首先通过数组表示它们,但意识到数组不能包含采样频率等信息。
答案 0 :(得分:3)
这取决于您最有可能与这些时间序列一起使用的常见操作。
喜欢这样
type TimedValue<'T> = { ts : DateTime; value: 'T}
type TimeSerie<'T> = TimedValue<'T> seq
喜欢这样
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