public void WhenNoRulesReturnNull() { var rules = new StopRulesCollection(); var rule = rules.RuleForPercentage(0); Assert.Null(rule); }
public void RulesSortedCorrectly() { // Arrange var b = new StopRulesCollection { new StopLossRule { LowerProfitPercentage = 10, UpperProfitPercentage = 20 }, new StopLossRule { LowerProfitPercentage = 1, UpperProfitPercentage = 2 } }; // Act b.Sort(new StopLossRuleComparer()); // Assert Assert.Equal(1, b[0].LowerProfitPercentage); Assert.Equal(20, b[1].UpperProfitPercentage); }
public void ForSingleRuleOnEdgeOfRangeReturnRule(double value) { var rules = new StopRulesCollection { new StopLossRule { LowerProfitPercentage = 1, UpperProfitPercentage = 10 } }; var rule = rules.RuleForPercentage(value); Assert.NotNull(rule); }
public void WhenGreaterThanMaxReturnLastRule() { var rules = new StopRulesCollection { new StopLossRule { LowerProfitPercentage = 1, UpperProfitPercentage = 10 } }; var rule = rules.RuleForPercentage(20); Assert.NotNull(rule); }
public void WhenOutOfRangeReturnNull() { var rules = new StopRulesCollection { new StopLossRule { LowerProfitPercentage = 1, UpperProfitPercentage = 10 } }; var rule = rules.RuleForPercentage(0); Assert.Null(rule); }
public void ForMultipleRulesWhenGreaterThanMaxReturnLastRule() { var rules = new StopRulesCollection { new StopLossRule { LowerProfitPercentage = 1, UpperProfitPercentage = 10, StopType = StopTypeValue.Trailing }, new StopLossRule { LowerProfitPercentage = 10, UpperProfitPercentage = 20, StopType = StopTypeValue.Smart } }; var rule = rules.RuleForPercentage(30); Assert.Equal(StopTypeValue.Smart, rule.StopType); }
public void ForMultipleRulesOnEdgeOfRangeReturnFirstRule() { var rules = new StopRulesCollection { new StopLossRule { LowerProfitPercentage = 1, UpperProfitPercentage = 10, StopType = StopTypeValue.Trailing }, new StopLossRule { LowerProfitPercentage = 10, UpperProfitPercentage = 13, StopType = StopTypeValue.Floating } }; var rule = rules.RuleForPercentage(10); Assert.Equal(StopTypeValue.Trailing, rule.StopType); }
public void WhenZeroProfitTrailingStopUsed(double profitPercentage) { const double EntryPrice = 10; const double Percentage = 6.5; var calculator = new Calculator(); var currentPrice = EntryPrice * (1 + profitPercentage / 100); var rules = new StopRulesCollection { new StopLossRule { StopType = StopTypeValue.Trailing, LowerProfitPercentage = 0, UpperProfitPercentage = 10, Percentage = Percentage } }; var result = calculator.CalculateStopLoss(EntryPrice, currentPrice, rules); Assert.Equal("TRAIL", result.OrderType); Assert.Equal(Percentage, result.StopPrice.TrailingPercent); }