private static List <InstrumentValuePair> ExpandValues(List <InstrumentValuePair> values) { List <InstrumentValuePair> ret = new List <InstrumentValuePair>(); InstrumentValuePair Prev = null; foreach (var itr in values) { if (Prev == null) { Prev = itr; continue; } //calculate the average value between the 2 points Debug.Assert(Prev.Stamp < itr.Stamp); // values are in theory ordered by increasing timestamps long TimeDiff = itr.Stamp - Prev.Stamp; double DiffValue = Prev.SellValue - itr.SellValue; double ValueIncrease = DiffValue / TimeDiff; for (int i = 0; i < TimeDiff; i++) { ret.Add(new InstrumentValuePair(Prev.Stamp + i, Prev.SellValue + i * ValueIncrease)); } Prev = itr; } return(ret); }
public static double GetInstrumentAveragePricePeriod(string InstrumentName, long StartStamp, long EndStamp) { List <InstrumentValuePair> values = Globals.Persistency.GetInstrumentValues(InstrumentName, StartStamp, EndStamp); double ValueSum = 0; double ValueCount = 0; InstrumentValuePair Prev = null; foreach (var itr in values) { if (Prev == null) { Prev = itr; continue; } //calculate the average value between the 2 points Debug.Assert(Prev.Stamp < itr.Stamp); // values are in theory ordered by increasing timestamps long TimeDiff = itr.Stamp - Prev.Stamp; double AvgValue = (itr.SellValue + Prev.SellValue) / 2; Debug.Assert(AvgValue < itr.SellValue * 1.10); // no more than 10% change is expected ? Debug.Assert(AvgValue > itr.SellValue * 0.90); // no more than 10% change is expected ? //we estimate 1 value for every second ValueSum += AvgValue * TimeDiff; ValueCount += TimeDiff; Prev = itr; } return(ValueSum / ValueCount); }