Exemplo n.º 1
0
        static void tryAnotherFile(string destination, string source)
        {
            var match          = Regex.Match(destination, @"(.*)\.([^\.]+)$");
            var extension      = match.Groups[2].Value;
            var everythingElse = match.Groups[1].Value;

            Bomb.unless(match.Success, () => "log file must have an extension: " + destination);
            match = Regex.Match(everythingElse, @"(.*)\.(\d+)$");
            string nextDestination;

            if (match.Success)
            {
                var number = int.Parse(match.Groups[2].Value) + 1;
                Bomb.unless(number < 10, () => "log files 1-9 are locked, nowhere to log to!");
                var prefix = match.Groups[1].Value;
                nextDestination = O.join(".", O.list(prefix, "" + number, extension));
            }
            else
            {
                nextDestination = everythingElse + ".2." + extension;
            }
            setOut(source, nextDestination, true);
        }
Exemplo n.º 2
0
        public void testOnCloseCalledInForecastMode()
        {
            var date = O.date("2009/09/09 11:22:33");
            var bar  = new Bar(1, 1, 1, 1, date);

            processBar(bar);
            var counter = positionPublishCounter();

            processTick(2, date);
            counter.requireCount(2);
            AreEqual(0, counter.get <int>(1, "beginValue"));
            AreEqual(0, counter.get <int>(1, "liveValue"));
            AreEqual(100, counter.get <int>(1, "forecastCloseValue"));
            date = date.AddSeconds(59);
            symbolSystem.tickProcessed = false;
            processTick(2, date);
            IsFalse(symbolSystem.tickProcessed);
            counter.requireCount(2);
            date = date.AddSeconds(1);
            processTick(2, date);
            IsTrue(symbolSystem.tickProcessed);
            counter.requireCount(3);
            AreEqual(100, counter.get <int>(2, "forecastCloseValue"));
        }
Exemplo n.º 3
0
        public void doPlot(IEnumerable <Position> positions)
        {
            clear();
            var closed      = O.accept(positions, position => position.isClosed());
            var pnls        = O.sort(O.convert(closed, toValue));
            var min         = O.first(pnls);
            var max         = O.last(pnls);
            var range       = max - min;
            var bucketCount = Math.Max(Math.Min(150, pnls.Count / 5), 1);
            var blockSize   = Math.Max(1, range / bucketCount);

            if (blockSize == 1)
            {
                bucketCount = (int)range + 1;
            }
            var buckets = O.array(O.nCopies(bucketCount, 0.0));

            O.each(pnls, pnl => {
                var bucket = (int)((pnl - min) / blockSize);
                if (bucket == bucketCount)
                {
                    bucket--;
                }
                buckets[bucket]++;
            });
            var bucketStarts  = O.array(O.convert(buckets, (i, unused) => i * blockSize + min));
            var pnlCount      = O.count(pnls);
            var lowerQuartile = pnls[pnlCount / 4];
            var upperQuartile = pnls[3 * pnlCount / 4];
            var median        = pnls[pnlCount / 2];
            var mean          = O.average(pnls);
            var sd            = O.populationStandardDeviation(pnls);
            var colors        = O.array(O.convert(bucketStarts, (i, bucket) => {
                var isLow    = bucket < median;
                var isBright = bucket <= lowerQuartile || bucket >= upperQuartile;
                if (isLow)
                {
                    return(isBright ? (2.0 / 3.0) : 0.0);
                }
                return(isBright ? 1.0 : (1.0 / 3.0));
            }));
            var points = new PointPairList(bucketStarts, buckets, colors);

            addBars("pnls", O.array(Color.DarkRed, Color.FromArgb(0, 18, 110), Color.Red, Color.FromArgb(0, 60, 255)), points);

            GraphObjList.Add(new LineObj(Color.Lime, 0, 0, 0, 1)
            {
                Location = { CoordinateFrame = CoordType.XScaleYChartFraction },
                Line     = { Style = DashStyle.Dot, Width = 2 }
            });
            GraphObjList.Add(new TextObj(O.join("\n", O.list(
                                                    "min = " + O.prettyNumber(min),
                                                    "25% = " + O.prettyNumber(lowerQuartile),
                                                    "50% = " + O.prettyNumber(median),
                                                    "75% = " + O.prettyNumber(upperQuartile),
                                                    "max = " + O.prettyNumber(max), "",
                                                    "mean = " + O.prettyNumber(mean),
                                                    "sd(pop) = " + O.prettyNumber(sd)
                                                    )), 0.9, 0.12, CoordType.ChartFraction)
            {
                FontSpec = { StringAlignment = StringAlignment.Near }
            });
            BarSettings.MinClusterGap = 0;
            XAxis.Scale.MinGrace      = 0;
            XAxis.Scale.MaxGrace      = 0;
        }
