Example #1
0
        public List <DateDelta> MonthlyDeltas()
        {
            List <DateDelta> monthlyDeltas = new List <DateDelta>();

            // if no records, return empty list
            if ((m_recs == null) || (m_recs.Count == 0))
            {
                return(monthlyDeltas);
            }


            BenchmarkIndexFileRecord monthBeginRec = m_recs[0];
            BenchmarkIndexFileRecord currRec       = m_recs[0];

            monthlyDeltas.Add(new DateDelta(monthBeginRec.Date));
            monthlyDeltas[monthlyDeltas.Count - 1].Delta = 0;

            for (int i = 0; i < m_recs.Count; i++)
            {
                // new month
                if ((m_recs[i].Date.Month != monthBeginRec.Date.Month) ||
                    (m_recs[i].Date.Year != monthBeginRec.Date.Year))
                {
                    monthBeginRec = m_recs[i];
                    monthlyDeltas.Add(new DateDelta(monthBeginRec.Date));
                }

                // calculate current delta
                currRec = m_recs[i];
                decimal diff  = currRec.AdjustedClose - monthBeginRec.AdjustedClose;
                decimal delta = diff / monthBeginRec.AdjustedClose;

                monthlyDeltas[monthlyDeltas.Count - 1].Date  = currRec.Date;
                monthlyDeltas[monthlyDeltas.Count - 1].Delta = delta;
            }

            return(monthlyDeltas);
        }
Example #2
0
        public List <BenchmarkIndexFileRecord> Records()
        {
            // return list to be used outside of this class
            // ? save m_recs at end of proc
            // ? so we can compare?
            List <BenchmarkIndexFileRecord> recs = new List <BenchmarkIndexFileRecord>();

            string line;

            string[] fields = null;
            string   field  = string.Empty;

            for (int i = 1; i < m_lines.Length; i++)
            {
                line = m_lines[i];

                // skip blank lines
                if (line.Trim().Length == 0)
                {
                    continue;
                }

                fields = line.Split(',');

                // create new record object
                BenchmarkIndexFileRecord rec = new BenchmarkIndexFileRecord();

                field    = fields[Date_Idx];
                field    = field.Replace("\"", "");
                rec.Date = DateTime.Parse(field);

                field    = fields[Open_Idx];
                field    = field.Replace("\"", "");
                rec.Open = Decimal.Parse(field);

                field    = fields[High_Idx];
                field    = field.Replace("\"", "");
                rec.High = Decimal.Parse(field);

                field   = fields[Low_Idx];
                field   = field.Replace("\"", "");
                rec.Low = Decimal.Parse(field);

                field     = fields[Close_Idx];
                field     = field.Replace("\"", "");
                rec.Close = Decimal.Parse(field);

                field      = fields[Volume_Idx];
                field      = field.Replace(".0", "");
                field      = field.Replace("\"", "");
                rec.Volume = Int64.Parse(field);

                field             = fields[AdjustedClose_Idx];
                field             = field.Replace("\"", "");
                rec.AdjustedClose = Decimal.Parse(field);

                /*
                 * field = fields[StDt1_Idx];
                 * field = field.Replace("\"", "");
                 * if (field.Trim() != String.Empty)
                 *  rec.StDt1 = DateTime.Parse(field);
                 */

                recs.Add(rec);
            }

            m_recs = recs;
            return(recs);
        }