Beispiel #1
0
        // 最简单的算法,指令为前一日最低值买入,最高值卖出
        public override ICollection <StockOper> GetOper(DateTime day, IAccount account)
        {
            IStockData prevStock = stockHistory.GetPrevDayStock(day);

            if (prevStock == null)
            {
                Debug.WriteLine("StrategyMinMax -- GetPrevDayStock ERROR: Cur Day: " + day.ToLongDateString());
                //Debug.Assert(false);
                return(null);
            }

            ICollection <StockOper> opers = new List <StockOper>();
            int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll,
                                                             prevStock.MinPrice);

            if (stockCount > 0)
            {
                StockOper oper = new StockOper(prevStock.MinPrice, stockCount, OperType.Buy);
                opers.Add(oper);
            }

            if (stockHolder.HasStock())
            {
                StockOper oper2 = new StockOper(prevStock.MaxPrice, stockHolder.StockCount(), OperType.Sell);
                opers.Add(oper2);
            }

            return(opers);
        }
        // 指令为前一日最低值买入,赚x%卖出
        public override ICollection <StockOper> GetOper(DateTime day, IAccount account)
        {
            IStockData prevStockProp = stockHistory.GetPrevDayStock(day);

            if (prevStockProp == null)
            {
                Debug.WriteLine("StrategyPercent -- GetPrevDayStock ERROR: Cur Day: " + day.ToLongDateString());
                return(null);
            }

            ICollection <StockOper> opers = new List <StockOper>();
            int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll,
                                                             prevStockProp.MinPrice);

            if (stockCount > 0)
            {
                StockOper oper = new StockOper(prevStockProp.MinPrice, stockCount, OperType.Buy);
                opers.Add(oper);
            }

            if (stockHolder.HasStock())
            {
                double unitCost = stockHolder.UnitPrice;
                if (unitCost > 0)
                {
                    StockOper oper2 = new StockOper(unitCost * (1 + winPercent), stockHolder.StockCount(), OperType.Sell);
                    opers.Add(oper2);
                }
            }

            return(opers);
        }
Beispiel #3
0
        public override ICollection <StockOper> GetOper(DateTime day, IAccount account)
        {
            IStockData curProp = stockHistory.GetStock(day);

            if (!CheckStock(curProp, day))
            {
                return(null);
            }

            _Averager.AddVal(curProp.Amount);
            _SlopeCalc.AddVal(curProp.EndPrice); // 计算收盘价斜率

            if (!_Averager.IsEnough() || !_SlopeCalc.IsEnough())
            {
                return(null);
            }

            ICollection <StockOper> opers = new List <StockOper>();
            double avgMinAmount           = _Averager.GetValue() * (1 - _BuyMargin);
            double avgMaxAmount           = _Averager.GetValue() * (1 + _SellMargin);

            ShapeJudger judger = new ShapeJudger(curProp);

            //if ((curProp.Amount < avgMinAmount) && (judger.IsCross() && _SlopeCalc.IsDownPeriod()))
            if ((curProp.Amount < avgMinAmount) && ShapeJudger.IsCross(curProp))
            {
                // 成交地量,十字星,买入
                int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll,
                                                                 curProp.EndPrice);
                if (stockCount > 0)
                {
                    StockOper oper = new StockOper(curProp.EndPrice, stockCount, OperType.Buy);
                    opers.Add(oper);
                    return(opers);
                }
            }
            else if ((curProp.Amount > avgMaxAmount) && _SlopeCalc.IsRisePeriod())
            {
                // 上涨过程,成交天量,卖出
                if (stockHolder.HasStock())
                {
                    StockOper oper = new StockOper(curProp.EndPrice, stockHolder.StockCount(), OperType.Sell);
                    opers.Add(oper);
                    return(opers);
                }
            }

            if (judger.IsReverseT())
            {
                // 倒T型,卖出
                if (stockHolder.HasStock())
                {
                    StockOper oper = new StockOper(curProp.EndPrice, stockHolder.StockCount(), OperType.Sell);
                    opers.Add(oper);
                    return(opers);
                }
            }

            return(null);
        }
Beispiel #4
0
        public override ICollection <StockOper> GetOper(DateTime day, IAccount account)
        {
            IStockData curStockProp = stockHistory.GetStock(day);

            if (curStockProp == null)
            {
                return(null);
            }

            ICollection <StockOper> opers = new List <StockOper>();

            if (!stockHolder.HasStock())
            {
                // 无股票则买入10%
                int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll * BAMBOOPERCENT,
                                                                 curStockProp.StartPrice); // 开盘买入
                if (stockCount >= STOCKHAND)
                {
                    StockOper oper = new StockOper(curStockProp.StartPrice, stockCount, OperType.Buy);
                    opers.Add(oper);
                }
            }
            else
            {
                double unitCost = stockHolder.UnitPrice; // 持仓成本
                if (unitCost > 0)
                {
                    double expectedMinPrice = unitCost * (1 - BAMBOOPERCENT);
                    double expectedMaxPrice = unitCost * (1 + BAMBOOPERCENT);

                    if (curStockProp.MinPrice <= expectedMinPrice)
                    {
                        // 现金的10%
                        int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll * BAMBOOPERCENT,
                                                                         curStockProp.StartPrice);

                        if (stockCount > 0)
                        {
                            StockOper oper2 = new StockOper(expectedMinPrice, stockCount, OperType.Buy);
                            opers.Add(oper2);
                        }
                    }

                    if (curStockProp.MaxPrice >= expectedMaxPrice)
                    {
                        // 卖出持仓股票的10%
                        double sellCount = stockHolder.StockCount() * BAMBOOPERCENT;
                        if (sellCount >= STOCKHAND)
                        {
                            opers.Add(new StockOper(expectedMaxPrice, Convert.ToInt32(sellCount), OperType.Sell));
                        }
                    }
                }
            }

            return(opers);
        }
