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));
        }
Exemple #2
0
 public void Write(BinaryWriter writer, IBinaryWriter <FeatureType> writer_features, IBinaryWriter <LabelType> writer_labels)
 {
     this.DataContext.Write(writer);
     writer_features.Write(ToolsCollection.ConvertToArray2D(this.feature_data));
     writer.Write(ToolsCollection.ConvertToArray2D(this.missing_data));
     writer_labels.Write(ToolsCollection.ConvertToArray2D(this.label_data));
 }
        public ITransform GenerateTransform(IDataSet <double> data_set)
        {
            AMatrix <MatrixType> data       = algebra.Create(ToolsCollection.ConvertToArray2D(data_set.FeatureData));
            SVD <MatrixType>     svd        = algebra.ComputeSVD(data);
            AMatrix <MatrixType> projection = svd.VT.Transpose().GetColumns(0, destination_dimension_count);

            return(new DimensionReductionPCA <MatrixType>(data_set.DataContext, projection));
        }
        public override IModelLikelihood <double, int> GenerateModelLikelihood(IDataSet <double, int> training_set)
        {
            svm_problem prob = new svm_problem();

            prob.l = training_set.InstanceCount;
            prob.x = CreateNodeArray(ToolsCollection.ConvertToArray2D(training_set.FeatureData));
            prob.y = ToolsCollection.ConvertToDoubleArray(ToolsCollection.ConvertToArray2D(training_set.LabelData).Select1DIndex1(0));

            //Train model---------------------------------------------------------------------
            return(new ModelLibSVMCSVC(training_set.DataContext, new C_SVC(prob, KernelHelper.RadialBasisFunctionKernel(this.Gamma), this.C, this.CacheSize, true)));
        }
        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));
        }
        //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));
        }
        public override IModelDiscrete <double, int> GenerateModelDiscrete(IDataSet <double, int> training_set)
        {
            double[][] instance_features_array = training_set.FeatureData;
            int[]      outputs = ToolsCollection.ConvertToArray2D(training_set.LabelData).Select1DIndex1(0);

            // Specify the input variables
            List <DecisionVariable> variables = new List <DecisionVariable>();

            foreach (VariableDescriptor feature_descriptor in training_set.DataContext.FeatureDescriptors)
            {
                variables.Add(new DecisionVariable(feature_descriptor.Name, DecisionVariableKind.Continuous));
            }

            // Create the discrete Decision tree
            DecisionTree tree = new DecisionTree(variables, training_set.DataContext.GetLabelDescriptor(0).ValueCount);

            // Create the C4.5 learning algorithm
            C45Learning c45 = new C45Learning(tree); //TODO are there others?

            // Learn the decision tree using C4.5
            double error = c45.Run(instance_features_array, outputs);

            return(new ModelDiscreteC45 <int>(training_set.DataContext, tree));
        }
Exemple #8
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));
        }
 public AMatrix <double[, ]> Create(IList <double> array, bool transpose = false)
 {
     return(new MatrixKozzion <double>(this, ToolsCollection.ConvertToArray2D(array), transpose));
 }