Example #1
0
        static void ExceptionTraceIsCorrect(bool reallyDie, Exception e, ICollection <string> patterns)
        {
            if (reallyDie)
            {
                Fail("expected failure did not occur");
            }
            if (O.isEmpty(patterns))
            {
                Bomb.toss("expected failure occurred, provide regex to Bombs\nEXPECTED:" + e);
            }
            var exceptions = O.list <Exception>();

            exceptions.Add(e);
            while (e != e.GetBaseException())
            {
                e = e.GetBaseException();
                exceptions.Add(e);
            }
            var messages = O.convert(exceptions, anE => anE.Message);

            try {
                Bomb.when(
                    patterns.Count > exceptions.Count,
                    () => "exception stack not deep enough for " + patterns.Count + " patterns:\n" + e
                    );
                O.each(patterns, messages, Matches);
            } catch (Exception matchFailed) {
                Bomb.toss("expected patterns:\n" + O.toShortString(patterns) +
                          "\ndid not match exception messages:\n" + O.toShortString(messages), matchFailed);
            }
        }
Example #2
0
 public void testMetrics()
 {
     bar(1, 2, 10, 4);
     fill(A, 0, 2);
     fill(B, 0, 2);
     fill(C, 0, 2);
     fill(D, 0, 2);
     bar(2, 4, 6, 8);
     bar(0, 0, 0, 0);
     bar(3, 6, 9, 2);
     bar(2, 3, 4, 5);
     O.each(O.copy(system().allPositions()), p => system().systems_[p.symbol].placeOrder(p.exit("f-in a", market(), fillOrKill())));
     fill(A, 0, 0);
     fill(B, 0, 0);
     fill(C, 0, 0);
     fill(D, 0, 0);
     bar(5, 7, 9, 11);
     bridge().statistics().writeSTOFiles(true);
     checkMetrics(A.name, "QNetProfit", -2);
     checkMetrics("ALL", "QNetProfit", -8);
     checkMetrics(A.name, "QMaxDrawdown", -3);
     checkMetrics("ALL", "QMaxDrawdown", -20);
     checkMetrics("P1", "QMaxDrawdown", -15);
     checkMetrics("P2", "QMaxDrawdown", -30);
 }
Example #3
0
        protected override void initializeSymbols()
        {
            base.initializeSymbols();
            var names = new List <string>();

            O.zeroTo(50, i => names.Add("sym" + (i + 1)));
            symbols = O.list(O.convert(names, name => new Symbol(name)));
            O.each(symbols, symbol => insertMarket(symbol.name, 0.0));
            O.each(symbols, symbol => insertSymbol("RC." + symbol.name));
        }
Example #4
0
        protected override void initializeSymbols()
        {
            var names = new List <string>();

            O.zeroTo(5, i => names.Add("sym" + (i + 1)));
            symbols = O.list(O.convert(names, name => new Symbol(name)));
            var series = createEmptyTestSeries();

            O.each(symbols, symbol => setupSymbol(symbol, series));
        }
Example #5
0
        void populateNoClear(IEnumerable <string> rest, bool sortEntries)
        {
            if (O.isEmpty(rest))
            {
                return;
            }
            var items = sortEntries ? O.sort(rest) : rest;

            O.each(items, item => Items.Add(new ComboBoxItem {
                Content = item
            }));
        }
Example #6
0
        [Test] public void testEach()
        {
            var result = new List <string>();

            O.each(LETTERS, result.Add);
            AreEqual(LETTERS, result);
            result.Clear();
            O.eachIt(LETTERS, (i, s) => result.Add(i + " " + s));
            AreEqual(O.list("0 a", "1 b", "2 c"), result);
            int[] sum = { 0 };
            O.eachIt(START, delegate(int i, int val) { sum[0] += val + i; });
            AreEqual(sum[0], 21);
            sum[0] = 0;
            O.eachIt(O.list(7, 8, 9), delegate(int i, int val) { sum[0] += val * i; });
            AreEqual(sum[0], 26);
        }
        void close(double c1, double c2, double c3, double c4, double c5)
        {
            var date = nextTime();
            var bars = new Dictionary <Symbol, Bar> {
                { symbol1, new Bar(c1, date) },
                { symbol2, new Bar(c2, date) },
                { symbol3, new Bar(c3, date) },
                { symbol4, new Bar(c4, date) },
                { symbol5, new Bar(c5, date) },
            };

            O.each(system().systems_, (pair, pairSystem) => {
                pairSystem.leftPrior.add(date, bars[CommodityCarry.prior(pair.left)]);
                pairSystem.rightPrior.add(date, bars[CommodityCarry.prior(pair.right)]);
            });
            bars.Remove(symbol1);
            processClose(lastBar => bars);
        }