Beispiel #5
0
        public override ICollection <StockOper> GetOper(DateTime day, IAccount account)
        {
            IStockData curProp            = stockHistory.GetStock(day);
            IStockData stockYesterdayProp = stockHistory.GetPrevDayStock(day);

            DateTime   prevDate      = stockHistory.GetPreviousDay(day);
            IStockData stockprevProp = stockHistory.GetPrevDayStock(prevDate);
            DateTime   prevNextDate  = stockHistory.GetPreviousDay(prevDate);

            if (!CheckStock(curProp, day) || !CheckStock(stockYesterdayProp, prevDate) ||
                !CheckStock(stockprevProp, prevNextDate))
            {
                return(null);
            }

            ICollection <StockOper> opers = new List <StockOper>();

            // IsRise? Condition questionable.
            if (
                StockJudger.IsRise(stockYesterdayProp, stockprevProp)
                &&
                StockJudger.IsUp(stockYesterdayProp) &&
                StockJudger.IsUp(stockprevProp))
            {
                if (stockHolder.HasStock())
                {
                    StockOper oper = new StockOper(curProp.StartPrice, stockHolder.StockCount(), OperType.Sell);
                    opers.Add(oper);
                    return(opers);
                }
            }
            else if (
                !StockJudger.IsRise(stockYesterdayProp, stockprevProp)
                &&
                !StockJudger.IsUp(stockYesterdayProp) &&
                !StockJudger.IsUp(stockprevProp))
            {
                int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll,
                                                                 curProp.StartPrice);
                if (stockCount > 0)
                {
                    StockOper oper = new StockOper(curProp.StartPrice, stockCount, OperType.Buy);
                    opers.Add(oper);
                    return(opers);
                }
            }

            return(null);
        }
Beispiel #6
0
        // 指令为如果没有股票,当日开盘买入,否则涨跌幅达到x%卖出(止盈止损策略)
        public override ICollection <StockOper> GetOper(DateTime day, IAccount account)
        {
            IStockData prevStockProp = stockHistory.GetPrevDayStock(day);
            IStockData curStockProp  = stockHistory.GetStock(day);

            if ((prevStockProp == null) || (curStockProp == null))
            {
                return(null);
            }

            ICollection <StockOper> opers = new List <StockOper>();

            if (!stockHolder.HasStock())
            {
                int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll,
                                                                 curStockProp.StartPrice); // 如果没有股票,当天开盘买入
                if (stockCount > 0)
                {
                    StockOper oper = new StockOper(curStockProp.StartPrice, stockCount, OperType.Buy);
                    opers.Add(oper);
                    return(opers); // 有疑问,目前不支持一天之内的买卖
                }
            }
            else
            {
                double unitCost = stockHolder.UnitPrice;
                if (unitCost > 0)
                {
                    if (curStockProp.MaxPrice >= (unitCost * (1 + winPercent)))
                    {
                        // 止盈
                        StockOper oper2 = new StockOper(unitCost * (1 + winPercent), stockHolder.StockCount(), OperType.Sell);
                        opers.Add(oper2);
                        return(opers);
                    }

                    if (curStockProp.MinPrice <= (unitCost * (1 - winPercent)))
                    {
                        // 止损
                        StockOper oper1 = new StockOper(unitCost * (1 - winPercent), stockHolder.StockCount(), OperType.Sell);
                        opers.Add(oper1);
                        return(opers);
                    }
                }
            }

            return(null);
        }
        public override ICollection <StockOper> GetOper(DateTime dt, IAccount account)
        {
            DateTime yesterday = stockHistory.GetPreviousDay(dt);

            IStockData curProp = stockHistory.GetStock(dt);

            if (curProp == null)
            {
                return(null);
            }

            OperType operType = _Calc.MatchSignal(dt, yesterday);

            if (operType == OperType.Buy)
            {
                int stockCount = Transaction.GetCanBuyStockCount(account.BankRoll,
                                                                 curProp.EndPrice);
                if (stockCount <= 0)
                {
                    return(null);
                }

                ICollection <StockOper> opers = new List <StockOper>();
                StockOper oper = new StockOper(curProp.EndPrice, stockCount, OperType.Buy);
                opers.Add(oper);
                return(opers); // 买入
            }
            else if (operType == OperType.Sell)
            {
                if (!stockHolder.HasStock())
                {
                    return(null);
                }

                ICollection <StockOper> opers = new List <StockOper>();
                StockOper oper = new StockOper(curProp.EndPrice, stockHolder.StockCount(), OperType.Sell);
                opers.Add(oper);
                return(opers);
            }
            return(null);
        }
Beispiel #8
0
        public bool IsOperSuccess(DateTime dt, StockOper oper)
        {
            if (!DailyStocks_.ContainsKey(dt))
            {
                return(false);
            }
            if (oper == null)
            {
                return(false);
            }

            if (oper.Type == OperType.NoOper)
            {
                return(true);
            }

            StockData stock = DailyStocks_[dt];

            switch (oper.Type)
            {
            case OperType.Buy:
                if (oper.UnitPrice >= stock.MinPrice)
                {
                    return(true);
                }
                break;

            case OperType.Sell:
                if (oper.UnitPrice <= stock.MaxPrice)
                {
                    return(true);
                }
                break;

            default:
                break;
            }

            return(false);
        }