public void FundsAreSettledInAccountCurrency()
        {
            var securities   = new SecurityManager(TimeKeeper);
            var transactions = new SecurityTransactionManager(null, securities);
            var portfolio    = new SecurityPortfolioManager(securities, transactions);
            var model        = new AccountCurrencyImmediateSettlementModel();

            portfolio.SetCash(1000);
            portfolio.SetCash("EUR", 0, 1.1m);

            var config   = CreateTradeBarConfig(Symbols.DE30EUR);
            var security = new Security(
                SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(),
                config,
                portfolio.CashBook["EUR"],
                SymbolProperties.GetDefault("EUR"),
                ErrorCurrencyConverter.Instance,
                RegisteredSecurityDataTypesProvider.Null,
                new SecurityCache()
                );

            Assert.AreEqual(1000, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);

            var timeUtc = Noon.ConvertToUtc(TimeZones.NewYork);

            model.ApplyFunds(portfolio, security, timeUtc, "EUR", 1000);

            // 1000 + 1000 * 1.1 = 2100
            Assert.AreEqual(2100, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);

            model.ApplyFunds(portfolio, security, timeUtc, "EUR", -500);

            // 2100 - 500 * 1.1 = 1550
            Assert.AreEqual(1550, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);

            model.ApplyFunds(portfolio, security, timeUtc, "EUR", 1000);

            // 1550 + 1000 * 1.1 = 2650
            Assert.AreEqual(2650, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);
        }
        public void FundsAreSettledImmediately()
        {
            var securities   = new SecurityManager(TimeKeeper);
            var transactions = new SecurityTransactionManager(null, securities);
            var portfolio    = new SecurityPortfolioManager(securities, transactions);
            var model        = new AccountCurrencyImmediateSettlementModel();
            var config       = CreateTradeBarConfig(Symbols.SPY);
            var security     = new Security(
                SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(),
                config,
                new Cash(Currencies.USD, 0, 1m),
                SymbolProperties.GetDefault(Currencies.USD),
                ErrorCurrencyConverter.Instance,
                RegisteredSecurityDataTypesProvider.Null,
                new SecurityCache()
                );

            portfolio.SetCash(1000);
            Assert.AreEqual(1000, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);

            var timeUtc = Noon.ConvertToUtc(TimeZones.NewYork);

            model.ApplyFunds(portfolio, security, timeUtc, Currencies.USD, 1000);

            Assert.AreEqual(2000, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);

            model.ApplyFunds(portfolio, security, timeUtc, Currencies.USD, -500);

            Assert.AreEqual(1500, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);

            model.ApplyFunds(portfolio, security, timeUtc, Currencies.USD, 1000);

            Assert.AreEqual(2500, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);
        }