private QCAlgorithm GetAlgorithm(IOrderProcessor orderProcessor) { var algorithm = new FakeAlgorithm(); algorithm.SetFinishedWarmingUp(); algorithm.Transactions.SetOrderProcessor(orderProcessor); return(algorithm); }
public void ClearRemovesUnreachedTarget() { var algorithm = new FakeAlgorithm(); algorithm.SetFinishedWarmingUp(); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); var dummySecurityHolding = new FakeSecurityHolding(equity); equity.Holdings = dummySecurityHolding; var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, -1); collection.Add(target); collection.Clear(); Assert.AreEqual(collection.Count, 0); }
public void OrderByMarginImpactDoesNotReturnTargetsWithNoData() { var algorithm = new FakeAlgorithm(); algorithm.SetFinishedWarmingUp(); algorithm.Transactions.SetOrderProcessor(new FakeOrderProcessor()); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); algorithm.AddEquity(symbol); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, -1); collection.Add(target); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(targets.IsNullOrEmpty()); }
public void OrderByMarginImpactDoesNotReturnTargetsForWhichUnorderedQuantityIsZeroBecauseTargetIsZero() { var algorithm = new FakeAlgorithm(); algorithm.SetFinishedWarmingUp(); algorithm.Transactions.SetOrderProcessor(new FakeOrderProcessor()); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); equity.Cache.AddData(new TradeBar(DateTime.UtcNow, symbol, 1, 1, 1, 1, 1)); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, 0); collection.Add(target); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(targets.IsNullOrEmpty()); }
public void OrderByMarginImpactReturnsExpectedTargets() { var algorithm = new FakeAlgorithm(); algorithm.SetFinishedWarmingUp(); algorithm.Transactions.SetOrderProcessor(new FakeOrderProcessor()); var symbol = new Symbol(SecurityIdentifier.GenerateEquity(_symbol, Market.USA), _symbol); var equity = algorithm.AddEquity(symbol); equity.Cache.AddData(new TradeBar(DateTime.UtcNow, symbol, 1, 1, 1, 1, 1)); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, -1); collection.Add(target); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.AreEqual(targets.Count(), 1); Assert.AreEqual(targets.First(), target); }