public void Are_Macd_indicator_properties_correct()
        {
            const IndicatorType type = IndicatorType.Macd;

            _factory.Setup(f => f.CreateIndicator(type)).Returns(new MacdIndicator());
            var properties = _service.GetPropertiesForIndicator(type);

            properties.Count.Should().Be(3);
            properties.Should().Contain(p => p.Name == "LongTerm" && p.Value == MacdIndicator.DefaultLongTerm);
            properties.Should().Contain(p => p.Name == "ShortTerm" && p.Value == MacdIndicator.DefaultShortTerm);
            properties.Should().Contain(p => p.Name == "SignalTerm" && p.Value == MacdIndicator.DefaultSignalTerm);
        }
        private void AddIndicator(ParameterizedIndicator indicator, InvestmentStrategy investmentStrategy)
        {
            if (!indicator.IndicatorType.HasValue)
            {
                throw new BusinessException("Wrong indicator value");
            }

            var strategyIndicator = new StrategyIndicator
            {
                IndicatorType = (int)indicator.IndicatorType.Value,
                Strategy      = investmentStrategy,
                Properties    = new List <StrategyIndicatorProperty>()
            };

            foreach (var indicatorProperty in indicator.Properties)
            {
                if (
                    _indicatorsService.GetPropertiesForIndicator(indicator.IndicatorType.Value)
                    .All(item => item.Name != indicatorProperty.Name))
                {
                    continue;
                }
                strategyIndicator.Properties.Add(new StrategyIndicatorProperty
                {
                    Indicator = strategyIndicator,
                    Name      = indicatorProperty.Name,
                    Value     = indicatorProperty.Value
                });
            }
            investmentStrategy.Indicators.Add(strategyIndicator);
        }
        private async Task <EditStrategyViewModel> GetViewModel(int?id)
        {
            var model = new EditStrategyViewModel
            {
                Indicators = _indicatorsService.GetIndicatorsAvailableForStrategies().Select(dto => new EditIndicatorViewModel()
                {
                    Name = dto.IndicatorName,
                    Type = dto.IndicatorType
                }).ToList(),
            };

            foreach (var indicator in model.Indicators)
            {
                var properties = _indicatorsService.GetPropertiesForIndicator(indicator.Type);
                indicator.Properties = properties.Select(p => new IndicatorPropertyViewModel {
                    Name = p.Name, Value = p.Value
                }).ToList();
                var description = _indicatorsService.GetIndicatorDescription(indicator.Type);
                indicator.BuySignalDescription  = description.BuySignalDescription;
                indicator.SellSignalDescription = description.SellSignalDescription;
            }
            if (id.HasValue)
            {
                model.Id = id;
                await FillIndicatorValues(id, model);
            }
            return(model);
        }
Exemple #4
0
        private async Task <ChartsIndexModel> BuildChartIndexModel()
        {
            var companies = await _companyService.GetCompanies();

            var groups = await _companyService.GetCompanyGroups();

            return(new ChartsIndexModel
            {
                Companies = companies,
                Indicators = _indicatorsService.GetAllIndicators()
                             .Select(i => new EditIndicatorViewModel
                {
                    Name = i.IndicatorName,
                    Type = i.IndicatorType,
                    Properties = _indicatorsService.GetPropertiesForIndicator(i.IndicatorType)
                                 .Select(p => new IndicatorPropertyViewModel {
                        Name = p.Name, Value = p.Value
                    }).ToList()
                }).ToList(),
                CompanyGroups = groups
            });
        }