/// <summary>
        /// Validates the power trades for a day. Invalid trades cause an exception to be thrown.
        /// </summary>
        /// <param name="trades">The power trades for a day.</param>
        /// <returns>The power trades for a day.</returns>
        public static PowerTrades ValidateTrades(PowerTrades trades)
        {
            var settlementDay = Helpers.SettlementDay(trades.Day);

            if (trades.Trades.Any(t => t.Periods.Length != settlementDay.NumberOfPeriods))
            {
                throw new ArgumentException(string.Format("expected all power trades for {0} to have {1} periods", trades.Day, settlementDay.NumberOfPeriods), "trades");
            }
            return(trades);
        }
        /// <summary>
        /// Aggregates the power trades for a day into the position.
        /// </summary>
        /// <param name="trades">The power trades for a day.</param>
        /// <returns>The position.</returns>
        public static Position BuildPosition(PowerTrades trades)
        {
            var settlementDay = Helpers.SettlementDay(trades.Day);
            var seed          = PowerTrade.Create(trades.Day.DateTime, settlementDay.NumberOfPeriods);
            var periods       =
                trades.Trades.Select(t => t.Periods)
                .Aggregate(seed.Periods,
                           (periods1, periods2) =>
                           periods1.Zip(periods2,
                                        (period1, period2) => new PowerPeriod {
                Period = period1.Period, Volume = period1.Volume + period2.Volume
            })
                           .ToArray());

            return(new Position {
                Day = trades.Day, Periods = periods
            });
        }