Exemplo n.º 4
0
 protected override SystemArguments arguments()
 {
     return(new SystemArguments(O.list(FOO, BAR), parameters()));
 }
Exemplo n.º 5
0
 public void testSystem()
 {
     addFirstMonth();
     noOrders();
     close(49, 82, 26, 75, 13); // Close of 8/31/2006
     hasOrders(symbols[0], symbols[0].buy("enter long", market(), 408, oneBar()));
     hasOrders(symbols[1], symbols[1].buy("enter long", market(), 244, oneBar()));
     hasOrders(symbols[2], symbols[2].sell("enter short", market(), 1154, oneBar()));
     hasOrders(symbols[3], symbols[3].buy("enter long", market(), 267, oneBar()));
     hasOrders(symbols[4], symbols[4].sell("enter short", market(), 2308, oneBar()));
     AreEqual(O.jDate("2006-08-31"), system().barDate);
     AreEqual(O.jDate("2006-07-31"), system().refDate);
     AreEqual(O.jDate("2006-08-31"), system().evaluationDate);
     AreEqual(O.jDate("2006-08-31"), system().rebalancingDate);
     AreEqual(O.jDate("2006-09-22"), system().tradeExitDate);
     O.zeroTo(5, i => fill(symbols[i], 0, 1));
     close(47, 80, 30, 70, 16); // Close of 9/01/2006
     AreEqual(O.jDate("2006-09-01"), system().barDate);
     AreEqual(O.jDate("2006-07-31"), system().refDate);
     AreEqual(O.jDate("2006-08-31"), system().evaluationDate);
     AreEqual(O.jDate("2006-08-31"), system().rebalancingDate);
     AreEqual(O.jDate("2006-09-22"), system().tradeExitDate);
     hasPosition(symbols[0], 408);
     hasPosition(symbols[1], 244);
     hasPosition(symbols[2], -1154);
     hasPosition(symbols[3], 267);
     hasPosition(symbols[4], -2308);
     close(48, 79, 31, 71, 14);
     close(49, 82, 26, 75, 13);
     addThreeDays();
     addThreeDays();
     addThreeDays();
     close(47, 80, 30, 70, 16);
     close(48, 79, 31, 71, 14);
     hasPosition(symbols[0], 408);
     hasPosition(symbols[1], 244);
     hasPosition(symbols[2], -1154);
     hasPosition(symbols[3], 267);
     hasPosition(symbols[4], -2308);
     AreEqual(O.jDate("2006-09-21"), system().barDate);
     close(49, 82, 26, 75, 13);
     AreEqual(O.jDate("2006-09-22"), system().barDate);
     hasOrders(symbols[0], symbols[0].sell("exit on days in trade", market(), 408, oneBar()));
     hasOrders(symbols[1], symbols[1].sell("exit on days in trade", market(), 244, oneBar()));
     hasOrders(symbols[2], symbols[2].buy("exit on days in trade", market(), 1154, oneBar()));
     hasOrders(symbols[3], symbols[3].sell("exit on days in trade", market(), 267, oneBar()));
     hasOrders(symbols[4], symbols[4].buy("exit on days in trade", market(), 2308, oneBar()));
     O.zeroTo(5, i => fill(symbols[i], 0, 1));
     close(47, 80, 30, 70, 16);
     AreEqual(O.jDate("2006-09-25"), system().barDate);
     AreEqual(O.jDate("2006-08-31"), system().refDate);
     AreEqual(O.jDate("2006-09-29"), system().evaluationDate);
     AreEqual(O.jDate("2006-09-29"), system().rebalancingDate);
     //AreEqual(O.jDate("2006-10-23"), system().tradeExitDate);
     noOrders();
     close(48, 79, 31, 71, 14);
     close(49, 82, 26, 75, 13);
     close(47, 80, 30, 70, 16);
     close(48, 79, 31, 71, 14);
     hasOrders(symbols[0], symbols[0].buy("enter long", market(), 417, oneBar()));
     hasOrders(symbols[1], symbols[1].sell("enter short", market(), 380, oneBar()));
     hasOrders(symbols[2], symbols[2].buy("enter long", market(), 645, oneBar()));
     hasOrders(symbols[3], symbols[3].sell("enter short", market(), 423, oneBar()));
     hasOrders(symbols[4], symbols[4].buy("enter long", market(), 1429, oneBar()));
 }
