public void update(Time time, FixedPointDecimal newPrice) { double thisReturn = (double)newPrice / (double)prevPrice - 1; if (thisReturn > +returnThreshold || thisReturn < -returnThreshold) { times.Write(time); prices.Write(newPrice); prevPrice = newPrice; } }
private int binarySearch(FixedPointDecimal price, int equal) { int low = 0; int high = bounds.Length - 1; while (low <= high) { int mid = low + ((high - low) >> 1); int order = price.CompareTo(bounds[mid]); if (order == 0) return mid + equal; if (order < 0) high = mid - 1; else low = mid + 1; } return low; }
public void WriteFixedPointDecimal(FixedPointDecimal fp) { WriteInt64(fp.ToRaw()); }
private void Init(FixedPointDecimal value) { this.value = value; }
public FixedPointDecimal roundUp(FixedPointDecimal price) { return price.RoundUp(value); }
public FixedPointDecimal getTickUp(FixedPointDecimal price) { return value; }
public FixedPointDecimal getBoundUp(FixedPointDecimal price) { return FixedPointDecimal.MaxValue; }
public FixedPointDecimal getBoundDown(FixedPointDecimal price) { return FixedPointDecimal.MinValue; }
public FixedTickSize(FixedPointDecimal value) { Init(value); }
private int findIndexOfDown(FixedPointDecimal price) { return binarySearch(price, 0); /* for (int i = 0; i < bounds.Length; i++) { if (price <= bounds[i]) return i; } return bounds.Length; */ }
public FixedPointDecimal roundUp(FixedPointDecimal price) { int i = findIndexOfUp(price); return price.RoundUp(values[i]); }
public FixedPointDecimal getTickUp(FixedPointDecimal price) { int i = findIndexOfUp(price); return values[i]; }
public FixedPointDecimal getBoundUp(FixedPointDecimal price) { int i = findIndexOfUp(price); if (i == bounds.Length) return FixedPointDecimal.MaxValue; return bounds[i]; }
public FixedPointDecimal getBoundDown(FixedPointDecimal price) { int i = findIndexOfDown(price) - 1; if (i == -1) return FixedPointDecimal.MinValue; return bounds[i]; }
public static void Encode(byte[] buffer, ref uint offset, FixedPointDecimal value, byte field_number) { EncodeFieldAndType(buffer, ref offset, 0, field_number); Varint.EncodeInt64(buffer, ref offset, value.ToRaw()); }