/// <summary>
        /// Gets all Periods.
        /// </summary>
        /// <returns></returns>
        public static Period GetAllPeriods()
        {
            BLL.Period period = new Period();
            period.LoadAll();

            period.AddColumn("StartDate_EndDate",typeof(string));
            DataRow[] dataRows = period.DataTable.Select();
            foreach (DataRow r in dataRows)
            {
                r["StartDate_EndDate"] = Convert.ToDateTime(r["StartDate"]).ToString("MMMM,dd,yyyy") + " - " + Convert.ToDateTime(r["EndDate"]).ToString("MMMM,dd,yyyy");
            }
            return period;
        }
        public string GetReport(Portfolio portfolio, DateTime start, DateTime end, Period period)
        {
            var reportBuilder = new StringBuilder();
            var prices = GetPrices(portfolio, start, end, period);
            var values = GetValues(portfolio, prices);
            var columnOrder = values.Keys.OrderBy(d => d.Date);

            // print header
            reportBuilder.Append("\t\t");
            foreach (var date in columnOrder)
            {
                reportBuilder.AppendFormat("| {0} ", date.ToString("d"));
            }
            reportBuilder.AppendLine();
            reportBuilder.Append("----------------");
            for (var i = 0; i < columnOrder.Count(); ++i)
                reportBuilder.Append("-------------");
            reportBuilder.AppendLine();

            foreach (var account in portfolio.Accounts)
            {
                reportBuilder.AppendLine(string.Format("{0,-16}", account.Name));
                foreach (var position in account.Positions)
                {
                    reportBuilder.AppendFormat("{0,-16}", position.Security.Symbol);
                    foreach (var date in columnOrder)
                    {
                        var rowValues = values[date];
                        var value = rowValues[position];
                        if (value < 0M)
                            reportBuilder.AppendFormat("| {0,10} ", " !*v*! ");
                        else
                            reportBuilder.AppendFormat("| {0,10} ", value.ToString("##.00"));
                    }
                    reportBuilder.AppendLine();
                }
            }

            return reportBuilder.ToString();
        }
 private IDictionary<DateTime, IDictionary<string, decimal>> GetPrices(Portfolio portfolio, DateTime start, DateTime end, Period period)
 {
     var securities = new List<Security>();
     foreach (var account in portfolio.Accounts)
     {
         securities.AddRange(account.Positions.Select(p => p.Security));
     }
     return _historicalPricer.GetHistoricalPrices(securities.Distinct(), start, end, period);
 }