Пример #1
0
        //保存至数据库
        public static void SaveToDB(int type, int startdate, int enddate, string buyrule, string sellrule, System.Collections.ArrayList list)
        {
            ClearDB(type, startdate, enddate, buyrule, sellrule);

            string sql = "insert into Ope_Simulate values(" + type + ",'" + startdate + "','" + enddate + "','" + buyrule + "','" + sellrule + "');";

            db.RunSql(sql);
            int maxid = db.GetMaxTableId("Ope_Simulate");

            //有可能是上次没删干净的记录
            sql = "delete from Ope_Simulate_Item where id = '" + maxid.ToString() + "';";
            db.RunSql(sql);
            System.Collections.ArrayList sqllist = new System.Collections.ArrayList();


            SQLMassImport rulefile = new SQLMassImport("Simulate");

            for (int i = 0; i < list.Count; i++)
            {
                StockSimulateItem item = (StockSimulateItem)list[i];
                string[]          strs = new string[18];
                strs[0]  = maxid.ToString();
                strs[1]  = item.type.ToString();
                strs[2]  = item.buyrule;
                strs[3]  = item.sellrule;
                strs[4]  = item.stockcode;
                strs[5]  = item.buydate.ToString();
                strs[6]  = item.buyindex.ToString();
                strs[7]  = item.buyprice.ToString();
                strs[8]  = item.selldate.ToString();
                strs[9]  = item.sellindex.ToString();
                strs[10] = item.sellprice.ToString();
                strs[11] = item.buyvolume.ToString();
                strs[12] = item.stockvalue.ToString();
                strs[13] = item.winvalue.ToString();
                strs[14] = item.holdstocknum.ToString();
                strs[15] = item.totalstockvalue.ToString();
                strs[16] = item.leftmoney.ToString();
                strs[17] = item.totalamount.ToString();
                rulefile.AddRow(strs);
            }

            rulefile.ImportClose(db, StockSQL.TABLE_SIMULATE_ITEM);
        }
Пример #2
0
        private void doBuy(StockOpeItem item)
        {
            StockSimulateItem smitem = new StockSimulateItem(item);

            smitem.type = item.type;
            //剩余资金需要均分给需要买的股票数量
            double buymoney = leftmoney / (totalnum - holditems.Count);
            //可以买的手数
            int buyvolume = (int)(buymoney / (100 * item.buyprice));

            //实际可以买的股票数
            smitem.buyvolume = buyvolume * 100;
            //剩余资金: 需要计算手续费
            leftmoney = leftmoney - smitem.buyvolume * item.buyprice * (1 + StockApp.FEE);
            holditems.Add(smitem);
            smitem.holdstocknum    = holditems.Count;
            smitem.totalstockvalue = getHoldStockValue();
            smitem.leftmoney       = leftmoney;
            record_opeitems.Add(smitem);
        }
Пример #3
0
 private void doSell(int date)
 {
     StockSimulateItem[] items = (StockSimulateItem[])holditems.ToArray(typeof(StockSimulateItem));
     for (int i = 0; i < items.Length; i++)
     {
         StockSimulateItem item = items[i];
         if (item.selldate == date)
         {
             //减去手续费
             holditems.Remove(item);
             StockSimulateItem sellitem = item.Copy();
             sellitem.type            = Rule.STATUS_SELL;
             leftmoney                = leftmoney + (sellitem.stockvalue + sellitem.winvalue) * (1 - StockApp.FEE);
             sellitem.holdstocknum    = holditems.Count;
             sellitem.totalstockvalue = getHoldStockValue();
             sellitem.leftmoney       = leftmoney;
             record_opeitems.Add(sellitem);
         }
     }
 }
Пример #4
0
        public StockSimulateItem Copy()
        {
            StockSimulateItem item = new StockSimulateItem();

            item.type            = type;
            item.buyrule         = buyrule;
            item.sellrule        = sellrule;
            item.stockcode       = stockcode;
            item.buydate         = buydate;
            item.buyindex        = buyindex;
            item.buyprice        = buyprice;
            item.selldate        = selldate;
            item.sellindex       = sellindex;
            item.sellprice       = sellprice;
            item.buyvolume       = buyvolume;
            item.holdstocknum    = holdstocknum;
            item.totalstockvalue = totalstockvalue;
            item.leftmoney       = leftmoney;

            return(item);
        }
Пример #5
0
        public static StockSimulateItem[] GetSimulateList(int type, int startdate, int endate, string buyname, string sellname)
        {
            string sql = "select id from Ope_Simulate where type = " + type + " and startdate = '" + startdate + "' and enddate = '" + endate + "' and buyrule = '" + buyname + "' and sellrule = '" + sellname + "';";
            object id  = db.GetOneValue(sql, "id");

            StockSimulateItem[] items = new StockSimulateItem[0];
            if (id != null)
            {
                sql = "select * from  Ope_Simulate_Item where id = '" + id.ToString() + "';";
                System.Data.DataTable table = db.GetTable(sql);
                items = new StockSimulateItem[table.Rows.Count];
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    System.Data.DataRow row  = table.Rows[i];
                    StockSimulateItem   item = new StockSimulateItem();
                    item.type      = Convert.ToInt32(row["type"]);
                    item.buyrule   = (string)row["buyrule"];
                    item.sellrule  = (string)row["sellrule"];
                    item.stockcode = (string)row["stockcode"];
                    item.buydate   = Convert.ToInt32(row["buydate"]);
                    item.buyindex  = Convert.ToInt32(row["buyindex"]);
                    item.buyprice  = Convert.ToDouble(row["buyprice"]);
                    item.selldate  = Convert.ToInt32(row["selldate"]);
                    item.sellindex = Convert.ToInt32(row["sellindex"]);
                    item.sellprice = Convert.ToDouble(row["sellprice"]);
                    item.buyvolume = Convert.ToInt32(row["buyvolume"]);
                    //item.stockvalue = Convert.ToDouble(row["stockvalue"]);
                    //item.winvalue = Convert.ToDouble(row["winvalue"]);
                    item.holdstocknum    = Convert.ToInt32(row["holdstocknum"]);
                    item.totalstockvalue = Convert.ToDouble(row["totalstockvalue"]);
                    item.leftmoney       = Convert.ToDouble(row["leftmoney"]);
                    //item.totalamount = Convert.ToDouble(row["totalamount"]);
                    items[i] = item;
                }
            }

            return(items);
        }