示例#1
0
 public BackTest() 
 {
     this.name = "GauntletRun";
     this.mybroker = new Broker();
     EarlyClose = Util.GetCloseTime();
     this.WorkerReportsProgress = true;
     this.WorkerSupportsCancellation = false;
     this.DoWork += new DoWorkEventHandler(BackTest_DoWork);
 }
示例#2
0
        public void DataProvider()
        {
            Tick t = Tick.NewTrade(s, 10, 700);
            // feature to pass-through ticks to any subscriber
            // this can be connected to tradelink library to allow filtered subscribptions
            // and interapplication communication
            Broker broker = new Broker();
            broker.GotTick += new TickDelegate(broker_GotTick);
            Assert.That((receivedtickDP == null) && (gottickDP == 0));
            broker.Execute(t); // should fire a gotTick
            Assert.That(gottickDP != 0);
            Assert.That((receivedtickDP != null) && (receivedtickDP.trade == t.trade));

        }
示例#3
0
        public void BBO()
        {
            Broker broker = new Broker();
            const string s = "TST";
            const decimal p1 = 10m;
            const decimal p2 = 11m;
            const int x = 100;
            Order bid,offer;

            // send bid, make sure it's BBO (since it's only order on any book)
            broker.sendOrder(new BuyLimit(s, x, p1));
            bid = broker.BestBid(s);
            offer = broker.BestOffer(s);
            Assert.That(bid.isValid && (bid.price==p1) && (bid.size==x), bid.ToString());
            Assert.That(!offer.isValid, offer.ToString());

            // add better bid, make sure it's BBO
            uint id1 = broker.sendOrder(new BuyLimit(s, x, p2));
            bid = broker.BestBid(s);
            offer = broker.BestOffer(s);
            Assert.That(bid.isValid && (bid.price == p2) && (bid.size == x), bid.ToString());
            Assert.That(!offer.isValid, offer.ToString());

            // add another bid at same price on another account, make sure it's additive
            uint id2 = broker.sendOrder(new BuyLimit(s, x, p2),new Account("ANOTHER_ACCOUNT"));
            bid = broker.BestBid(s);
            offer = broker.BestOffer(s);
            Assert.That(bid.isValid && (bid.price == p2) && (bid.size == (2*x)), bid.ToString());
            Assert.That(!offer.isValid, offer.ToString());

            // cancel order and make sure bbo returns
            broker.CancelOrder(id1);
            broker.CancelOrder(id2);
            bid = broker.BestBid(s);
            offer = broker.BestOffer(s);
            Assert.That(bid.isValid && (bid.price == p1) && (bid.size == x), bid.ToString());
            Assert.That(!offer.isValid, offer.ToString());

            // other test ideas
            // replicate above tests for sell-side


        }
示例#4
0
 public void Basics()
 {
     Broker broker = new Broker();
     broker.GotFill += new FillDelegate(broker_GotFill);
     broker.GotOrder += new OrderDelegate(broker_GotOrder);
     broker.GotWarning += new DebugDelegate(broker_GotWarning);
     Order o = new Order();
     uint failsoninvalid= broker.sendOrder(o);
     Assert.That(failsoninvalid==0);
     Assert.That(warn == 1);
     Assert.That(orders == 0);
     Assert.That(fills == 0);
     o = new BuyMarket(s, 100);
     Assert.That(broker.sendOrder(o)>0);
     Assert.That(orders == 1);
     Assert.That(fills == 0);
     Assert.That(broker.Execute(Tick.NewTrade(s,10,200)) == 1);
     Assert.That(fills == 1);
     // no warnings since first warning
     Assert.That(warn == 1);
 }
示例#5
0
 // make sure this box only generates orders when last one has been filled
 public void OneOrderAtTime() 
 {
     Always b = new Always();
     b.AllowMultipleOrders = false; // this is the default, but it's what we're testing
     b.MaxSize = Int32.MaxValue; // lets not restrict our maximum position for this example
     Broker broker = new Broker();
     Tick t;
     Assert.That(b.MinSize == 100);
     int good = 0;
     int i = 0;
     Order o = new Order();
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 0);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 1);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     // lets change this to a limit order, so he doesn't get filled on just any tick
     o.price = 1;
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     // first trade was pre-market 2nd order was never filled so 3rd was ignored... 2 total.
     Assert.That(good == 2);
 }