Beispiel #1
0
        public void ShouldCalculateFromHundredFilesCorrectly()
        {
            var parameters     = new StringBuilder();
            var correctMargins = new decimal();

            for (var i = 0; i < 100; i++)
            {
                var inputValue = new InputValue
                {
                    OpenPrice    = 1,
                    ClosePrice   = 2,
                    Volume       = 3,
                    ContractSize = 4,
                    Leverage     = 5,
                    Commission   = 7,
                };
                correctMargins = (inputValue.Volume * inputValue.ContractSize / inputValue.Leverage);
                var tmpFilePath = InputValueSaver.SaveToTmpFile(inputValue);

                parameters.Append(tmpFilePath + " ");
            }


            var response = ResponseParser.Parse(new FileStarter().LaunchProcess("-f " + parameters));

            Assert.That(response.FirstOrDefault(o =>
                                                Math.Abs(o.Margin - correctMargins) > 0.0001M), Is.Null, "Error in group calculation (3)");
        }
Beispiel #2
0
        public void ShouldCalculateMarginCorrectly()
        {
            var inputValue = new InputValue
            {
                OpenPrice    = 1,
                ClosePrice   = 2,
                Volume       = 3,
                ContractSize = 4,
                Leverage     = 5,
                Commission   = 7,
            };
            var correctMargin = inputValue.Volume * inputValue.ContractSize / inputValue.Leverage;
            var tmpFilePath   = InputValueSaver.SaveToTmpFile(inputValue);

            var response = ResponseParser.Parse(new FileStarter().LaunchProcess("-f " + tmpFilePath));

            Assert.That(Math.Abs(response[0].Margin - correctMargin), Is.LessThan(0.0001M), "Wrong margin calculation");
        }
Beispiel #3
0
        public void ShouldCalculatePerTradeCommissionCorrectly()
        {
            var inputValue = new InputValue
            {
                OpenPrice      = 1,
                ClosePrice     = 2,
                Volume         = 3,
                ContractSize   = 4,
                Leverage       = 5,
                Commission     = 7,
                CommissionType = "PerTrade"
            };
            var correctCommission = inputValue.Commission * 1;
            var tmpFilePath       = InputValueSaver.SaveToTmpFile(inputValue);

            var response = ResponseParser.Parse(new FileStarter().LaunchProcess("-f " + tmpFilePath));

            Assert.That(Math.Abs(response[0].Commission - correctCommission), Is.LessThan(0.0001M), "Wrong Commission (PerTrade) calculation");
        }
Beispiel #4
0
        public void ShouldCalculateMarginCorrectlyAndRiseErrorForZeroInput()
        {
            var parameters = new StringBuilder();

            var correctValue = new InputValue
            {
                OpenPrice    = 1,
                ClosePrice   = 2,
                Volume       = 3,
                ContractSize = 4,
                Leverage     = 5,
                Commission   = 7,
            };
            var correctMargin = correctValue.Volume * correctValue.ContractSize / correctValue.Leverage;
            var tmpFilePath   = InputValueSaver.SaveToTmpFile(correctValue);

            parameters.Append(tmpFilePath + " ");

            var incorrectValue = new InputValue
            {
                OpenPrice    = 0,
                ClosePrice   = 9,
                Volume       = 9,
                ContractSize = 9,
                Leverage     = 9,
                Commission   = 9,
            };

            tmpFilePath = InputValueSaver.SaveToTmpFile(incorrectValue);
            parameters.Append(tmpFilePath + " ");

            var response = ResponseParser.Parse(new FileStarter().LaunchProcess("-f " + parameters));

            Assert.That(response.Count(o => o.Errors.Count == 1), Is.EqualTo(1));
            Assert.That(Math.Abs(response.FirstOrDefault(o => o.Errors.Count == 0).Margin - correctMargin),
                        Is.LessThan(0.0001M), "Wrong margin calculation");
        }