public void VerifyMarginCallOrderShort()
        {
            var netLiquidationValue = 5000m;
            var totalMargin         = 10000m;
            var securityPrice       = 100m;
            var quantity            = -300;

            var orderProcessor = new MarginCallModelTests.OrderProcessor();
            var portfolio      = GetPortfolio(orderProcessor, quantity);
            var model          = new PatternDayTradingMarginBuyingPowerModel();

            // Open Market
            var security = CreateSecurity(Noon);

            security.Holdings.SetHoldings(securityPrice, quantity);

            var expected = (int)(Math.Round((totalMargin - netLiquidationValue) / securityPrice, MidpointRounding.AwayFromZero) * 4m);
            var actual   = portfolio.MarginCallModel.GenerateMarginCallOrder(security, netLiquidationValue, totalMargin, model.GetMaintenanceMarginRequirement(security)).Quantity;

            Assert.AreEqual(expected, actual);

            // Closed Market
            security = CreateSecurity(Midnight);
            security.Holdings.SetHoldings(securityPrice, quantity);

            expected = (int)(Math.Round((totalMargin - netLiquidationValue) / securityPrice, MidpointRounding.AwayFromZero) * 2m);
            actual   = portfolio.MarginCallModel.GenerateMarginCallOrder(security, netLiquidationValue, totalMargin, model.GetMaintenanceMarginRequirement(security)).Quantity;

            Assert.AreEqual(expected, actual);
        }
        public void InitializationTests()
        {
            // No parameters initialization, used default PDT 4x leverage open market and 2x leverage otherwise
            var model    = new PatternDayTradingMarginBuyingPowerModel();
            var leverage = model.GetLeverage(CreateSecurity(Noon));

            Assert.AreEqual(4.0m, leverage);

            model    = new PatternDayTradingMarginBuyingPowerModel(2.0m, 5.0m);
            leverage = model.GetLeverage(CreateSecurity(Noon));

            Assert.AreEqual(5.0m, leverage);
        }
        public void SetLeverageTest()
        {
            var model = new PatternDayTradingMarginBuyingPowerModel();

            // Open market
            var security = CreateSecurity(Noon);

            security.BuyingPowerModel = new PatternDayTradingMarginBuyingPowerModel();

            model.SetLeverage(security, 10m);
            Assert.AreNotEqual(10m, model.GetLeverage(security));

            // Closed market
            security = CreateSecurity(Midnight);

            model.SetLeverage(security, 10m);
            Assert.AreNotEqual(10m, model.GetLeverage(security));

            security.Holdings.SetHoldings(100m, 100);
        }