예제 #1
0
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                if (bFirst)
                {
                    bFirst = false;
                    Random rnd = new Random();
                    my_id = rnd.Next(1, 1000).ToString();
                }

                Description                = "test";
                Name                       = "KNN_Generator7";
                DaysToLookBack             = 1;
                FutureValueDaysToLookAhead = 5;

                TrainingStartDate = new DateTime(2017, 01, 01);
                TrainingEndDate   = new DateTime(2017, 09, 30);
                TestingStartDate  = new DateTime(2017, 10, 1);
                TestingEndDate    = new DateTime(2017, 12, 31);

                //Custom params
                indicator_to_use  = IndicatorEnum.indicator_MACD;
                KNN_num_neighbors = 3;
                num_training_pts  = 200;
                num_groups        = 20;
                stagger_factor    = 0;
                window_size       = 1;
                avg_target        = 1.0f;
                good_target       = 0.5f;
                bad_target        = 0.25f;
                min_samples       = 10;
                thresh1           = 1.0f;
                thresh2           = -1.0f;
                output_folder     = "C:\\temp\\knn\\";

                Param1 = 12;  //Defaults for MACD
                Param2 = 26;
                Param3 = 9;

                Sanitize = false;


                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = true;
                //IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.Configure)
            {
                String debug_txt = "min_samples=" + min_samples.ToString();
                Debug.WriteLine(debug_txt);

                for (int i = 0; i < symbol_list.Length; i++)
                {
                    //Don't add the dummy instrument (but we still need a placeholder list which is added below)
                    if (i != 0)
                    {
                        AddDataSeries(symbol_list[i], Data.BarsPeriodType.Day, 1);
                    }

                    list_Indicator_FutureValueChange_Training_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                    list_Indicator_FutureValueChange_Testing_ALL.Add(new List <Indicator_FutureValueChange_Pair>());
                }

                SetStopLoss(CalculationMode.Percent, 0.05);

                // Sets a 20 tick trailing stop for an open position
                //SetTrailStop(CalculationMode.Ticks, 20);
            }
            else if (State == State.DataLoaded)
            {
                //double input_param = 2.0;
                //greg1 = GregIndicator1(input_param);

                //AddChartIndicator(greg1);

                bDataLoaded = true;
            }
            else if ((bDataLoaded == true) && ((State == State.Transition) || (State == State.Terminated)))    //finished processing historical data (and ready for real-time)
            {
                //if (bExecutedPython == false)
                //{
                //    bExecutedPython = true;


                //System.Windows.Forms.MessageBox.Show("test");
                Random rnd       = new Random();
                String unique_id = "_" + rnd.Next(100000, 999999).ToString();     // creates a number between 100k and 999k

                String control_file_path          = output_folder + "control_file" + unique_id + ".txt";
                String consolidated_txt_file_path = output_folder + "consolidated_report" + unique_id + ".txt";
                String consolidated_csv_file_path = output_folder + "consolidated_report" + unique_id + ".csv";

                switch (indicator_to_use)
                {
                case IndicatorEnum.indicator_MACD:
                    if (Sanitize == false)
                    {
                        description = "MACD";
                    }
                    else
                    {
                        description = "M";
                    }
                    description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + "-" + Param3.ToString() + ")";
                    break;

                case IndicatorEnum.indicator_RSI:
                    if (Sanitize == false)
                    {
                        description = "RSI";
                    }
                    else
                    {
                        description = "R";
                    }
                    description = description + "(" + Param1.ToString() + "-" + Param2.ToString() + ")";
                    break;

                default:
                    description = "Unknown";
                    break;
                }

                description = description + " - " + FutureValueDaysToLookAhead.ToString();

                if (Sanitize == false)
                {
                    description = description + " days";
                }

                description = description + " - " + unique_id.Substring(1);      //remove preceding "_"

                bool bFirstTime = true;
                for (int i = 1; i < symbol_list.Length; i++)      //Start at index=1 since we want to ignore the first primary/dummy instrument
                {
                    String symbol_name = symbol_list[i];
                    if (Sanitize == true)
                    {
                        symbol_name = symbol_list[i][0].ToString();
                    }

                    String base_file_path_for_symbol = output_folder + symbol_name;      //i.e. c:\temp\knn\AAPL

                    String training_file_path = base_file_path_for_symbol + "_training" + unique_id + ".csv";
                    String testing_file_path  = base_file_path_for_symbol + "_testing" + unique_id + ".csv";
                    WriteListToCSV(list_Indicator_FutureValueChange_Training_ALL[i], training_file_path);      //trying out +1!!!
                    WriteListToCSV(list_Indicator_FutureValueChange_Testing_ALL[i], testing_file_path);

                    String config_file_name = "";
                    config_file_name = GenerateConfigFile(base_file_path_for_symbol, symbol_name, training_file_path, testing_file_path, unique_id);

                    if (bFirstTime)      //create new file
                    {
                        bFirstTime = false;
                        File.WriteAllText(control_file_path, config_file_name + "\r\n");
                    }
                    else     // append to existing file
                    {
                        File.AppendAllText(control_file_path, config_file_name + "\r\n");
                    }
                }

                //Now we can call python for all symbols at once by passing in the control_file as cmd line arg
                CallPythonScript(output_folder + "\\Data_Processing25.py", control_file_path + " " + consolidated_txt_file_path + " " + consolidated_csv_file_path + " true");

                //bDataLoaded = false;
                //}
            }
        }
 public DataTable GetStepWiseActions(Param1 sMode)
 {
     return(SessionObjects.obj.RequestTypeMasterPropertiesObject.LeftNavigationLinks.Tables["Action"]);
 }