Exemple #1
0
        public void TestShortBidOffer()
        {
            symbol = Factory.Symbol.LookupSymbol("EUR/USD");
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Retrace        = .60;
            inventory.RoundLotSize   = 1000;
            inventory.MaximumLotSize = 1000;
            inventory.MinimumLotSize = 1000;
            inventory.Goal           = 5000;
            //Console.WriteLine("Price,Quantity,Cumulative,BreakEven,PandL");
            var first = true;
            var sb    = new StringBuilder();
            var price = 1.7000D;

            for (var i = 0; i < 3000; i++)
            {
                var amountToOffer = 0;
                inventory.CalculateBidOffer(price, price);
                amountToOffer = inventory.OfferSize;
                inventory.Change(price, -amountToOffer);
                var pandl = inventory.CurrentProfitLoss(price);
                sb.AppendLine(Round(price) + "," + amountToOffer + "," + inventory.Size + "," + Round(inventory.BreakEven) + "," + Round(pandl));
                price += symbol.MinimumTick * 10;
            }
            //Console.Write(sb.ToString());
        }
Exemple #2
0
        public void CalculateBidOffer(double marketBid, double marketOffer)
        {
            marketBid   -= 10 * symbol.MinimumTick * bidOffset;
            marketOffer += 10 * symbol.MinimumTick * offerOffset;
            bidOwner     = offerOwner = active.First.Value;
            var spread = 0D;

            for (var current = active.First; current != null; current = current.Next)
            {
                var inventory = current.Value;
                inventory.CalculateBidOffer(marketBid, marketOffer);
                CompareBidOffer(inventory);
                spread = offerOwner.Offer - bidOwner.Bid;
            }
            if (spread > maximumSpread)
            {
                var previous  = active.Last.Value;
                var inventory = TryResumePausedInventory();
                if (inventory == null && inventories.Count < maxInventories)
                {
                    inventory = AddNewInventory();
                }
                if (inventory != null)
                {
                    ControlDirection(inventory, previous);
                    inventory.CalculateBidOffer(marketBid, marketOffer);
                    CompareBidOffer(inventory);
                }
            }
        }
Exemple #3
0
        public InventoryGroupMaster(SymbolInfo symbol)
        {
            this.symbol = symbol;
            var inventory = new InventoryGroupDefault(symbol, 1);

            active.AddLast(inventory);
            inventories.AddLast(inventory);
            ApplySettings();
            maximumSpread = 100 * symbol.MinimumTick;
        }
Exemple #4
0
        private InventoryGroupDefault AddNewInventory()
        {
            var id        = active.Count + 1;
            var inventory = new InventoryGroupDefault(symbol, id);

            active.AddLast(inventory);
            inventories.AddLast(inventory);
            ApplySettings();
            return(inventory);
        }
Exemple #5
0
        public void TestBreakEvenCalc()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, 1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(9, 666);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 9.6);
            inventory.Change(8, 555);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 9.2);
        }
Exemple #6
0
 private void CompareBidOffer(InventoryGroupDefault inventory)
 {
     if (inventory.Bid > bidOwner.Bid && inventory.BidSize > 0)
     {
         bidOwner = inventory;
     }
     if (inventory.Offer < offerOwner.Offer && inventory.OfferSize > 0)
     {
         offerOwner = inventory;
     }
 }
Exemple #7
0
        public void TestShortAddQuantity()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, -1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(11, -666);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 10.4);
            var howManyToAdd = inventory.QuantityToChange(13);

            Assert.AreEqual(-740, howManyToAdd);
            inventory.Change(13, howManyToAdd);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 11.2);
        }
Exemple #8
0
        public void TestLongAddQuantity()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, 1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(9, 666);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 9.6);
            var howManyToAdd = inventory.QuantityToChange(7);

            Assert.AreEqual(740, howManyToAdd);
            inventory.Change(7, howManyToAdd);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 8.8);
        }
Exemple #9
0
        public void TestLongAddPrice()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, 1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(9, 666);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 9.6);
            var howManyToAdd = 740;
            var priceToAdd   = inventory.PriceToChange(howManyToAdd, inventory.BreakEven);

            Assert.AreEqual(7, Math.Round(priceToAdd));
            inventory.Change(7, howManyToAdd);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 8.8);
        }
Exemple #10
0
        public void TestShortAddPrice()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, -1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(11, -666);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 10.4);
            var howManyToAdd = -740;
            var priceToAdd   = inventory.PriceToChange(howManyToAdd, inventory.BreakEven);

            Assert.AreEqual(13, Math.Round(priceToAdd));
            inventory.Change(13, howManyToAdd);
            Assert.AreEqual(Math.Round(inventory.BreakEven, 2), 11.2);
        }
Exemple #11
0
        public void TestShortClose()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, -1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(11, -666);
            Assert.AreEqual(10.4, Math.Round(inventory.BreakEven, 2));
            inventory.Change(12, -555);
            Assert.AreEqual(10.8, Math.Round(inventory.BreakEven, 2));
            double price = 15D;

            price = inventory.PriceToClose();
            var howManyToClose = inventory.Size;

            Assert.AreEqual(10.6, Round(price));
            Assert.AreEqual(-2221, howManyToClose);
        }
Exemple #12
0
        public void TestLongClose()
        {
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Change(10, 1000);
            Assert.AreEqual(inventory.BreakEven, 10);
            inventory.Change(9, 666);
            Assert.AreEqual(9.6, Math.Round(inventory.BreakEven, 2), "break even 1");
            inventory.Change(8, 555);
            Assert.AreEqual(9.2, Math.Round(inventory.BreakEven, 2), "break even 2");
            var price = 6D;

            inventory.CalculateBidOffer(price, price);
            price = inventory.PriceToClose();
            int howManyToClose = inventory.Size;

            Assert.AreEqual(Math.Round(9.4, 2), Math.Round(price, 2), "close price");
            Assert.AreEqual(2221, howManyToClose, "close size");
        }
Exemple #13
0
        private void ControlDirection(InventoryGroupDefault inventory, InventoryGroupDefault last)
        {
            switch (last.Status)
            {
            case InventoryStatus.Flat:
                inventory.Type = InventoryType.Either;
                break;

            case InventoryStatus.Long:
                inventory.Type = InventoryType.Short;
                break;

            case InventoryStatus.Short:
                inventory.Type = InventoryType.Long;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unexpected inventory status: " + last.Status);
            }
        }
Exemple #14
0
        public void TestLongBidOffer()
        {
            symbol = Factory.Symbol.LookupSymbol("EUR/USD");
            var inventory = new InventoryGroupDefault(symbol);

            inventory.Retrace        = .60;
            inventory.RoundLotSize   = 1000;
            inventory.MaximumLotSize = 1000;
            inventory.MinimumLotSize = 1000;
            inventory.Goal           = 5000;
            //Console.WriteLine("Price,Quantity,Cumulative,BreakEven,PandL");
            var first = true;
            var sb    = new StringBuilder();

            for (var price = 1.7000D; price > 1.4000; price -= 10 * symbol.MinimumTick)
            {
                var amountToBid = 0;
                inventory.CalculateBidOffer(price, price);
                amountToBid = inventory.BidSize;
                inventory.Change(price, amountToBid);
                var pandl = inventory.CurrentProfitLoss(price);
                sb.AppendLine(Round(price) + "," + amountToBid + "," + inventory.Size + "," + Round(inventory.BreakEven) + "," + Round(pandl));
            }
        }