Пример #1
0
Файл: Coint.cs Проект: rc153/LTF
 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;
 }
Пример #2
0
 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;
     }
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
Файл: Coint.cs Проект: rc153/LTF
        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);
        }
Пример #5
0
 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;
         }
     }
 }
Пример #6
0
        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;
        }
Пример #7
0
 public override double getValue(Time now)
 {
     return gc.getSpeed();
 }
Пример #8
0
 public RateSensor(string name, uint thresholdHits = 1, Time thresholdTime = default(Time))
 {
     Name = name;
     ThresholdHits = thresholdHits;
     ThresholdTime = thresholdTime;
 }
Пример #9
0
Файл: Vol.cs Проект: rc153/LTF
 public override double getValue(Time now)
 {
     double refPrice = avg.update(now, instr.MidPrice.ToDouble());
     stat.Add(refPrice / instr.MidPrice.ToDouble() - 1);
     return stat.StandardDeviation;
 }
Пример #10
0
 public ThirdMeanInitStragey(Time halfLife)
 {
     this.halfLife = halfLife;
 }
Пример #11
0
 public double update(Time deltaT, double newX)
 {
     if (3 * sumT > halfLife)
         Done = true;
     sumX += deltaT * newX;
     sumT += deltaT;
     return sumX / sumT;
 }
Пример #12
0
 // 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;
 }
Пример #13
0
 public abstract double getValue(Time now);
Пример #14
0
 // todo think about carefullt about the dirty model here
 // todo propagate dirty as events
 private void setDirty(Time time)
 {
     dirty = true;
 }
Пример #15
0
Файл: Coint.cs Проект: rc153/LTF
 private void sample(Time time)
 {
     prices1.Write(instr.MidPrice);
     prices2.Write(instr2.MidPrice);
     env.Scheduler.ScheduleAfterBackground(sampleTime, sample);
 }
Пример #16
0
 void Speed_midChanged(Time time)
 {
     gc.update(time, instr.MidPrice);
 }
Пример #17
0
 public EwmaComputer(Time halfLife)
     : this(halfLife, new ThirdMeanInitStragey(halfLife))
 {
 }
Пример #18
0
 public double getValue(Time now)
 {
     return update(now, lastX);
 }
Пример #19
0
 public EwmaComputer(Time halfLife, InitStrategy initStrat)
 {
     this.halfLife = halfLife;
     this.minDeltaT = halfLife / 100UL;
     this.initStrat = initStrat;
 }