public void SaveState()
        {
            List <string[]> array_list = new List <string[]>();

            array_list.Add(new string[]
            {
                LastUpdateDateTime.ToString(),
                "",
                "",
                "",
                ""
            });

            foreach (TradingCalenderEvent trading_calender_event in event_list)
            {
                array_list.Add(new string[]
                {
                    trading_calender_event.EventTimeUTC.ToString(),
                    trading_calender_event.Symbol,
                    trading_calender_event.Description,
                    trading_calender_event.IsAllDay.ToString(),
                    ToolsString.DictionaryToString(trading_calender_event.Tags)
                });
            }


            ToolsIOCSV.WriteCSVFile(database_path, ToolsCollection.ConvertToArray2D(array_list));
        }
示例#2
0
        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);
        }
示例#3
0
        public void DoExperiment()
        {
            IReadOnlyList <PriceCandle> candles = ToolsPrice.GetPriceCandles(ToolsPrice.DefaultSymbolUSDEUR, TimeScale.Second1);
            DictionaryCount <int>       dic     = new DictionaryCount <int>();

            foreach (PriceCandle candle in candles)
            {
                dic.Increment((int)Math.Round((candle.OpenAsk - candle.OpenBid) / TradingConstants.POINT));
            }
            List <int> keys = new List <int>(dic.Keys);

            keys.Sort();

            string[,] spread_table = new string[keys.Count, 2];
            for (int i = 0; i < keys.Count; i++)
            {
                Console.WriteLine(keys[i] + " " + dic[keys[i]]);
                spread_table[i, 0] = keys[i].ToString(CultureInfo.InvariantCulture);
                spread_table[i, 1] = dic[keys[i]].ToString(CultureInfo.InvariantCulture);
            }
            ToolsIOCSV.WriteCSVFile(@"D:\GoogleDrive\TestData\Trading\Spreads.csv", spread_table);
        }
        public void DoExperiment()
        {
            ToolsPrice.ComposeBinary(ToolsPrice.DefaultSymbolGBPUSD);
            PriceSet price_set = ToolsPrice.GetPriceSet(ToolsPrice.DefaultSymbolGBPUSD).SubSet(new DateTimeUTC(2016, 10, 17), new DateTimeUTC(2016, 10, 20));


            IIndicator            indicator_feature = new IndicatorSuperBollinger();
            IIndicator            indicator_label   = new IndicatorMagicProfit(60);
            MarketModelSimulation market0           = new MarketModelSimulation(10000, price_set);
            MarketModelSimulation market1           = new MarketModelSimulation(10000, price_set);

            double[] time = new double[price_set.Prices.Count];
            for (int price_index = 0; price_index < price_set.Prices.Count; price_index++)
            {
                time[price_index] = price_set.Prices[price_index].Time.Ticks;
            }

            Tuple <double[, ], bool[]> tuple0 = indicator_feature.ComputeAll(market0, price_set.Second1.Count);
            Tuple <double[, ], bool[]> tuple1 = indicator_label.ComputeAll(market1, price_set.Second1.Count);

            List <string[]> list_string = new List <string[]>();

            for (int index_0 = 0; index_0 < tuple0.Item2.Length; index_0++)
            {
                if (tuple0.Item2[index_0] && tuple1.Item2[index_0])
                {
                    double[] array_double = ToolsCollection.Append(tuple0.Item1.Select1DIndex0(index_0), tuple1.Item1.Select1DIndex0(index_0));
                    string[] array_string = new string[array_double.Length];
                    for (int index_1 = 0; index_1 < array_double.Length; index_1++)
                    {
                        array_string[index_1] = array_double[index_1].ToString(CultureInfo.InvariantCulture);
                    }
                    list_string.Add(array_string);
                }
            }

            ToolsIOCSV.WriteCSVFile(ToolsTradingDataSet.GetPath() + "data.csv", ToolsCollection.ConvertToArray2D(list_string));
        }