Example #8
0
        public void testSystem()
        {
            var rc = 0.0;

            O.each(symbols, symbol => system().richCheap[symbol].enterTestMode());
            O.each(symbols, symbol => system().richCheap[symbol].add(time, rc++));
            bridge().processBar(bars(time));
            hasOrders(symbols[0], symbols[0].buy("enter long", market(), 1, oneBar()));
            hasOrders(symbols[1], symbols[1].buy("enter long", market(), 1, oneBar()));
            hasOrders(symbols[2], symbols[2].buy("enter long", market(), 1, oneBar()));
            hasOrders(symbols[49], symbols[49].sell("enter short", market(), 1, oneBar()));
            hasOrders(symbols[48], symbols[48].sell("enter short", market(), 1, oneBar()));
            hasOrders(symbols[47], symbols[47].sell("enter short", market(), 1, oneBar()));
            var i = 1;

            system().richCheap[O.first(symbols)].add(time.AddDays(i++), 100);
            processBar(bars(time.AddDays(1)));
            hasOrders(symbols[3], symbols[3].buy("enter long", market(), 1, oneBar()));
            hasOrders(symbols[1], symbols[1].buy("enter long", market(), 1, oneBar()));
            hasOrders(symbols[2], symbols[2].buy("enter long", market(), 1, oneBar()));
            hasOrders(symbols[49], symbols[49].sell("enter short", market(), 1, oneBar()));
            hasOrders(symbols[48], symbols[48].sell("enter short", market(), 1, oneBar()));
            hasOrders(symbols[0], symbols[0].sell("enter short", market(), 1, oneBar()));
            O.each(orders(), order => fill(order, 0));
            processBar(bars(time.AddDays(i++)));
            noOrders();
            processBar(bars(time.AddDays(i++)));
            noOrders();
            processBar(bars(time.AddDays(i++)));
            noOrders();
            system().richCheap[O.first(symbols)].add(time.AddDays(i), 0);
            processBar(bars(time.AddDays(i++)));
            hasOrders(symbols[3], symbols[3].sell("exit long", market(), 1, oneBar()));
            hasOrders(symbols[47], symbols[47].sell("enter short", market(), 1, oneBar()));
            hasOrders(symbols[0], symbols[0].buy("enter long", market(), 1, oneBar()), symbols[0].buy("exit short", market(), 1, oneBar()));
            O.each(O.copy(orders()), order => fill(order, 0));
            system().richCheap[O.first(symbols)].add(time.AddDays(i), 100);
            processBar(bars(time.AddDays(i)));
            noOrders(); // holding period
        }
Example #9
0
        [Test] public void testParallelEach()
        {
            string[] content = { "" };
            O.each(
                LETTERS,
                START,
                delegate(int i, string s, int val) {
                content[0] += i + ":" + s + "(" + val + ")";
                O.info(i + ":" + s + "(" + val + ")");
            });
            AreEqual("0:a(5)1:b(6)2:c(7)", content[0]);
            content[0] = "";
            O.each(LETTERS, START, delegate(string s, int val) { content[0] += s + "(" + val + ")"; });
            AreEqual("a(5)b(6)c(7)", content[0]);
            Bombs(() => O.each(O.list(1, 2, 3, 4), O.list(2, 3, 4), delegate(int i1, int i2) { }),
                  "failed",
                  "mismatched");
            Bombs(() => O.each(O.list(1, 2, 3), O.list(1, 2, 3, 4), delegate(int i1, int i2) { }), "mismatched");

            Bombs(() => O.each(O.list(4, 5, 6), val => Bomb.when(val == 5, () => "VALUE IS 5!")),
                  "failed@1, processing: 5 in \\[4, 5, 6\\]", "VALUE IS 5");
        }
Example #10
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;
        }