예제 #1
0
        public object ProvideValue(IFigureProviderContext context)
        {
            var price = context.Data.SeriesOf(typeof(Price)).Current();

            if (price == null)
            {
                return(new MissingData("Price", null));
            }
            return(price);
        }
예제 #2
0
        public sealed override object ProvideValue(IFigureProviderContext context)
        {
            var price = ( Price )context.Data.SeriesOf(typeof(Price)).Current();

            if (price == null)
            {
                return(new MissingData("Price", null));
            }

            var values = context.GetSeries(mySeriesName);

            if (!values.Any())
            {
                return(new MissingData(mySeriesName, null));
            }

            Contract.Requires(price.Currency != null, "Currency missing at price");

            var priceValue = price.Value.Value;

            if (values.Currency != null && price.Currency != values.Currency)
            {
                priceValue = context.TranslateCurrency(price.Value.Value, price.Currency, values.Currency);
            }

            var priceYear = price.Period.Year();

            var value = values.SingleOrDefault(e => e.Period.Year() == priceYear);

            if (value == null)
            {
                value = values.SingleOrDefault(e => e.Period.Year() == priceYear - 1);
                if (value == null)
                {
                    return(new MissingDataForPeriod(mySeriesName, null, new YearPeriod(priceYear), new YearPeriod(priceYear - 1)));
                }
            }

            var result = new DerivedFigure
            {
                Period = price.Period,
                Value  = myRatioCalculationOperator(priceValue, value.Value.Value)
            };

            if (PreserveCurrency)
            {
                result.Currency = values.Currency != null ? values.Currency : price.Currency;
            }

            result.Inputs.Add(price);
            result.Inputs.Add(value);

            return(result);
        }
예제 #3
0
        public object ProvideValue(IFigureProviderContext context)
        {
            var series = context.Data.OfType <IFigureSeries>()
                         .Where(s => s.FigureType == myFigureType)
                         .SingleOrDefault();

            if (series == null)
            {
                return(new MissingData(Name, FigureSeries.Empty));
            }

            return(series);
        }
예제 #4
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);
        }
예제 #5
0
 public object ProvideValue(IFigureProviderContext context)
 {
     return(myProvideValueDelegate(context));
 }
예제 #6
0
 public abstract object ProvideValue(IFigureProviderContext context);
 public static IFigureSeries GetSeries <T>(this IFigureProviderContext self)
 {
     return(self.GetSeries(typeof(T).Name));
 }