Ejemplo n.º 1
0
        public void testSynchronicity()
        {
            var manager = new SpudManager();
            var d       = new RootSpud <double>(manager);

            Bombs(() => O.info("" + d[0]), "uninitialized");
            d.set(7.5);
            var i = new RootSpud <int>(manager);

            i.set(4);
            var b = new RootSpud <bool>(manager);

            b.set(true);
            manager.newBar();
            d.set(6.5);
            i.set(3);
            b.set(false);
            manager.newBar();
            i.set(2);
            AreEqual(8.5, d[0] + i[0]);
            AreEqual(6.5, d[0]);
            AreEqual(6.5, d[1]);
            AreEqual(7.5, d[2]);
            AreEqual(2, i[0]);
            AreEqual(3, i[1]);
            AreEqual(4, i[2]);
            AreEqual(false, b[0]);
            AreEqual(false, b[1]);
            AreEqual(true, b[2]);
        }
Ejemplo n.º 2
0
        public void testLogSpud()
        {
            var manager = new SpudManager();
            var r       = new RootSpud <double>(manager);
            var d       = new LogSpud(r);

            r.set(-5);
            AreEqual(double.NaN, d[0]);
            r.set(1);
            AreEqual(0, d[0]);
            manager.newBar();
            r.set(6.5);
            AlmostEqual(1.871802, d[0], 1e-6);
            manager.newBar();
            r.set(10);
            AlmostEqual(2.302585, d[0], 1e-6);
            AlmostEqual(1.871802, d[1], 1e-6);
            manager.newBar();
            r.set(0);
            AreEqual(double.NaN, d[0]);
            manager.newBar();
            r.set(-1);
            AreEqual(double.NaN, d[0]);
            r.set(3);
            AlmostEqual(1.098612, d[0], 1e-6);
            AreEqual(double.NaN, d[1]);
        }
Ejemplo n.º 3
0
        public void testSymbolValueLive()
        {
            Log.setFile(@"C:\logs\jefftest");

            SystemTimeSeriesTable.SYSTEM_TS.insert("testone", "ASCII", "ActiveMQ", "somedangtopic");
            AsciiTable.SYSTEM_ASCII.insert("testone", @"\\nysrv37\share\Tools\RightEdge\TransitionTest\TY1C.full.csv", true, 1);
            var manager  = new SpudManager();
            var barSpud  = new BarSpud(manager);
            var barSpud2 = new BarSpud(manager);
            var symbol   = new Symbol("testone");
            var spud     = symbol.doubles(barSpud);
            var spud2    = new Symbol("RE.TEST.TY.1C").doubles(barSpud2);

            manager.newBar();
            barSpud.set(new Bar(1, 3, 1, 2, O.date("2008/08/06")));
            barSpud2.set(new Bar(1, 3, 1, 2, O.date("2008/08/06")));

            manager.newTick();
            spud.doSubscribe();

            barSpud.lastTickedAt(O.date("2008/08/06 11:22:34"));
            spud2.doSubscribe();
            IsTrue(spud2.isDirty());
            symbol.javaSymbol().jmsLive().topic().send("value=97.1|timestamp=2008/08/06 11:22:33|MSTimestamp=2008/06/05 13:10:08");

            Bombs(() => LogC.info("" + spud[0]), "stale");
            symbol.javaSymbol().jmsLive().topic().send("value=97.2|timestamp=2008/08/06 11:22:34|MSTimestamp=2008/06/05 13:10:08");
            O.wait(() => spud[0] == 97.2);
            barSpud.lastTickedAt(O.date("2008/08/06 11:22:35"));
            spud.allowStaleTicks();
            AreEqual(97.2, spud[0]);
            AreEqual(116.140625, spud2[0]);
        }
Ejemplo n.º 4
0
        public void testDiffSpudLag0()
        {
            var manager = new SpudManager();
            var r       = new RootSpud <double>(manager);

            Bombs(() => new DiffSpud(r, 0), "lag should be >= 1");
        }
Ejemplo n.º 5
0
        public void testSpud()
        {
            var manager = new SpudManager();
            var v       = new RootSpud <double>(manager);

            v.set(7);
            Double foo = v;

            AreEqual(7.0, foo);
            v.set(6);
            AreEqual(6.0, (double)v);
            manager.newBar();
            AreEqual(6.0, v[0]);
            AreEqual(6.0, v[1]);
            v.set(3);
            AreEqual(3.0, v[0]);
            AreEqual(6.0, v[1]);
            manager.newBar();
            v.set(8);
            v.set(9);
            AreEqual(9.0, (double)v);
            AreEqual(9.0, v[0]);
            AreEqual(3.0, v[1]);
            AreEqual(6, v[2]);
        }
Ejemplo n.º 6
0
        public void testInvalidSpudBlowsUp()
        {
            var           manager = new SpudManager();
            Spud <double> v       = new RootSpud <double>(manager);

            new DoesNotDependsOnProperly(v);
            Bombs(manager.newBar, "failed@1", "dependsOn");
        }
