Beispiel #1
0
        public void Ctor_WithElements_ElementsAddedInOrder()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));

            Assert.That(series.First().Period, Is.EqualTo(new YearPeriod(2014)));
            Assert.That(series.Last().Period, Is.EqualTo(new YearPeriod(2015)));
        }
Beispiel #2
0
        public void Add_CurrencyUnexpected_Throws()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure));

            series.Add(FigureFactory.New(2015, 5, null));
            var ex = Assert.Throws <ArgumentException>(() => series.Add(FigureFactory.New(2014, 7, Dollar)));

            Assert.That(ex.Message, Does.Contain("Currency inconsistencies"));
        }
Beispiel #3
0
        public void Add_WithICurrencyFigure_CurrencyIsTakenOver()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure));

            series.Add(FigureFactory.New(2015, 5, Euro));
            series.Add(FigureFactory.New(2014, 7, Euro));

            Assert.That(series.Currency, Is.EqualTo(Euro));
        }
Beispiel #4
0
        public void Add_FigureTypeMismatch_Throws()
        {
            var series = new FigureSeries(typeof(FakeFigure));

            series.Add(FigureFactory.New(2015, 5));
            var ex = Assert.Throws <ArgumentException>(() => series.Add(FigureFactory.NewPrice("2013-11-11", 7, Dollar)));

            Assert.That(ex.Message, Does.Contain("FigureType mismatch"));
        }
        private void OnImport(FigureSeries series, bool withPreview)
        {
            var currentYear = DateTime.Now.Year;

            var request = DataProviderRequest.Create(Stock, series.FigureType, currentYear - 10, currentYear);

            request.WithPreview = withPreview;

            DataProvider.Fetch(request, series);
        }
Beispiel #6
0
        public sealed override object ProvideValue(IFigureProviderContext context)
        {
            var allLhs = context.GetSeries(myLhsSeriesName);

            if (!allLhs.Any())
            {
                return(new MissingData(myLhsSeriesName, FigureSeries.Empty));
            }

            var allRhs = context.GetSeries(myRhsSeriesName);

            if (!allRhs.Any())
            {
                return(new MissingData(myRhsSeriesName, FigureSeries.Empty));
            }

            EnsureCurrencyConsistancy(allLhs, allRhs);

            var resultSeries = new FigureSeries(typeof(DerivedFigure));

            foreach (var lhs in allLhs)
            {
                var rhs = allRhs.SingleOrDefault(e => e.Period.Equals(lhs.Period));

                if (rhs == null)
                {
                    continue;
                }

                var result = new DerivedFigure
                {
                    Value  = myJoinOperator(lhs.Value.Value, rhs.Value.Value),
                    Period = lhs.Period
                };

                if (PreserveCurrency)
                {
                    result.Currency = allLhs.Currency ?? allRhs.Currency;
                }

                result.Inputs.Add(lhs);
                result.Inputs.Add(rhs);

                resultSeries.Add(result);
            }

            return(resultSeries);
        }
Beispiel #7
0
        public void Ctor_WithElements_CurrencyIsTakenOver()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));

            Assert.That(series.Currency, Is.EqualTo(Euro));
        }
Beispiel #8
0
        public void Ctor_WhenCalled_NameIsSet()
        {
            var series = new FigureSeries(typeof(Equity));

            Assert.That(series.Name, Does.Contain("Equity"));
        }
Beispiel #9
0
        public void Ctor_WhenCalled_DataTypeSet()
        {
            var series = new FigureSeries(typeof(Equity));

            Assert.That(series.FigureType, Is.EqualTo(typeof(Equity)));
        }
        public void Initialize(Stock stock)
        {
            Stock = stock;

            myFigures = new List <IFigureSeries>();
            foreach (var figureType in Dynamics.AllFigures.Where(t => t != typeof(Price)))
            {
                myFigures.Add(Dynamics.GetSeries(stock, figureType, false));
            }

            // we might have prices of different currencies - do only add latest
            {
                var series = new FigureSeries(typeof(Price));
                series.EnableCurrencyCheck = false;

                var currentPrice = stock.Prices.OrderByDescending(p => p.Period).FirstOrDefault();
                if (currentPrice != null)
                {
                    series.Add(currentPrice);
                }

                myFigures.Add(series);
            }

            // data sanity - TODO: later move to creation of new DataSheet
            {
                var series = (FigureSeries)myFigures.SeriesOf(typeof(Price));
                if (series.Current <Price>() == null)
                {
                    series.Add(new Price());
                }
            }

            // defaultCurrency could be taken from any figure but Price
            Currency defaultCurrency = null;

            foreach (var type in Dynamics.AllFigures.Where(t => t != typeof(Price)))
            {
                var series = (FigureSeries)myFigures.SeriesOf(type);

                // TODO: today we only support yearly values here
                var currentYear   = DateTime.Now.Year;
                var existingYears = series
                                    .Select(v => ((YearPeriod)v.Period).Year)
                                    .ToList();

                if (defaultCurrency == null)
                {
                    defaultCurrency = series.Currency;
                }

                // select hard coded 11 years here as minimum to allow growth calc based on recent 10 years
                for (int i = currentYear - 10; i <= currentYear; ++i)
                {
                    if (!existingYears.Contains(i))
                    {
                        var figure = Dynamics.CreateFigure(Stock, type, new YearPeriod(i),
                                                           series.Currency != null ? series.Currency : defaultCurrency);
                        series.Add(figure);
                    }
                }
            }

            RaisePropertyChanged(nameof(Price));
            RaisePropertyChanged(nameof(DataSeries));
        }