예제 #1
0
        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);
        }
예제 #3
0
        public void ForSingleRuleOnEdgeOfRangeReturnRule(double value)
        {
            var rules = new StopRulesCollection
            {
                new StopLossRule
                {
                    LowerProfitPercentage = 1,
                    UpperProfitPercentage = 10
                }
            };
            var rule = rules.RuleForPercentage(value);

            Assert.NotNull(rule);
        }
예제 #4
0
        public void WhenGreaterThanMaxReturnLastRule()
        {
            var rules = new StopRulesCollection
            {
                new StopLossRule
                {
                    LowerProfitPercentage = 1,
                    UpperProfitPercentage = 10
                }
            };
            var rule = rules.RuleForPercentage(20);

            Assert.NotNull(rule);
        }
예제 #5
0
        public void WhenOutOfRangeReturnNull()
        {
            var rules = new StopRulesCollection
            {
                new StopLossRule
                {
                    LowerProfitPercentage = 1,
                    UpperProfitPercentage = 10
                }
            };
            var rule = rules.RuleForPercentage(0);

            Assert.Null(rule);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }