Beispiel #1
0
        private void loadModel(IniUtil ini, string strategyName)
        {
            string list = getparams(strategyName);

            string[] names = list.Split(';');

            DataSet set = new DataSet();

            DataTable table = new DataTable();

            table.TableName = "param";

            DataColumn col = table.Columns.Add();

            col.ColumnName = "参数名";

            col.Caption = "参数名";

            col.DataType = System.Type.GetType("System.String");

            DataColumn col2 = table.Columns.Add();

            col2.ColumnName = "参数值";

            col2.Caption = "参数值";

            col2.DataType = System.Type.GetType("System.String");

            foreach (string param in names)
            {
                if (param != "")                //"交易合约;交易数量;开仓价;"   会多出一行来
                {
                    DataRow row = table.NewRow();

                    row[0] = param;

                    row[1] = "";

                    //读取配置文件的值
                    row[1] = ini.ReadString("params", param, "error!!!");

                    table.Rows.Add(row);
                }
            }


            set.Tables.Add(table);

            dataGridView1.DataSource = table.DefaultView;

            isLoadModel = true;
        }
Beispiel #2
0
        private void saveModel(string modelName)
        {
            //如果是加载已有模型就不保存
            if (isLoadModel)
            {
                return;
            }

            string str1 = Process.GetCurrentProcess().MainModule.FileName;

            int nt = str1.LastIndexOf("\\");

            string path = str1.Substring(0, nt);

            path = path + "\\strmodels\\" + modelName + ".ini";

            string strategyName = comboBox1.Text.ToString();


            IniUtil ini = new IniUtil(path);

            ini.WriteString("strategyName", "策略名称", strategyName);

            ini.WriteString("modelName", "模型名称", modelName);


            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataGridViewRow row = dataGridView1.Rows[i];

                if (row.Cells[1] != null && row.Cells[1].Value != null)
                {
                    string key = row.Cells[0].Value.ToString();     //参数值

                    string value = row.Cells[1].Value.ToString();   //参数值

                    ini.WriteString("params", key, value);
                }
            }
        }
Beispiel #3
0
        //加载保存过的模型
        private void button4_Click(object sender, EventArgs e)
        {
            string filename = "";

            dataGridView1.DataSource = null;

            OpenFileDialog f1 = new OpenFileDialog();

            f1.Filter = "文本文件|*.ini";
            if (f1.ShowDialog() == DialogResult.OK)
            {
                filename = f1.FileName;
            }

            if (filename != "")
            {
                IniUtil ini = new IniUtil(filename);

                comboBox1.Text = ini.ReadString("strategyName", "策略名称", "请手动增加模型!");

                loadModel(ini, comboBox1.Text);
            }
        }