Ejemplo n.º 7
0
        public void testPushDownOnNonRetrievedSpud()
        {
            var manager = new SpudManager();
            var a       = new RootSpud <double>(manager);
            var child   = new DependentSpud(a);

            a.set(1.0);
            manager.newBar();
            AreEqual(2.0, child[1]);
        }
Ejemplo n.º 8
0
            public MakesLoop(SpudManager manager, int size) : base(manager)
            {
                Spud <double> last = this;

                zeroTo(size, i => {
                    Spud <double> next = new RootSpud <double>(manager);
                    next.dependsOn(last);
                    last = next;
                });
                dependsOn(last);
            }
Ejemplo n.º 9
0
        public void testSymbolValueSpud()
        {
            var manager = new SpudManager();
            var barSpud = new BarSpud(manager);
            var spud    = new Symbol("RE.TEST.TY.1C").doubles(barSpud);

            barSpud.set(new Bar(1, 3, 1, 2, O.date("2007/01/02")));
            AreEqual(105.04687500, spud[0]);

            // test barSPud has date, but spud does not
            manager.newBar();
            barSpud.set(new Bar(1, 3, 1, 2, O.date("2007/01/06")));
            AreEqual(105.32812500, spud[0]);
        }
Ejemplo n.º 10
0
        public void testObserver()
        {
            var manager  = new SpudManager();
            var observed = new RootSpud <double>(manager);

            observed.valueChanged += onChanged;
            observed.set(1.0);
            AreEqual(1, getAndReset());
            manager.newBar();
            AreEqual(0, getAndReset());
            observed.set(1.0);
            AreEqual(0, getAndReset());
            AreEqual(1.0, value);
        }
Ejemplo n.º 11
0
        public void testDiffSpudLag1()
        {
            var manager = new SpudManager();
            var r       = new RootSpud <double>(manager);
            var d       = new DiffSpud(r, 1);

            r.set(7.5);
            AreEqual(double.NaN, d[0]);
            manager.newBar();
            r.set(6.5);
            AreEqual(-1, d[0]);
            manager.newBar();
            r.set(10);
            AreEqual(3.5, d[0]);
        }
Ejemplo n.º 12
0
        public void testHasNaNs()
        {
            var manager = new SpudManager();
            var d       = new RootSpud <double>(manager);

            IsFalse(d.hasNaN(10));
            manager.newBar();
            d.set(double.NaN);
            IsTrue(d.hasNaN(1));
            manager.newBar();
            d.set(0);
            IsFalse(d.hasNaN(1));
            IsTrue(d.hasNaN(2));
            IsTrue(d.hasNaN(10));
        }
Ejemplo n.º 13
0
        public void testTransform()
        {
            var manager = new SpudManager();
            var d       = new RootSpud <double>(manager);
            var i       = d.transform(x => (int)Math.Round(x));

            d.set(7.5);
            AreEqual(8, i[0]);
            d.set(6.5);
            AreEqual(6, i[0]);
            manager.newBar();
            AreEqual(6, i[0]);
            d.set(5.4);
            AreEqual(5, i[0]);
            AreEqual(6, i[1]);
        }
Ejemplo n.º 14
0
        public void testChanged()
        {
            var manager = new SpudManager();
            var v       = new RootSpud <double>(manager);

            Bombs(() => v.changed(), "uninitialized");
            v.set(4.0);
            IsTrue(v.changed());
            manager.newBar();
            IsFalse(v.changed());
            v.set(5.0);
            IsTrue(v.changed());
            manager.newBar();
            v.set(5.0);
            IsFalse(v.changed());
        }
Ejemplo n.º 15
0
        public void testLast10()
        {
            var manager = new SpudManager();
            var v       = new RootSpud <double>(manager);

            AreEqual("EMPTYSPUD", v.last10());
            Last10Matches(manager, "1", v, 1);
            Last10Matches(manager, "2, 1", v, 2);
            Last10Matches(manager, "3, 2, 1", v, 3);
            Last10Matches(manager, "4, 3, 2, 1", v, 4);
            Last10Matches(manager, "5, 4, 3, 2, 1", v, 5);
            Last10Matches(manager, "6, 5, 4, 3, 2, 1", v, 6);
            Last10Matches(manager, "7, 6, 5, 4, 3, 2, 1", v, 7);
            Last10Matches(manager, "8, 7, 6, 5, 4, 3, 2, 1", v, 8);
            Last10Matches(manager, "9, 8, 7, 6, 5, 4, 3, 2, 1", v, 9);
            Last10Matches(manager, "10, 9, 8, 7, 6, 5, 4, 3, 2, 1", v, 10);
            Last10Matches(manager, "11, 10, 9, 8, 7, 6, 5, 4, 3, 2, ...", v, 11);
        }
