如何计算 Deedle 中系列的累积乘积(或总和)(最好是在 C# 而不是 F# 中)?

How to compute cumulative product (or sum) of a Series in Deedle (ideally in c# rather than F#)?

如何在 Deedle 中计算系列的累积乘积(或总和)(最好是在 C# 而不是 F# 中)?窗口化/聚合有什么聪明的地方吗?

仅供参考,我想使用 deedle 编写与 python/pandas

中的这行代码等效的代码

curve['equity_curve'] = (1.0+curve['returns']).cumprod()

非常感谢

干杯, Lamp'

Deedle内置了累加函数(Stats.expandingSum),但没有扩展乘法。我认为最简单的选择是实现 Scan method for ordinary IEnumerable 然后按如下方式使用它:

 var result = input.Observations.Scan
   (KeyValue.Create(-1, 1.0), (acc, kvp) =>
      KeyValue.Create(kvp.Key, acc.Value * kvp.Value)).Skip(1).ToSeries();

为了完整起见,Scan 扩展方法看起来像这样:

public static IEnumerable<U> Scan<T, U>
    (this IEnumerable<T> input, U state, Func<U, T, U> next) {
  yield return state;
  foreach (var item in input) {
    state = next(state, item);
    yield return state;
  }
}