public static ITimeSeries <double> FirstDifference(this ITimeSeries <double> timeseries, ReturnMethod method = ReturnMethod.Geometric) { if (method == ReturnMethod.Arithmetic) { var res = from cur in timeseries.Skip(1) select new TSDataPoint <double>(cur.Date, cur.Value / timeseries[(from prev in timeseries where prev.Date < cur.Date select prev.Date).Max()] - 1); return(TimeSeriesFactory <double> .Create(res, timeseries.Name, timeseries.IntegrationOrder - 1, timeseries.Frequency)); } else { var res = from cur in timeseries.Skip(1) select new TSDataPoint <double>(cur.Date, Math.Log(cur.Value / timeseries[(from prev in timeseries where prev.Date < cur.Date select prev.Date).Max()])); return(TimeSeriesFactory <double> .Create(res, timeseries.Name, timeseries.IntegrationOrder - 1, timeseries.Frequency)); } }