示例#5
0
        //Layout: open, high, low, close, year, month, day_of_month, day of week, minute_of_day,
        public static void ExportDataSet(IList <PriceCandle> prices, DateTimeUTC first_day, DateTimeUTC last_day, string file_path)
        {
            IList <string[]> lines = new List <string[]>();

            foreach (PriceCandle price_candle in prices)
            {
                if ((first_day.Date <= price_candle.OpenTime.Date) && (price_candle.OpenTime.Date <= last_day.Date))
                {
                    string[] line = new string[9];
                    line[0] = price_candle.OpenBid.ToString(CultureInfo.InvariantCulture);
                    line[1] = price_candle.HighBid.ToString(CultureInfo.InvariantCulture);
                    line[2] = price_candle.LowBid.ToString(CultureInfo.InvariantCulture);
                    line[3] = price_candle.CloseBid.ToString(CultureInfo.InvariantCulture);
                    line[4] = price_candle.OpenTime.Year.ToString(CultureInfo.InvariantCulture);
                    line[5] = price_candle.OpenTime.Month.ToString(CultureInfo.InvariantCulture);
                    line[6] = price_candle.OpenTime.Day.ToString(CultureInfo.InvariantCulture);
                    line[7] = ((int)price_candle.OpenTime.DayOfWeek).ToString();
                    line[8] = ((price_candle.OpenTime.Hour * 60) + price_candle.OpenTime.Minute).ToString();
                    lines.Add(line);
                }
            }
            ToolsIOCSV.WriteCSVFile(file_path, ToolsCollection.ConvertToArray2D(lines));
        }
示例#6
0
        private void ExecuteParseAll()
        {
            if (PageFileSelected == null)
            {
                return;
            }
            bitmapSource = new Bitmap(PageFileSelected);
            if (bitmapSource == null)
            {
                return;
            }
            if ((bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) ||
                (bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                bitmapSource = ToolsConvolution.ConvertTo24(bitmapSource);
            }


            //Rotate
            var bitmapRot             = new RotateBilinear(PageLayout.Rotation.Value, true).Apply(bitmapSource);
            var linesH                = ToolsFindLine.FindLinesH(bitmapRot.Width, bitmapRot.Height, PageLayout.LineSize.Value, PageLayout.LineOffset.Value, PageLayout.LineCount.Value);
            var linesV                = ToolsFindLine.FindLinesV(bitmapRot.Width, bitmapRot.Height, PageLayout.ColSize.Value, PageLayout.ColOffset.Value, PageLayout.ColCount.Value);
            List <RenderLine> rl_list = new List <RenderLine>();

            rl_list.AddRange(linesH);
            rl_list.AddRange(linesV);

            //Convert to gray
            Bitmap bitmapTemp = new Grayscale(1, 0, 0).Apply(bitmapRot);

            bitmapTemp = new Erosion().Apply(bitmapTemp);
            bitmapTemp = new Threshold(160).Apply(bitmapTemp);
            bitmapTemp = new Invert().Apply(bitmapTemp);


            //Tuple<List<ConnectedComponent>, double, double>[] componentSectionList = new Tuple<List<ConnectedComponent>, double, double>[1];
            //Bitmap[] BitmapArray = new Bitmap[1];
            Tuple <List <ConnectedComponent>, double, double>[,] componentTable = new Tuple <List <ConnectedComponent>, double, double> [PageLayout.LineCount.Value, PageLayout.ColCount.Value];

            for (int lineIndex = 0; lineIndex < PageLayout.LineCount.Value; lineIndex++)
            {
                for (int colIndex = 0; colIndex < PageLayout.ColCount.Value; colIndex++)
                {
                    //TODO add margin?
                    int    x      = (int)((PageLayout.ColSize.Value * colIndex) + PageLayout.ColOffset.Value); // - PageLayout.Margin.Value;
                    int    y      = (int)((PageLayout.LineSize.Value * lineIndex) + PageLayout.LineOffset.Value) - PageLayout.Margin.Value;
                    int    w      = (int)PageLayout.ColSize.Value;                                             // + (PageLayout.Margin.Value * 2);
                    int    h      = (int)PageLayout.LineSize.Value + (PageLayout.Margin.Value * 2);
                    Bitmap bitmap = new Crop(new Rectangle(x, y, w, h)).Apply(bitmapTemp);
                    List <ConnectedComponent> lineComponentList = new List <ConnectedComponent>();
                    lineComponentList = GetTokens(bitmap);
                    componentTable[lineIndex, colIndex] = new Tuple <List <ConnectedComponent>, double, double>(lineComponentList, x, y);
                }
            }

            //ImageParse = RenderBitmap(bitmapRot, rl_list, componentTable);
            ImageLayout = RenderBitmap(bitmapRot, rl_list, componentTable);
            //Create output
            string[,] string_table = new string[PageLayout.LineCount.Value, PageLayout.ColCount.Value];
            for (int i = 0; i < PageLayout.LineCount.Value; i++)
            {
                for (int j = 0; j < PageLayout.ColCount.Value; j++)
                {
                    string_table[i, j] = TokensToString(componentTable[i, j].Item1, 3, " ");
                }
            }
            string csvFileSelected = LayoutFileSelected.Replace(".png", ".csv");

            ToolsIOCSV.WriteCSVFile(csvFileSelected, string_table, KozzionCore.IO.CSV.Delimiter.SemiColon);
        }
示例#7
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));
        }