示例#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
文件: GridComputer.cs 项目: rc153/LTF
 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
文件: RateSensor.cs 项目: rc153/LTF
 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
文件: EwmaComputer.cs 项目: rc153/LTF
        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
文件: ExpGrowth.cs 项目: rc153/LTF
 public override double getValue(Time now)
 {
     return gc.getSpeed();
 }
示例#8
0
文件: RateSensor.cs 项目: rc153/LTF
 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
文件: EwmaComputer.cs 项目: rc153/LTF
 public ThirdMeanInitStragey(Time halfLife)
 {
     this.halfLife = halfLife;
 }
示例#11
0
文件: EwmaComputer.cs 项目: rc153/LTF
 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
文件: ExpGrowth.cs 项目: rc153/LTF
 void Speed_midChanged(Time time)
 {
     gc.update(time, instr.MidPrice);
 }
示例#17
0
文件: EwmaComputer.cs 项目: rc153/LTF
 public EwmaComputer(Time halfLife)
     : this(halfLife, new ThirdMeanInitStragey(halfLife))
 {
 }
示例#18
0
文件: EwmaComputer.cs 项目: rc153/LTF
 public double getValue(Time now)
 {
     return update(now, lastX);
 }
示例#19
0
文件: EwmaComputer.cs 项目: rc153/LTF
 public EwmaComputer(Time halfLife, InitStrategy initStrat)
 {
     this.halfLife = halfLife;
     this.minDeltaT = halfLife / 100UL;
     this.initStrat = initStrat;
 }