public static Stat2 <TKey> Stat2 <TKey, TValue, TCursor>( this Series <TKey, TValue, TCursor> series) where TCursor : ICursor <TKey, TValue, TCursor> { var stat = new Stat2 <TKey>(); using (var cursor = series.GetEnumerator()) { var first = true; while (cursor.MoveNext()) { if (first) { stat._start = cursor.CurrentKey; first = false; } stat.AddValue(DoubleUtil.GetDouble(cursor.CurrentValue)); } stat._end = cursor.CurrentKey; stat._endValue = DoubleUtil.GetDouble(cursor.CurrentValue); } return(stat); }
public void OnlineVarianceIsStable() { var count = 300000; // fails with 400k, small values become not equal var stat = new Stat2 <int>(); var forward = new double[count + 1]; var backward = new double[count + 1]; for (int i = 1; i <= count; i++) { stat.AddValue(i); if (i > 1) { forward[i] = stat.StDev; //Console.WriteLine($"{i} - {stat.StDev}"); } } for (int i = count; i >= 1; i--) { if (i > 1) { backward[i] = stat.StDev; //Console.WriteLine($"{i} - {stat.StDev}"); } stat.RemoveValue(i); } for (int i = 1; i <= count; i++) { if (i > 1) { Assert.AreEqual(forward[i], backward[i]); if (i < 20 || i > count - 20) { // matches to Excel VAR.S/ STDEV.S Console.WriteLine($"{i} - {forward[i]} - {backward[i]}"); } } } var statDt = new Stat2 <DateTime>(); statDt.AnnualizedVolatility(); }
public static Stat2 <TKey> Stat2 <TKey, TValue>(this ISeries <TKey, TValue> series) { var stat = new Stat2 <TKey>(); using (var cursor = series.GetSpecializedCursor()) { var first = true; while (cursor.MoveNext()) { if (first) { stat._start = cursor.CurrentKey; first = false; } stat.AddValue(DoubleUtil.GetDouble(cursor.CurrentValue)); } stat._end = cursor.CurrentKey; stat._endValue = DoubleUtil.GetDouble(cursor.CurrentValue); } return(stat); }
public void AddNewRight(KeyValuePair <TKey, TValue> newRight) { var x = DoubleUtil.GetDouble(newRight.Value); _state.AddValue(x); }