Пример #1
0
        private static void GetStartStop(string line, RunStats runstats)
        {
            int    r     = line.IndexOf("Start: ", StringComparison.Ordinal) + @"Start: ".Length;
            int    t     = line.IndexOf("Stop:", StringComparison.Ordinal);
            string start = line.Substring(r, t - r).Trim();

            runstats.Start = Convert.ToDateTime(start);
            string stop = line.Substring(t + @"Stop: ".Length);

            runstats.Stop = Convert.ToDateTime(stop);
        }
Пример #2
0
 public static int CompareEndingPortfolioValue(RunStats r1, RunStats r2)
 {
     return r1.EndingPortfolioValue.CompareTo(r2.EndingPortfolioValue) * -1;
 }
Пример #3
0
 public static int CompareCompoundingAnnualReturn(RunStats r1, RunStats r2)
 {
     return r1.CompoundingAnnualReturn.CompareTo(r2.CompoundingAnnualReturn) * -1;
 }
Пример #4
0
        private static void SetPropertyValue(PropertyInfo[] properties, string propname, decimal propval, ref RunStats runstats)
        {
            PropertyInfo p = properties.First(n => n.Name == propname);

            try
            {
                var setmethod = p.SetMethod;
                if (setmethod != null)
                {
                    p.SetValue(runstats, propval);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Пример #5
0
        public List <RunStats> ParseFile(string filepath)
        {
            var runstats = new RunStats();

            PropertyInfo[] properties  = typeof(RunStats).GetProperties();
            var            runstatlist = new List <RunStats>();

            using (var sr = new StreamReader(filepath))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line.Contains("Start Time: "))
                    {
                        runstats.StartTime = System.Convert.ToDateTime(line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim());
                    }
                    if (line.Contains("End Time: "))
                    {
                        runstats.EndTime = System.Convert.ToDateTime(line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim());
                    }
                    if (line.Contains("Begin DataStream"))
                    {
                        GetStartStop(line, runstats);
                    }
                    if (line.Contains("Algorithm Name:"))
                    {
                        runstats.AlgorithmName = line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim();
                    }
                    if (line.Contains("Symbol:"))
                    {
                        runstats.Symbol = line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim();
                    }
                    if (line.Contains("Ending Portfolio Value:"))
                    {
                        runstats.EndingPortfolioValue =
                            Convert.ToDecimal(line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim());
                    }
                    if (line.Contains("STATISTICS::"))
                    {
                        string[] arr      = line.Split(' ');
                        string   propname = string.Empty;

                        // get the name from the line by replacing spaces and -
                        for (int i = 3; i < arr.Length - 1; i++)
                        {
                            propname += arr[i].Trim().Replace("-", "");
                        }

                        // Get the value from the line and convert to decimal
                        decimal propval = PropertyValueFromString(arr[arr.Length - 1]);

                        // Set the property value in runstats
                        SetPropertyValue(properties, propname, propval, ref runstats);

                        //// Used for development for creating the class
                        //GeneratePropertyStringForClass(propname);
                    }
                    if (line.Contains("Total Fees"))
                    {
                        runstatlist.Add(runstats);
                        runstats = new RunStats();
                    }
                }
            }
            return(runstatlist);
        }
Пример #6
0
 public static int CompareEndingPortfolioValue(RunStats r1, RunStats r2)
 {
     return(r1.EndingPortfolioValue.CompareTo(r2.EndingPortfolioValue) * -1);
 }
Пример #7
0
 public static int CompareCompoundingAnnualReturn(RunStats r1, RunStats r2)
 {
     return(r1.CompoundingAnnualReturn.CompareTo(r2.CompoundingAnnualReturn) * -1);
 }
Пример #8
0
 private static void GetStartStop(string line, RunStats runstats)
 {
     int r = line.IndexOf("Start: ", StringComparison.Ordinal) + @"Start: ".Length;
     int t = line.IndexOf("Stop:", StringComparison.Ordinal);
     string start = line.Substring(r, t - r).Trim();
     runstats.Start = Convert.ToDateTime(start);
     string stop = line.Substring(t + @"Stop: ".Length);
     runstats.Stop = Convert.ToDateTime(stop);
 }
Пример #9
0
        public List<RunStats> ParseFile(string filepath)
        {
            var runstats = new RunStats();
            PropertyInfo[] properties = typeof(RunStats).GetProperties();
            var runstatlist = new List<RunStats>();

            using (var sr = new StreamReader(filepath))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line.Contains("Start Time: "))
                    {
                        runstats.StartTime = System.Convert.ToDateTime(line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim());
                    }
                    if (line.Contains("End Time: "))
                    {
                        runstats.EndTime = System.Convert.ToDateTime(line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim());
                    }
                    if (line.Contains("Begin DataStream"))
                    {
                        GetStartStop(line, runstats);
                    }
                    if (line.Contains("Algorithm Name:"))
                    {
                        runstats.AlgorithmName = line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim();
                    }
                    if (line.Contains("Symbol:"))
                    {
                        runstats.Symbol = line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim();
                    }
                    if (line.Contains("Ending Portfolio Value:"))
                    {
                        runstats.EndingPortfolioValue =
                            Convert.ToDecimal(line.Substring(line.IndexOf(@":", StringComparison.Ordinal) + 1).Trim());
                    }
                    if (line.Contains("STATISTICS::"))
                    {
                        string[] arr = line.Split(' ');
                        string propname = string.Empty;

                        // get the name from the line by replacing spaces and -
                        for (int i = 3; i < arr.Length - 1; i++)
                        {
                            propname += arr[i].Trim().Replace("-", "");
                        }

                        // Get the value from the line and convert to decimal
                        decimal propval = PropertyValueFromString(arr[arr.Length - 1]);

                        // Set the property value in runstats
                        SetPropertyValue(properties, propname, propval, ref runstats);

                        //// Used for development for creating the class
                        //GeneratePropertyStringForClass(propname);
                    }
                    if (line.Contains("Total Fees"))
                    {
                        runstatlist.Add(runstats);
                        runstats = new RunStats();
                    }
                }
            }
            return runstatlist;
        }
Пример #10
0
 private static void SetPropertyValue(PropertyInfo[] properties, string propname, decimal propval, ref RunStats runstats)
 {
     PropertyInfo p = properties.First(n => n.Name == propname);
     try
     {
         var setmethod = p.SetMethod;
         if (setmethod != null)
             p.SetValue(runstats, propval);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
     }
 }