public override double getValue(Time now) { double sum = 0; for (int i = 1; i < prices1.Length; i++) { sum += Math.Sign((double)(prices1[i] - prices1[i - 1]) * (double)(prices2[i] - prices2[i - 1])); } return sum / prices1.Length; }
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; } }
public void EndRecord(Time now) { long duration = Stopwatch.GetTimestamp() - timeStamp; stat.Add(duration); if (duration > stat.Mean + ThresholdSigma * stat.StandardDeviation) { Time durationNs = new Time(unchecked((ulong)(duration * freq))); Output.DoPerf(now, SensorType.DURATION, Name, 1, durationNs); } }
public override void Initialize() { int size = (int)cfg.getDouble("size", 10); sampleTime = Time.fromSeconds(cfg.getDouble("timeSec", 5 * 60)); prices1 = new WrappedArray<FixedPointDecimal>(size); prices2 = new WrappedArray<FixedPointDecimal>(size); Id id2 = env.GetIdService().GetId(cfg.getString("ref"), cfg.getEnum<SymbolType>("symbolType")); instr2 = env.GetUniverseService().GetInstrument(id2); env.Scheduler.ScheduleAfterBackground(sampleTime, sample); }
public void Record(Time now) { if (++hits >= ThresholdHits) { ulong deltaT = now - start; if (deltaT >= ThresholdTime) { Output.DoPerf(now, SensorType.RATE, Name, hits, deltaT); hits = 0; start = now; } } }
public double update(Time now, double newX) { Time deltaT = now - lastTime; double deltaX = newX - lastX; if (deltaX * 1e6 > newX || deltaT > minDeltaT) { lastX = newX; lastTime = now; if (!initStrat.Done) { value = initStrat.update(deltaT, newX); } else { double alpha = Math.Exp(-(double)deltaT / halfLife); value = alpha * value + (1 - alpha) * newX; } } return value; }
public override double getValue(Time now) { return gc.getSpeed(); }
public RateSensor(string name, uint thresholdHits = 1, Time thresholdTime = default(Time)) { Name = name; ThresholdHits = thresholdHits; ThresholdTime = thresholdTime; }
public override double getValue(Time now) { double refPrice = avg.update(now, instr.MidPrice.ToDouble()); stat.Add(refPrice / instr.MidPrice.ToDouble() - 1); return stat.StandardDeviation; }
public ThirdMeanInitStragey(Time halfLife) { this.halfLife = halfLife; }
public double update(Time deltaT, double newX) { if (3 * sumT > halfLife) Done = true; sumX += deltaT * newX; sumT += deltaT; return sumX / sumT; }
// if you will have a new value after an event, but don't care to receive all updates, use these protected void setDirtyOnTimer(Time halfLife) { // todo check the halflife here instr.quoteChanged += setDirty; }
public abstract double getValue(Time now);
// todo think about carefullt about the dirty model here // todo propagate dirty as events private void setDirty(Time time) { dirty = true; }
private void sample(Time time) { prices1.Write(instr.MidPrice); prices2.Write(instr2.MidPrice); env.Scheduler.ScheduleAfterBackground(sampleTime, sample); }
void Speed_midChanged(Time time) { gc.update(time, instr.MidPrice); }
public EwmaComputer(Time halfLife) : this(halfLife, new ThirdMeanInitStragey(halfLife)) { }
public double getValue(Time now) { return update(now, lastX); }
public EwmaComputer(Time halfLife, InitStrategy initStrat) { this.halfLife = halfLife; this.minDeltaT = halfLife / 100UL; this.initStrat = initStrat; }