Ejemplo n.º 1
0
 public void DoExperiment()
 {
     string [,] event_table = ToolsIOCSV.ReadCSVFile(@"D:\GoogleDrive\TestData\Trading\events.csv", Delimiter.SemiColon);
     //Load events
     //ToolsTradingCalendarEvent.GetTradingCalendarEvents(new string[] { "EUR", "USD" }, start_date, end_date);
     //Load candles
     ToolsPrice.GetPriceCandles("EUR_USD", TimeScale.Minute1, start_date, end_date, 0.07);
     //
 }
Ejemplo n.º 2
0
 public static void AddFileToPriceList(List <Price> price_list, string file)
 {
     string[,] table = ToolsIOCSV.ReadCSVFile(file);
     for (int index_0 = 0; index_0 < table.GetLength(0); index_0++)
     {
         //TODO duplicate date_times can exist both on the server and on the client
         DateTimeUTC date_time = ToolsTime.UnixTimeStampToDateTimeUTC(int.Parse(table[index_0, 1]));
         double      bid       = double.Parse(table[index_0, 2], CultureInfo.InvariantCulture);
         double      ask       = double.Parse(table[index_0, 3], CultureInfo.InvariantCulture);
         price_list.Add(new Price(date_time, bid, ask));
     }
 }
Ejemplo n.º 3
0
        public void DoExperiment()
        {
            double commission = 7;
            double spread     = 5;
            int    lookAhead  = 60;

            //Load data
            string[,] table = ToolsIOCSV.ReadCSVFile(@"D:\GoogleDrive\TestData\Trading\eurusddata.csv", Delimiter.Comma);

            //Convert data to values
            double[] ask = new double[table.GetLength(0)];
            double[] bid = new double[table.GetLength(0)];
            for (int i = 0; i < table.GetLength(0); i++)
            {
                bid[i] = 100000 * double.Parse(table[i, 2].Replace(".", ","));
                ask[i] = bid[i] + spread;
            }
            double mean1 = ToolsMathStatistics.Mean(ask);
            double mean2 = ToolsMathStatistics.Mean(bid);

            double[] buyCurve       = new double[table.GetLength(0) - lookAhead];
            double[] sellCurve      = new double[table.GetLength(0) - lookAhead];
            string[] buyCurveString = new string[buyCurve.Length];

            for (int i = 0; i < buyCurve.Length; i++)
            {
                double max = double.MinValue;
                double min = double.MaxValue;

                for (int j = 1; j < lookAhead; j++)
                {
                    max = Math.Max(max, bid[i + j]);
                    min = Math.Min(min, ask[i + j]);
                }

                buyCurve[i]       = max - ask[i] - commission;
                buyCurveString[i] = bid[i] + ";" + buyCurve[i];
                sellCurve[i]      = bid[i] - min - commission;
            }

            double mean3 = ToolsMathStatistics.Mean(buyCurve);
            double mean4 = ToolsMathStatistics.Mean(sellCurve);

            File.AppendAllLines(@"D:\GoogleDrive\TestData\Trading\buyCurveOut.csv", buyCurveString);

            /*
             * Load data
             * for each time point find optimal buy order
             * create line of optimal buy orders
             */
        }
 public void LoadState()
 {
     string [,] table   = ToolsIOCSV.ReadCSVFile(database_path);
     LastUpdateDateTime = DateTimeUTC.Parse(table[0, 0]);
     for (int index_0 = 1; index_0 < table.GetLength(0); index_0++)
     {
         event_list.Add(new TradingCalenderEvent(
                            DateTimeUTC.Parse(table[index_0, 0]),
                            table[index_0, 1],
                            table[index_0, 2],
                            bool.Parse(table[index_0, 3]),
                            ToolsString.StringToDictionary(table[index_0, 4])));
     }
 }
Ejemplo n.º 5
0
 static void Old0(string[] args)
 {
     // sample are 30 per second.
     string [,] table = ToolsIOCSV.ReadCSVFile(@"D:\Dropbox\TestData\ML6\data_0.csv", Delimiter.Comma, Delimiter.None);
     string [] row    = table.Select1DIndex0(1);
     double[]  signal = new double[row.Length];
     for (int element_index = 0; element_index < row.Length; element_index++)
     {
         signal[element_index] = double.Parse(row[element_index].Replace('.', ','), NumberStyles.Any);
     }
     double[] speed = RunRoy1(signal, 128);
     ToolsPlotting.PlotLinesXY(@"D:\Dropbox\TestData\ML6\data_0.png", speed);
     Console.ReadLine();
 }