Ejemplo n.º 16
0
        public void testCrossOver()
        {
            var manager   = new SpudManager();
            var spud1     = new RootSpud <double>(manager);
            var spud2     = new RootSpud <double>(manager);
            var crossOver = new CrossOverSpud <double>(spud1, spud2);

            spud1.set(1);
            spud2.set(1);
            IsFalse(crossOver.crossedAbove());
            IsFalse(crossOver.crossedBelow());
            IsFalse(crossOver.crossed());
            manager.newBar();
            spud1.set(1);
            spud2.set(2);
            IsFalse(crossOver.crossedAbove());
            IsFalse(crossOver.crossedBelow());
            IsFalse(crossOver.crossed());
            manager.newBar();
            spud1.set(2);
            spud2.set(1);
            IsTrue(crossOver.crossedAbove());
            IsFalse(crossOver.crossedBelow());
            IsTrue(crossOver.crossed());
            manager.newBar();
            spud1.set(1);
            spud2.set(2);
            IsFalse(crossOver.crossedAbove());
            IsTrue(crossOver.crossedBelow());
            IsTrue(crossOver.crossed());
            manager.newBar();
            spud1.set(2);
            IsFalse(crossOver.crossedAbove());
            IsFalse(crossOver.crossedBelow());
            IsFalse(crossOver.crossed());
            manager.newBar();
            spud1.set(3);
            IsTrue(crossOver.crossedAbove());
            IsFalse(crossOver.crossedBelow());
            IsTrue(crossOver.crossed());
        }
Ejemplo n.º 17
0
        public void testSymbolBarSpud()
        {
            var manager = new SpudManager();
            var barSpud = new BarSpud(manager);
            var symbol  = new Symbol("RE.TEST.TY.1C");
            var spud    = symbol.bars(barSpud);

            barSpud.set(new Bar(1, 3, 1, 2, O.date("2007/01/02")));
            AreEqual(105.04687500, spud[0].close);
            barSpud.lastTickedAt(O.date("2007/01/02 12:34:55"));
            symbol.javaSymbol().jmsLive().publish(new JTick(98, 100, 96, 99, 93, O.jDate("2007/01/02 12:34:56")));
            O.sleep(250);
            AreEqual(105.04687500, spud[0].close);

            manager.goLive();
            symbol.javaSymbol().jmsLive().publish(new JTick(98, 100, 96, 99, 93, O.jDate("2007/01/02 12:34:57")));
            O.wait(() => spud[0].time.Equals(date("2007/01/02 12:34:57")));

            AreEqual(98.0, spud[0].close);
            AreEqual(93.0, spud[0].low);
        }
Ejemplo n.º 18
0
        public void testDependencies()
        {
            var manager      = new SpudManager();
            var root         = new RootSpud <double>(manager);
            var otherRoot    = new RootSpud <double>(manager);
            var plusOne      = new DependentSpud(root);
            var plusTwo      = new DependsOnDependent(root);
            var otherPlusOne = new DependentSpud(otherRoot);

            root.set(7);
            AreEqual(8, plusOne[0]);
            AreEqual(9, plusTwo[0]);
            IsTrue(plusOne.checkAndReset());
            IsTrue(plusTwo.checkAndReset());
            otherRoot.set(15);
            IsFalse(plusOne.checkAndReset());
            IsFalse(plusTwo.checkAndReset());
            IsFalse(otherPlusOne.checkAndReset());
            AreEqual(16.0, otherPlusOne[0]);
            IsTrue(otherPlusOne.checkAndReset());
            AreEqual(8, plusOne[0]);
            AreEqual(9, plusTwo[0]);

            root.set(11);
            manager.newBar();

            AreEqual(12, plusOne[1]);
            AreEqual(13, plusTwo[1]);
            IsTrue(plusOne.checkAndReset());
            IsTrue(plusTwo.checkAndReset());

            IsFalse(plusOne.checkAndReset());
            IsFalse(plusTwo.checkAndReset());
            root.set(30);
            AreEqual(31, plusOne[0]);
            AreEqual(32, plusTwo[0]);
            IsTrue(plusOne.checkAndReset());
            IsTrue(plusTwo.checkAndReset());
            IsFalse(otherPlusOne.checkAndReset());
        }
Ejemplo n.º 19
0
 protected SpudBase(SpudManager manager)
 {
     this.manager = manager;
     manager.register(this);
 }
Ejemplo n.º 20
0
        public void testLoopsBork()
        {
            var manager = new SpudManager();

            Bombs(() => new MakesLoop(manager, 10), "loop");
        }
Ejemplo n.º 21
0
 static void Last10Matches(SpudManager manager, string s, RootSpud <double> v, int i)
 {
     v.set(i);
     AreEqual(s, v.last10());
     manager.newBar();
 }
Ejemplo n.º 22
0
 public RootSpud(SpudManager manager, T initialValue) : base(manager)
 {
     set(initialValue);
 }
Ejemplo n.º 23
0
 protected Spud(SpudManager manager) : base(manager)
 {
     valueChanged += doNothing;
     valueSet     += doNothing;
     pushedDown   += doNothing;
 }
Ejemplo n.º 24
0
 protected ComparableSpud(SpudManager manager) : base(manager)
 {
 }
Ejemplo n.º 25
0
 public RootSpud(SpudManager manager) : base(manager)
 {
 }