/// <summary>Serves as the default hash function. </summary> /// <returns>A hash code for the current object.</returns> public override int GetHashCode() { unchecked { return((BuyingPowerModel.GetHashCode() * 397) ^ UnitQuantities.GetListHashCode()); } }
[TestCase(-40.5, 12.5, 1508, .5, 161)] // -506.25 public void OrderCalculation(decimal currentHoldings, decimal perUnitMargin, decimal targetMargin, decimal lotSize, decimal expectedOrderSize) { var currentHoldingsMargin = currentHoldings * perUnitMargin; // Determine the order size to get us to our target margin var orderSize = BuyingPowerModel.GetAmountToOrder(currentHoldingsMargin, targetMargin, perUnitMargin, lotSize); Assert.AreEqual(expectedOrderSize, orderSize); // Determine the final margin and assert we have met our target condition var resultMargin = currentHoldingsMargin + (orderSize * perUnitMargin); Assert.IsTrue(Math.Abs(resultMargin) <= Math.Abs(targetMargin)); }
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary> /// <param name="other">An object to compare with this object.</param> /// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns> public bool Equals(PositionGroupKey other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(BuyingPowerModel.Equals(other.BuyingPowerModel) && UnitQuantities.ListEquals(other.UnitQuantities)); }
[TestCase(-40.5, 12.5, 1508, .5, 120.5)] // -506.25 public void OrderAdjustmentCalculation(decimal currentOrderSize, decimal perUnitMargin, decimal targetMargin, decimal lotSize, decimal expectedOrderSize) { var currentOrderMargin = currentOrderSize * perUnitMargin; // Determine the adjustment to get us to our target margin and apply it // Use our GetAmountToOrder for determining adjustment to reach the end goal var orderAdjustment = BuyingPowerModel.GetAmountToOrder(currentOrderMargin, targetMargin, perUnitMargin, lotSize); // Apply the change in margin var resultMargin = currentOrderMargin + (orderAdjustment * perUnitMargin); // Assert after our adjustment we have met our target condition Assert.IsTrue(Math.Abs(resultMargin) <= Math.Abs(targetMargin)); // Verify our adjustment meets our expected order size var adjustOrderSize = currentOrderSize + orderAdjustment; Assert.AreEqual(expectedOrderSize, adjustOrderSize); }
public void Setup() { _model = new BuyingPowerModel(); }