示例#1
0
        public bool FindStockInDB(StockData dt)
        {
            var query = Query.And(
                Query.EQ("StockId", dt.StockId),
                Query.EQ("TradeDate", dt.TradeDate));

            var res = Collection_.Find(query);
            return (res.Count() != 0);
        }
        public void RunSell()
        {
            EngulfingSignal es = new EngulfingSignal();

            StockData sd1 = new StockData { StartPrice = 106, MaxPrice = 106, MinPrice = 96, EndPrice = 96 };
            StockData sd2 = new StockData { StartPrice = 97, MaxPrice = 105, MinPrice = 97, EndPrice = 105 };
            Assert.IsFalse(es.AddStock(sd2));
            Assert.IsTrue(es.AddStock(sd1));

            Assert.AreEqual(es.GetSignal(), OperType.Sell);
        }
        public void RunNoOper2()
        {
            EngulfingSignal es = new EngulfingSignal();

            StockData sd1 = new StockData { StartPrice = 102, MaxPrice = 102, MinPrice = 98, EndPrice = 98 };
            StockData sd2 = new StockData { StartPrice = 99, MaxPrice = 105, MinPrice = 99, EndPrice = 105 };
            Assert.IsFalse(es.AddStock(sd2));
            Assert.IsTrue(es.AddStock(sd1));

            Assert.AreEqual(es.GetSignal(), OperType.NoOper);
        }
示例#4
0
        public void AddStockData(StockData sd)
        {
            if (FindHelper_.FindStock(sd.StockId, sd.TradeDate))
            {
                // Already exist
                return;
            }

            AllStock.Insert(sd);
            FindHelper_.AddStockDay(sd.StockId, sd.TradeDate);
        }
示例#5
0
        /// <summary>
        /// Convert from DotNetStock.Engine.Stock to IStockData
        /// </summary>
        /// <param name="stock">DotNetStock.Engine.Stock</param>
        /// <returns>Converted IStockData</returns>
        public static StockData ToStockData(DotNetStock.Engine.Stock stock)
        {
            StockData data = new StockData();

            data.Amount = stock.getVolume();
            data.EndPrice = stock.getLastPrice();
            data.StockId = ConvertStockId(stock.getSymbol().toString());
            data.MaxPrice = stock.getHighPrice();
            data.MinPrice = stock.getLowPrice();
            data.StartPrice = stock.getOpenPrice();
            data.TradeDate = stock.getCalendar().CurrentDate;
            data.VolumeHand = Convert.ToInt32(stock.getVolume());
            return data;
        }
        /// <summary>
        /// 创建假的股票数据供测试
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="startPrice"></param>
        /// <param name="maxPrice"></param>
        /// <param name="minPrice"></param>
        /// <param name="endPrice"></param>
        /// <param name="volumehand"></param>
        /// <returns></returns>
        public static StockData Create(DateTime dt, double startPrice, double maxPrice, 
            double minPrice, double endPrice, int volumehand)
        {
            StockData val = new StockData();
            val.Amount = 100000;
            val.StockId = 999999;

            val.TradeDate = dt;
            val.StartPrice = startPrice;
            val.EndPrice = endPrice;
            val.MaxPrice = maxPrice;
            val.MinPrice = minPrice;
            val.VolumeHand = volumehand;

            return val;
        }