public void DoExperiment() { DateTimeUTC week_start = new DateTimeUTC(2007, 1, 1); List <ForexFactoryEvent> all_event_list = new List <ForexFactoryEvent>(); while (week_start < DateTimeUTC.Now) { Console.WriteLine(week_start); all_event_list.AddRange(ToolsForexFactory.GetForexFactoryEvents(week_start)); week_start = week_start.AddDays(7); Thread.Sleep(1000); } string[,] table = new string[all_event_list.Count, 9]; for (int index = 0; index < all_event_list.Count; index++) { table[index, 0] = all_event_list[index].WeekStartDay.ToString(); table[index, 1] = all_event_list[index].DateString; table[index, 2] = all_event_list[index].TimeString; table[index, 3] = all_event_list[index].Symbol; table[index, 4] = all_event_list[index].Impact; table[index, 5] = all_event_list[index].Description; table[index, 6] = all_event_list[index].Actual; table[index, 7] = all_event_list[index].Forecast; table[index, 8] = all_event_list[index].Previous; } ToolsIOCSV.WriteCSVFile(@"D:\GoogleDrive\TestData\Trading\events.csv", table, Delimiter.SemiColon); }
private static void CreateEventCSV() { // read CSV string[,] source = ToolsIOCSV.ReadCSVFile(ToolsTradingDataSet.GetPath() + "events.csv", Delimiter.SemiColon); //Allocate new array List <string[]> result_list = new List <string[]>(); string[] exclusion = new string[] { "day", "Day", "Data" }; //For each other column for (int index_0 = 0; index_0 < source.GetLength(0); index_0++) { if (!ExtensionsString.ContainsAny(source[index_0, 2], exclusion)) { string[] result = new string[3]; // Date symbol impact //Find dat DateTime week_start = DateTime.Parse(source[index_0, 0]); int year = week_start.Year; int month = ToolsForexFactory.MonthToInt(source[index_0, 1].Split(' ')[0]); int day = int.Parse(source[index_0, 1].Split(' ')[1]); if ((week_start.Month == 12) && (month == 1)) { year++; } int hour = int.Parse(source[index_0, 2].Split(':')[0]); int minute = int.Parse(source[index_0, 2].Split(':')[1].Substring(0, 2)); if (source[index_0, 2].Contains("pm")) { hour = hour + 12; } if (hour == 24) { hour = 0; DateTime date_time = new DateTime(year, month, day, hour, minute, 0); date_time = date_time.AddDays(1); result[0] = ToolsTime.DateTimeToUnixTimestampInt32(date_time).ToString(); } else { DateTime date_time = new DateTime(year, month, day, hour, minute, 0); result[0] = ToolsTime.DateTimeToUnixTimestampInt32(date_time).ToString(); } result[1] = source[index_0, 3]; switch (source[index_0, 4]) { case "Non-Economic": result[2] = "0"; // Impacs break; case "Low Impact Expected": result[2] = "1"; // Impacs break; case "Medium Impact Expected": result[2] = "2"; // Impacs break; case "High Impact Expected": result[2] = "3"; // Impacs break; default: throw new Exception("Unknown impact"); } result_list.Add(result); } } ToolsIOCSV.WriteCSVFile(ToolsTradingDataSet.GetPath() + "events_small.csv", ToolsCollection.ConvertToArray2D(result_list)); }