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;
        }
        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
        static bool IsValidOperation(IStockData stock, StockOper oper)
        {
            switch (oper.Type)
            {
            case OperType.Buy:
                return(oper.UnitPrice >= stock.MinPrice);

            case OperType.Sell:
                return(oper.UnitPrice <= stock.MaxPrice);

            default:
                return(false);
            }
        }
        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 #7
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;
        }
Beispiel #8
0
        // 买入股票
        private void BuyStocks(StockOper oper)
        {
            BuyTransactionCount_++;
            double charge = Transaction.GetTotalCharge(oper.UnitPrice * oper.HandCount);

            if (bankRoll_ >= charge)
            {
                bankRoll_ -= charge;
                Holder.BuyStock(oper.HandCount, oper.UnitPrice);

                LogMgr.Logger.LogInfo("Action: Buy Stock Count: {0}, Unit Price: {1}",
                                      oper.HandCount,
                                      oper.UnitPrice);
            }
            else
            {
                throw new InvalidOperationException("Bank Roll is smaller than total price!");
            }
        }
Beispiel #9
0
        public bool IsOperSuccess(DateTime dt, StockOper oper)
        {
            if (oper == null)
            {
                return(false);
            }

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

            if (!DailyStocks_.ContainsKey(dt))
            {
                return(false);
            }

            IStockData stock = DailyStocks_[dt];

            return(IsValidOperation(stock, oper));
        }
Beispiel #10
0
        /// <summary>
        /// 处理买入或者卖出操作
        /// </summary>
        /// <param name="oper">操作</param>
        /// <returns>操作是否成功</returns>
        public bool DoBusiness(StockOper operation)
        {
            if (operation == null)
            {
                return(false);
            }

            if (operation.Type == OperType.Buy)
            {
                this.BuyStocks(operation);
            }
            else if (operation.Type == OperType.Sell)
            {
                this.bankRoll_ += Holder.SellStock(operation.HandCount, operation.UnitPrice);
                this.SellTransactionCount_++;
            }
            else
            {
            }

            return(true);
        }
        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 #12
0
 static bool IsValidOperation(IStockData stock, StockOper oper)
 {
     switch (oper.Type)
     {
         case OperType.Buy:
             return (oper.UnitPrice >= stock.MinPrice);
         case OperType.Sell:
             return (oper.UnitPrice <= stock.MaxPrice);
         default:
             return false;
     }
 }
Beispiel #13
0
        /// <summary>
        /// ������������������
        /// </summary>
        /// <param name="oper">����</param>
        /// <returns>�����Ƿ�ɹ�</returns>
        public bool DoBusiness(StockOper operation)
        {
            if (operation == null)
            {
                return false;
            }

            if (operation.Type == OperType.Buy)
            {
                this.BuyStocks(operation);
            }
            else if (operation.Type == OperType.Sell)
            {
                this.bankRoll_ += Holder.SellStock(operation.HandCount, operation.UnitPrice);
                this.SellTransactionCount_++;
            }
            else
            {
            }

            return true;
        }
Beispiel #14
0
        public bool IsOperSuccess(DateTime dt, StockOper oper)
        {
            if (oper == null)
            {
                return false;
            }

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

            if (!DailyStocks_.ContainsKey(dt))
            {
                return false;
            }

            IStockData stock = DailyStocks_[dt];
            return IsValidOperation(stock, oper);
        }
 public bool IsOperSuccess(DateTime dt, StockOper oper)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
 public bool IsOperSuccess(DateTime dt, StockOper oper)
 {
     throw new NotImplementedException();
 }
        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;
        }
Beispiel #18
0
        // �����Ʊ
        private void BuyStocks(StockOper oper)
        {
            BuyTransactionCount_++;
            double charge = Transaction.GetTotalCharge(oper.UnitPrice * oper.HandCount);

            if (bankRoll_ >= charge)
            {
                bankRoll_ -= charge;
                Holder.BuyStock(oper.HandCount, oper.UnitPrice);

                LogMgr.Logger.LogInfo("Action: Buy Stock Count: {0}, Unit Price: {1}",
                    oper.HandCount,
                    oper.UnitPrice);
            }
            else
            {
                throw new InvalidOperationException("Bank Roll is smaller than total price!");
            }
        }