Ejemplo n.º 6
0
        public void DoExperiment()
        {
            double commission = 7;

            //Load data
            string [,] table = ToolsIOCSV.ReadCSVFile(@"D:\GoogleDrive\TestData\Trading\spreads.csv", Delimiter.SemiColon);

            //Convert data to values
            double[] ask = new double [table.GetLength(0)];
            double[] bid = new double [table.GetLength(0)];
            for (int i = 0; i < table.GetLength(0); i++)
            {
                ask[i] = 10000 * double.Parse(table[i, 3].Replace(".", ","));
                bid[i] = 10000 * double.Parse(table[i, 2].Replace(".", ","));
            }
            double mean1 = ToolsMathStatistics.Mean(ask);
            double mean2 = ToolsMathStatistics.Mean(bid);

            double[] buyCurve  = new double[table.GetLength(0) - 3600];
            double[] sellCurve = new double[table.GetLength(0) - 3600];

            for (int i = 0; i < buyCurve.Length; i++)
            {
                double max = double.MinValue;
                double min = double.MaxValue;

                for (int j = 1; j < 3600; j++)
                {
                    max = Math.Max(max, bid[i + j]);
                    min = Math.Min(min, ask[i + j]);
                }

                buyCurve[i]  = max - ask[i] - commission;
                sellCurve[i] = bid[i] - min - commission;
            }

            double mean3 = ToolsMathStatistics.Mean(buyCurve);
            double mean4 = ToolsMathStatistics.Mean(sellCurve);

            /*
             * Load data
             * for each time point find optimal buy order
             * create line of optimal buy orders
             */
        }
Ejemplo n.º 7
0
        private PriceSet ImportSecondData(string file_path)
        {
            string        symbol         = Path.GetFileName(file_path).Substring(0, 6);
            TradingSymbol trading_symbol = new TradingSymbol("TradersWay", "MT4.VAR.DEMO", symbol, "The one we mine on the VM");
            List <Price>  price_list     = new List <Price>();

            string[,] table = ToolsIOCSV.ReadCSVFile(file_path);
            for (int index_0 = 0; index_0 < table.GetLength(0); index_0++)
            {
                //TODO duplicate date_times can exist both on the server and on the client
                DateTimeUTC date_time = ToolsTime.UnixTimeStampToDateTimeUTC(int.Parse(table[index_0, 0]));
                double      bid       = double.Parse(table[index_0, 2], CultureInfo.InvariantCulture);
                double      ask       = double.Parse(table[index_0, 3], CultureInfo.InvariantCulture);
                price_list.Add(new Price(date_time, bid, ask));
            }

            return(new PriceSet(trading_symbol, price_list));
        }
Ejemplo n.º 8
0
        private static Dictionary <string, List <Tuple <GeoLocationDecimalDegree, DateTime> > > ReadData(string file_path)
        {
            string [,] table = ToolsIOCSV.ReadCSVFile(file_path, Delimiter.Comma);
            //for (int i = 0; i < table.GetLength(1); i++)
            //{
            //    System.Console.WriteLine(i);
            //    System.Console.WriteLine(table[0, i]);
            //}
            Dictionary <string, List <Tuple <GeoLocationDecimalDegree, DateTime> > > data = new Dictionary <string, List <Tuple <GeoLocationDecimalDegree, DateTime> > >();

            for (int i = 1; i < table.GetLength(0); i++)
            {
                string   ship_id             = table[i, 14];
                double   latitutde           = Double.Parse(table[i, 5].Replace(".", ","));
                double   longitude           = Double.Parse(table[i, 4].Replace(".", ","));
                string[] date_time_utc_split = table[i, 11].Split(" ".ToCharArray());
                string[] date_utc_split      = date_time_utc_split[0].Split("/".ToCharArray());
                DateTime time      = DateTime.Parse(date_time_utc_split[1]);
                DateTime date      = new DateTime(Int32.Parse(date_utc_split[2]), Int32.Parse(date_utc_split[0]), Int32.Parse(date_utc_split[1]));
                DateTime data_time = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second, DateTimeKind.Utc);
                System.Console.WriteLine(ship_id);
                System.Console.WriteLine(latitutde);
                System.Console.WriteLine(longitude);
                System.Console.WriteLine(data_time);
                if (!data.ContainsKey(ship_id))
                {
                    data.Add(ship_id, new List <Tuple <GeoLocationDecimalDegree, DateTime> >());
                }
                data[ship_id].Add(new Tuple <GeoLocationDecimalDegree, DateTime>(new GeoLocationDecimalDegree((AngleDegree)latitutde, (AngleDegree)longitude), data_time));
            }
            List <string> ship_ids = new List <string>(data.Keys);

            foreach (string ship_id in ship_ids)
            {
                data[ship_id] = new List <Tuple <GeoLocationDecimalDegree, DateTime> >(data[ship_id].OrderBy(tuple => tuple.Item2));
            }

            return(data);
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
 private static IDataSet <int> ReadCSVNominal(string file_path)
 {
     return(new DataSet <int, int>(ToolsIOCSV.ReadCSVFile(file_path, Delimiter.Comma, Delimiter.None)));
 }