public void OrderByMarginImpactDoesNotReturnTargetsForWhichUnorderedQuantityIsZeroBecauseOpenOrder() { var algorithm = new FakeAlgorithm(); var orderProcessor = new FakeOrderProcessor(); algorithm.Transactions.SetOrderProcessor(orderProcessor); 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 openOrderRequest = new SubmitOrderRequest(OrderType.Market, symbol.SecurityType, symbol, 1, 0, 0, DateTime.UtcNow, ""); openOrderRequest.SetOrderId(1); var openOrderTicket = new OrderTicket(algorithm.Transactions, openOrderRequest); orderProcessor.AddOrder(new MarketOrder(symbol, 1, DateTime.UtcNow)); orderProcessor.AddTicket(openOrderTicket); var targets = collection.OrderByMarginImpact(algorithm); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(targets.IsNullOrEmpty()); }
/// <summary> /// Initializes a new instance of the <see cref="MaximumSectorExposureRiskManagementModel"/> class /// </summary> /// <param name="maximumSectorExposure">The maximum exposure for any sector, defaults to 20% sector exposure.</param> public MaximumSectorExposureRiskManagementModel( decimal maximumSectorExposure = 0.20m ) { _maximumSectorExposure = Math.Abs(maximumSectorExposure); _targetsCollection = new PortfolioTargetCollection(); }
/// <summary> /// Initializes a new instance of the <see cref="StandardDeviationExecutionModel"/> class /// </summary> /// <param name="period">Period of the standard deviation indicator</param> /// <param name="deviations">The number of deviations away from the mean before submitting an order</param> /// <param name="resolution">The resolution of the STD and SMA indicators</param> public StandardDeviationExecutionModel( int period = 60, decimal deviations = 2m, Resolution resolution = Resolution.Minute ) { _period = period; _deviations = deviations; _resolution = resolution; _targetsCollection = new PortfolioTargetCollection(); _symbolData = new Dictionary <Symbol, SymbolData>(); }
public void AddContainsAndRemoveWork() { var symbol = new Symbol(SecurityIdentifier.GenerateBase(_symbol, Market.USA), _symbol); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, 1); collection.Add(target); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(collection.Contains(target)); Assert.IsTrue(collection.Remove(target)); Assert.AreEqual(collection.Count, 0); }
/// <summary> /// Initializes a new instance of the <see cref="MaximumSectorExposureRiskManagementModel"/> class /// </summary> /// <param name="maximumSectorExposure">The maximum exposure for any sector, defaults to 20% sector exposure.</param> public MaximumSectorExposureRiskManagementModel( decimal maximumSectorExposure = 0.20m ) { if (maximumSectorExposure <= 0) { throw new ArgumentOutOfRangeException("MaximumSectorExposureRiskManagementModel: the maximum sector exposure cannot be a non-positive value."); } _maximumSectorExposure = maximumSectorExposure; _targetsCollection = new PortfolioTargetCollection(); }
public void ClearRemovesUnreachedTarget() { var algorithm = new FakeAlgorithm(); 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(); 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 OrderByMarginImpactDoesNotReturnTargetsForWhichUnorderdQuantityIsZeroBecauseTargetIsZero() { var algorithm = new FakeAlgorithm(); 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 ClearFulfilledRemovesPositiveTarget() { 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); dummySecurityHolding.SetQuantity(1); collection.ClearFulfilled(algorithm); Assert.AreEqual(collection.Count, 0); }
public void OrderByMarginImpactReturnsExpectedTargets() { var algorithm = new FakeAlgorithm(); 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); }
/// <summary> /// Initializes a new instance of the <see cref="SpreadExecutionModel"/> class /// </summary> /// <param name="acceptingSpreadPercent">Maximum spread accepted comparing to current price in percentage.</param> public SpreadExecutionModel(decimal acceptingSpreadPercent = 0.005m) { _acceptingSpreadPercent = Math.Abs(acceptingSpreadPercent); _targetsCollection = new PortfolioTargetCollection(); }