Exemplo n.º 6
0
 public void testRaceCondition()
 {
     O.zeroTo(10000000, i => new WeakRef <Bar>(new Bar(1, 1, 1, 1)).safeValue());
 }
Exemplo n.º 7
0
 public static DateTime date(string s)
 {
     return(O.date(s));
 }
Exemplo n.º 8
0
 public static void HaveSameCount <T1, T2>(List <T1> ones, List <T2> twos)
 {
     if (ones.Count == twos.Count)
     {
         return;
     }
     throw Bomb.toss("lists have different counts - \nONES: \n" + O.toShortString(ones) + "\nTWOS:\n" + O.toShortString(twos));
 }
Exemplo n.º 9
0
 public void addColumns(int n)
 {
     O.zeroTo(n, i => addColumn());
 }
Exemplo n.º 10
0
 public void testTimeTolerance4()
 {
     startingBars();
     processBar(907.25, 913.5, 906.25, 913, O.date("2009-06-18 10:00:16"));
     noOrders();
 }
Exemplo n.º 11
0
 public void testTimeTolerance3()
 {
     startingBars();
     processBar(907.25, 913.5, 906.25, 913, O.date("2009-06-18 09:59:44"));
     noOrders();
 }
Exemplo n.º 12
0
 [Test] public void testLogPrologIsCallable()
 {
     // info(util.Log.prolog() + "some string");
     O.info("some string");
 }
Exemplo n.º 13
0
        UIElement filterPanel()
        {
            var result = new QGrid {
                Height = 25
            };

            result.addColumn(200);
            result.addColumn(100);
            result.addColumn(100);
            result.add(new QComboBox("ALL", selected => watcher.setTagFilter(selected), O.list <string>(BloombergTagsTable.TAGS.C_TAG.distinct(Clause.TRUE))));
            result.add(new QCheckBox("Show Zeros", false, setting => watcher.setFilterZeroes(!setting)), 1);
            result.add(new QCheckBox("Show Hidden", false, setting => watcher.setShowHidden(setting)), 2);
            return(result);
        }
Exemplo n.º 14
0
 public void testReverse()
 {
     AreEqual(O.list(4, 3, 2, 1), O.list(O.reverse(Objects.list(1, 2, 3, 4))));
     AreEqual(O.list(O.reverse(O.reverse(Objects.seq(15)))), O.list(O.seq(15)));
 }
Exemplo n.º 15
0
 List <Order> orders()
 {
     return(O.collect(symbols, s => orders(s)));
 }
Exemplo n.º 16
0
 Dictionary <Symbol, Bar> bars(DateTime current)
 {
     return(O.dictionary(symbols, symbol => new Bar(1, 1, 1, 1, current)));
 }
