public void FundsAreSettledImmediately()
        {
            var securities   = new SecurityManager(TimeKeeper);
            var transactions = new SecurityTransactionManager(securities);
            var portfolio    = new SecurityPortfolioManager(securities, transactions);
            var model        = new ImmediateSettlementModel();
            var config       = CreateTradeBarConfig(Symbol);
            var security     = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1);

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

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

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

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

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

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

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

            Assert.AreEqual(2500, portfolio.Cash);
            Assert.AreEqual(0, portfolio.UnsettledCash);
        }
Example #2
0
 /// <summary>
 /// Construct the Equity Object
 /// </summary>
 public Equity(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage)
     : base(exchangeHours, config, leverage)
 {
     //Holdings for new Vehicle:
     Cache      = new EquityCache();
     Exchange   = new EquityExchange(exchangeHours);
     DataFilter = new EquityDataFilter();
     //Set the Equity Transaction Model
     TransactionModel = new EquityTransactionModel();
     PortfolioModel   = new EquityPortfolioModel();
     MarginModel      = new EquityMarginModel(leverage);
     SettlementModel  = new ImmediateSettlementModel();
     Holdings         = new EquityHolding(this, TransactionModel, MarginModel);
 }
Example #3
0
 /// <summary>
 /// Construct the Equity Object
 /// </summary>
 public Equity(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage) 
     : base(exchangeHours, config, leverage) 
 {
     //Holdings for new Vehicle:
     Cache = new EquityCache();
     Exchange = new EquityExchange(exchangeHours);
     DataFilter = new EquityDataFilter();
     //Set the Equity Transaction Model
     TransactionModel = new EquityTransactionModel();
     PortfolioModel = new EquityPortfolioModel();
     MarginModel = new EquityMarginModel(leverage);
     SettlementModel = new ImmediateSettlementModel();
     Holdings = new EquityHolding(this, TransactionModel, MarginModel);
 }
Example #4
0
File: Forex.cs Project: skyfyl/Lean
        /// <summary>
        /// Constructor for the forex security
        /// </summary>
        /// <param name="exchangeHours">Defines the hours this exchange is open</param>
        /// <param name="quoteCurrency">The cash object that represent the quote currency</param>
        /// <param name="config">The subscription configuration for this security</param>
        /// <param name="leverage">The leverage used for this security</param>
        public Forex(SecurityExchangeHours exchangeHours, Cash quoteCurrency, SubscriptionDataConfig config, decimal leverage)
            : base(exchangeHours, config, leverage)
        {
            QuoteCurrency = quoteCurrency;
            //Holdings for new Vehicle:
            Cache = new ForexCache();
            Exchange = new ForexExchange(exchangeHours); 
            DataFilter = new ForexDataFilter();
            TransactionModel = new ForexTransactionModel();
            PortfolioModel = new ForexPortfolioModel();
            MarginModel = new ForexMarginModel(leverage);
            SettlementModel = new ImmediateSettlementModel();
            Holdings = new ForexHolding(this);

            // decompose the symbol into each currency pair
            string baseCurrencySymbol, quoteCurrencySymbol;
            DecomposeCurrencyPair(config.Symbol.Value, out baseCurrencySymbol, out quoteCurrencySymbol);
            BaseCurrencySymbol = baseCurrencySymbol;
            QuoteCurrencySymbol = quoteCurrencySymbol;
        }
Example #5
0
        /// <summary>
        /// Constructor for the forex security
        /// </summary>
        /// <param name="exchangeHours">Defines the hours this exchange is open</param>
        /// <param name="quoteCurrency">The cash object that represent the quote currency</param>
        /// <param name="config">The subscription configuration for this security</param>
        /// <param name="leverage">The leverage used for this security</param>
        public Forex(SecurityExchangeHours exchangeHours, Cash quoteCurrency, SubscriptionDataConfig config, decimal leverage)
            : base(exchangeHours, config, leverage)
        {
            QuoteCurrency = quoteCurrency;
            //Holdings for new Vehicle:
            Cache            = new ForexCache();
            Exchange         = new ForexExchange(exchangeHours);
            DataFilter       = new ForexDataFilter();
            TransactionModel = new ForexTransactionModel();
            PortfolioModel   = new ForexPortfolioModel();
            MarginModel      = new ForexMarginModel(leverage);
            SettlementModel  = new ImmediateSettlementModel();
            Holdings         = new ForexHolding(this);

            // decompose the symbol into each currency pair
            string baseCurrencySymbol, quoteCurrencySymbol;

            DecomposeCurrencyPair(config.Symbol.Value, out baseCurrencySymbol, out quoteCurrencySymbol);
            BaseCurrencySymbol  = baseCurrencySymbol;
            QuoteCurrencySymbol = quoteCurrencySymbol;
        }
Example #6
0
        public void FundsAreSettledImmediately()
        {
            var securities   = new SecurityManager(TimeKeeper);
            var transactions = new SecurityTransactionManager(null, securities);
            var portfolio    = new SecurityPortfolioManager(securities, transactions);
            var model        = new ImmediateSettlementModel();
            var config       = CreateTradeBarConfig();
            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);
        }