Exemplo n.º 17
0
 public void testCase1()
 {
     startingBars();
     processBar(907.25, 913.5, 906.25, 913, O.date("2009-06-18 10:00:10"));
     hasOrders(buy("Entry L", limit(913.5), 48, oneDay()));
     fill(0, 913);
     AreEqual(true, symbolSystem.hasBeenMarked);
     hasOrders(sell("Stop L", protectiveStop(908.87), 48, oneDay()));
     processBar(916.25, 916.75, 914.75, 915, O.date("2009-06-18 14:00:00"));
     hasOrders(sell("Stop L", protectiveStop(908.87), 48, oneDay()));
     AreEqual(4800, symbolSystem.lastTradePNL);
     AreEqual(true, symbolSystem.hasBeenMarked);
     AreEqual(false, symbolSystem.hasBeenClosed);
     processBar(912.25, 913.75, 911.5, 913.75, O.date("2009-06-18 16:00:00"));
     hasOrders(
         sell("Stop L", protectiveStop(908.87), 48, oneDay()),
         sell("Exit EOD L", limit(908.75), 48, oneDay())
         );
     fill(0, 913.75);
     noOrders();
     AreEqual(false, symbolSystem.hasBeenMarked);
     AreEqual(true, symbolSystem.hasBeenClosed);
     AreEqual(1800, symbolSystem.lastTradePNL);
     processBar(921.25, 921.75, 920.5, 921, O.date("2009-06-19 09:00:00"));
     AreEqual(1, symbolSystem.scaleWins[0]);
     AreEqual(false, symbolSystem.hasBeenMarked);
     AreEqual(true, symbolSystem.hasBeenClosed);
     processBar(921.5, 922.5, 920.75, 921.25, O.date("2009-06-19 10:00:00"));
     hasOrders(buy("Entry L", limit(921.75), 48, oneDay()));
     fill(0, 921.25);
     AreEqual(true, symbolSystem.hasBeenMarked);
     AreEqual(false, symbolSystem.hasBeenClosed);
     hasOrders(sell("Stop L", protectiveStop(917.08), 48, oneDay()));
     processBar(915.5, 916.5, 914.5, 917.5, O.date("2009-06-19 14:00:00"));
     hasOrders(sell("Stop L", protectiveStop(917.08), 48, oneDay()));
     AreEqual(-9000, symbolSystem.lastTradePNL);
     processBar(914.75, 916, 914.75, 916, O.date("2009-06-19 16:00:00"));
     hasOrders(
         sell("Stop L", protectiveStop(917.08), 48, oneDay()),
         sell("Exit EOD L", limit(911), 48, oneDay())
         );
     fill(0, 916);
     AreEqual(-12600, symbolSystem.lastTradePNL);
     processBar(906.25, 906.75, 906, 906.25, O.date("2009-06-22 09:00:00"));
     AreEqual(0, symbolSystem.scaleWins[0]);
     AreEqual(1, symbolSystem.scaleWins[1]);
     AreEqual(0.5, symbolSystem.scaleWins[2]);
     AreEqual(0.5, symbolSystem.scaleWins[9]);
     noOrders();
     noPositions();
     processBar(902.5, 903, 899.5, 900.25, O.date("2009-06-22 10:00:00"));
     hasOrders(sell("Entry S", limit(899.75), 38, oneDay()));
     fill(0, 900.25);
     hasOrders(buy("Stop S", protectiveStop(905.49), 38, oneDay()));
     processBar(893, 893.5, 892.25, 893, O.date("2009-06-22 14:00:00"));
     hasOrders(buy("Stop S", protectiveStop(905.49), 38, oneDay()));
     AreEqual(13775, symbolSystem.lastTradePNL);
     processBar(888.5, 889.5, 888, 884, O.date("2009-06-22 16:00:00"));
     hasOrders(
         buy("Stop S", protectiveStop(905.49), 38, oneDay()),
         buy("Exit EOD S", limit(889), 38, oneDay())
         );
     fill(0, 884);
     noOrders();
     noPositions();
     AreEqual(30875, symbolSystem.lastTradePNL);
     processBar(893.5, 893.75, 892, 892.25, O.date("2009-06-23 09:00:00"));
     AreEqual(1, symbolSystem.scaleWins[0]);
     AreEqual(0, symbolSystem.scaleWins[1]);
     AreEqual(1, symbolSystem.scaleWins[2]);
     AreEqual(0.5, symbolSystem.scaleWins[3]);
     AreEqual(0.5, symbolSystem.scaleWins[9]);
     noOrders();
     noPositions();
     processBar(891.25, 894, 891, 893.5, O.date("2009-06-23 10:00:00"));
     hasOrders(buy("Entry L", limit(894), 35, oneDay()));
     fill(0, 893.5);
     hasOrders(sell("Stop L", protectiveStop(887.83), 35, oneDay()));
     processBar(889.75, 890.75, 888.25, 887, O.date("2009-06-23 14:00:00"));
     hasOrders(sell("Stop L", protectiveStop(887.83), 35, oneDay()));
     fill(0, 887.83);
     noOrders();
     AreEqual(-11375, symbolSystem.lastTradePNL);
     noPositions();
     processBar(889.5, 890.25, 889.25, 890, O.date("2009-06-23 16:00:00"));
     AreEqual(0, symbolSystem.scaleWins[0]);
     AreEqual(1, symbolSystem.scaleWins[1]);
     AreEqual(0, symbolSystem.scaleWins[2]);
     AreEqual(1, symbolSystem.scaleWins[3]);
     AreEqual(0.5, symbolSystem.scaleWins[4]);
     AreEqual(0.5, symbolSystem.scaleWins[9]);
     noOrders();
     noPositions();
     processBar(893.5, 893.75, 892, 892.25, O.date("2009-06-24 09:00:00"));
     processBar(891.25, 894, 891, 897.5, O.date("2009-06-24 10:00:00"));
     noOrders();
     noPositions();
     processBar(889.75, 890.75, 888.25, 887, O.date("2009-06-24 14:00:00"));
     noOrders();
     noPositions();
     processBar(889.5, 890.25, 889.25, 890, O.date("2009-06-24 16:00:00"));
     AreEqual(0, symbolSystem.scaleWins[0]);
     AreEqual(1, symbolSystem.scaleWins[1]);
     AreEqual(0, symbolSystem.scaleWins[2]);
     AreEqual(1, symbolSystem.scaleWins[3]);
     AreEqual(0.5, symbolSystem.scaleWins[4]);
     AreEqual(0.5, symbolSystem.scaleWins[9]);
     noOrders();
     noPositions();
 }
Exemplo n.º 18
0
 public void testProcessCloseOrdersTime()
 {
     AreEqual(O.date(Dates.todayAt("12:30:00")), new Symbol("MKT2").processCloseOrdersTime());
 }
 protected override SystemArguments arguments()
 {
     return(new SystemArguments(O.list(symbol2, symbol3, symbol4, symbol5), parameters()));
 }
Exemplo n.º 20
0
 public static void HaveSameCount <T1, T2>(T1[] ones, T2[] twos)
 {
     if (ones.GetLength(0) == twos.GetLength(0))
     {
         return;
     }
     throw Bomb.toss("lists have different counts - \nONES: \n" + O.toShortString(ones) + "\nTWOS:\n" + O.toShortString(twos));
 }
 public override void setUp()
 {
     base.setUp();
     O.eachValue(system().systems_, s => s.enterTestMode());
 }
Exemplo n.º 22
0
 public override void setUp()
 {
     base.setUp();
     O.zeroTo(leadBars(), i => processBar(0, 0, 0, 0));
 }
Exemplo n.º 23
0
 static DateTime millisAhead(int millis)
 {
     return(O.now().AddMilliseconds(millis));
 }