public OperType Analyse(IStockData prevStock, IStockData stock, IStockData nextStock)
        {
            if ((stock == null) || (prevStock == null) || (nextStock == null))
            {
                return(OperType.NoOper);
            }

            double deltapercent = StockDataCalc.GetRisePercent(stock);
            //double prevPercent = StockDataCalc.GetRisePercent(prevStock);
            double nextPercent = StockDataCalc.GetRisePercent(nextStock);

            if (NumbericHelper.IsSameSign(deltapercent, nextPercent))
            {
                return(OperType.NoOper);
            }

            if ((nextPercent > 0.03) && (nextStock.EndPrice > prevStock.StartPrice) &&
                (nextStock.EndPrice > stock.StartPrice))
            {
                return(OperType.Buy);
            }

            if ((nextPercent < -0.03) && (nextStock.EndPrice < prevStock.StartPrice) &&
                (nextStock.EndPrice < stock.StartPrice))
            {
                return(OperType.Sell);
            }

            return(OperType.NoOper);
        }
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            prevStock_ = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return false;
            }

            double typicalPrice = CalcTypicalPrice(currentStock_);
            bool isUp = StockJudger.IsRise(currentStock_, prevStock_);
            AddTodayPrice(typicalPrice * currentStock_.Amount, isUp); // 直接保存Money Flow, 即Typical Price * Volume

            if (PriceUpDowns_.Count < MFICALCDAYS)
            {
                return false;
            }

            CalculateMFI();
            return true;
        }
        public OperType Analyse(IStockData prevStock, IStockData stock, IStockData nextStock)
        {
            if ((stock == null) || (prevStock == null) || (nextStock == null))
            {
                return OperType.NoOper;
            }

            double deltapercent = StockDataCalc.GetRisePercent(stock);
            //double prevPercent = StockDataCalc.GetRisePercent(prevStock);
            double nextPercent = StockDataCalc.GetRisePercent(nextStock);

            if (NumbericHelper.IsSameSign(deltapercent, nextPercent))
            {
                return OperType.NoOper;
            }

            if ((nextPercent > 0.03) && (nextStock.EndPrice > prevStock.StartPrice)
                && (nextStock.EndPrice > stock.StartPrice))
            {
                return OperType.Buy;
            }

            if ((nextPercent < -0.03) && (nextStock.EndPrice < prevStock.StartPrice)
                 && (nextStock.EndPrice < stock.StartPrice))
            {
                return OperType.Sell;
            }

            return OperType.NoOper;
        }
Example #4
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }

            stocks_.Add(sd);

            if (!stocks_.IsEnough())
            {
                return(false);
            }

            if (Judger_.FulFil(stocks_.GetAt(0), stocks_.GetAt(1), stocks_.GetAt(2)))
            {
                TodayOper_ = OperType.Sell;
            }
            else if (Judger_.ReverseFulFil(stocks_.GetAt(0), stocks_.GetAt(1), stocks_.GetAt(2)))
            {
                TodayOper_ = OperType.Buy;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }

            return(true);
        }
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            slopeCalc.AddVal(sd.EndPrice);
            if (!slopeCalc.IsEnough())
            {
                return false;
            }

            if (slopeCalc.IsDownPeriod() && ShapeJudger.IsUpCross(sd))
            {
                TodayOper_ = OperType.Buy;
            }
            else if (slopeCalc.IsRisePeriod() && ShapeJudger.IsDownCross(sd))
            {
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }
            return true;
        }
Example #6
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }

            slopeCalc.AddVal(sd.EndPrice);
            if (!slopeCalc.IsEnough())
            {
                return(false);
            }

            if (slopeCalc.IsDownPeriod() && ShapeJudger.IsUpCross(sd))
            {
                TodayOper_ = OperType.Buy;
            }
            else if (slopeCalc.IsRisePeriod() && ShapeJudger.IsDownCross(sd))
            {
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }
            return(true);
        }
Example #7
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }

            prevStock_    = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return(false);
            }

            EngulfingType et = JudgeEngulfing(prevStock_, currentStock_);

            if (et == EngulfingType.RED_ENGULFING)
            {
                TodayOper_ = OperType.Buy;
            }
            else if (et == EngulfingType.GREEN_ENGULFING)
            {
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }
            return(true);
        }
Example #8
0
        public string ParseChars(IStockData prevData, IStockData todayData)
        {
            if (todayData == null)
            {
                throw new ArgumentNullException();
            }

            double priseRatio = 0.0;

            if (prevData != null)
            {
                priseRatio = (todayData.StartPrice - prevData.EndPrice) / prevData.EndPrice;
            }

            if (todayData.AllPriceSame && (priseRatio < MINIMUM_RATIO))
            {
                // 处理停牌的情况
                return("");
            }

            double upRatio   = (todayData.MaxPrice - todayData.StartPrice) / todayData.StartPrice;
            double downRatio = (todayData.MinPrice - todayData.StartPrice) / todayData.StartPrice;
            double endRatio  = (todayData.EndPrice - todayData.StartPrice) / todayData.StartPrice;

            string todayMapping = GetRatioString(priseRatio) + GetRatioString(upRatio)
                                  + GetRatioString(downRatio) + GetRatioString(endRatio);

            return(todayMapping);
        }
Example #9
0
        public OperType Analyse(IStockData stock, IStockData prevStock)
        {
            if ((stock == null) || (prevStock == null))
            {
                return OperType.NoOper;
            }

            double deltapercent = StockDataCalc.GetRisePercent(stock);

            double prevPercent = StockDataCalc.GetRisePercent(prevStock);

            // Only for converse
            if (NumbericHelper.IsSameSign(deltapercent, prevPercent))
            {
                return OperType.NoOper;
            }

            // ratio should be larger than yesterday
            if (Math.Abs(deltapercent) < Math.Abs(prevPercent))
            {
                return OperType.NoOper;
            }

            if ((deltapercent > 0.02) && (stock.EndPrice > prevStock.StartPrice))
            {
                return OperType.Buy;
            }

            if ((deltapercent < -0.02) && (stock.EndPrice < prevStock.StartPrice))
            {
                return OperType.Sell;
            }

            return OperType.NoOper;
        }
Example #10
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }

            if (!Averager_.IsEnough())
            {
                Averager_.AddVal(sd.Amount);
                return(false);
            }

            double avgMinAmount = Averager_.GetValue() * (1 - BuyMargin_);
            double avgMaxAmount = Averager_.GetValue() * (1 + SellMargin_);

            if (sd.Amount < avgMinAmount)
            {
                // 成交地量,买入
                TodayOper_ = OperType.Buy;
            }
            else if (sd.Amount > avgMaxAmount)
            {
                // 成交天量,卖出
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }

            Averager_.AddVal(sd.Amount);
            return(true);
        }
Example #11
0
        public string GetCharMapping(IStockHistory hist)
        {
            string   totalMapping = "";
            DateTime startDate    = hist.MinDate;
            DateTime endDate      = hist.MaxDate;

            while (startDate < endDate)
            {
                IStockData todayData = hist.GetStock(startDate);
                IStockData pervData  = hist.GetPrevDayStock(startDate);

                if (todayData == null)
                {
                    startDate = DateFunc.GetNextWorkday(startDate);
                    continue;
                }

                string s = ParseChars(pervData, todayData);

                if (!string.IsNullOrEmpty(s))
                {
                    totalMapping += s + "|";
                }

                startDate = DateFunc.GetNextWorkday(startDate);
            }

            return(totalMapping);
        }
        public IEnumerable <IStockData> GetHistoricData(string symbol, DateTime startDate, DateTime endDate)
        {
            IReadOnlyList <Candle> historicData = _yahooFinanceApiManager.GetSecurityHistoricData(symbol, startDate, endDate);

            if (historicData == null)
            {
                _logger.Error($"No data retrieved from Api manager for symbol: {symbol}");
                return(Enumerable.Empty <IStockData>());
            }

            List <Candle> orderedHistoricData = historicData.OrderBy(x => x.DateTime).ToList();
            var           historicStockData   = new List <IStockData>();

            IStockData initialData = _securityDataFactory.GetStockData(symbol, orderedHistoricData[0], null);

            historicStockData.Add(initialData);
            for (int i = 1; i < orderedHistoricData.Count; i++)
            {
                //if(!IsValid(orderedHistoricData[i]))
                //{
                //    _logger.Error($"Data point not valid - index: {i} Date: {orderedHistoricData[i].DateTime.ToString("yyyy-MM-dd")}");
                //    continue;
                //}

                decimal?   previousClose = orderedHistoricData[i - 1].Close == 0 ? null : (decimal?)orderedHistoricData[i - 1].Close;
                IStockData stockData     = _securityDataFactory.GetStockData(symbol, orderedHistoricData[i], previousClose);
                historicStockData.Add(stockData);
            }

            return(historicStockData);
        }
Example #13
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            if (!Averager_.IsEnough())
            {
                Averager_.AddVal(sd.Amount);
                return false;
            }

            double avgMinAmount = Averager_.GetValue() * (1 - BuyMargin_);
            double avgMaxAmount = Averager_.GetValue() * (1 + SellMargin_);

            if (sd.Amount < avgMinAmount)
            {
                // 成交地量,买入
                TodayOper_ = OperType.Buy;
            }
            else if (sd.Amount > avgMaxAmount)
            {
                // 成交天量,卖出
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }

            Averager_.AddVal(sd.Amount);
            return true;
        }
Example #14
0
        // 添加某一天的股票信息
        public void AddDayStock(DateTime dt, IStockData stock)
        {
            StockPoint pt = new StockPoint(dt, stock.MaxPrice, stock.MinPrice,
                                           stock.StartPrice, stock.EndPrice, stock.VolumeHand);

            _Stocks.Add(dt, pt);
        }
Example #15
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }
            prevStock_    = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return(false);
            }

            if (ShapeJudger.IsT2(currentStock_, DeltaRatio_) && VolumeHelper.IsLargerThan(currentStock_, prevStock_, 0.3))
            {
                TodayOper_ = OperType.Buy;
            }
            else if (ShapeJudger.IsReverseT2(currentStock_, DeltaRatio_))
            {
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }

            return(true);
        }
Example #16
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            stocks_.Add(sd);

            if (!stocks_.IsEnough())
            {
                return false;
            }

            if (Judger_.FulFil(stocks_.GetAt(0), stocks_.GetAt(1), stocks_.GetAt(2)))
            {
                TodayOper_ = OperType.Sell;
            }
            else if (Judger_.ReverseFulFil(stocks_.GetAt(0), stocks_.GetAt(1), stocks_.GetAt(2)))
            {
                TodayOper_ = OperType.Buy;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }

            return true;
        }
Example #17
0
        public OperType Analyse(IStockData stock, IStockData prevStock)
        {
            if ((stock == null) || (prevStock == null))
            {
                return(OperType.NoOper);
            }

            double deltapercent = StockDataCalc.GetRisePercent(stock);

            double prevPercent = StockDataCalc.GetRisePercent(prevStock);

            // Only for converse
            if (NumbericHelper.IsSameSign(deltapercent, prevPercent))
            {
                return(OperType.NoOper);
            }

            // ratio should be larger than yesterday
            if (Math.Abs(deltapercent) < Math.Abs(prevPercent))
            {
                return(OperType.NoOper);
            }

            if ((deltapercent > 0.02) && (stock.EndPrice > prevStock.StartPrice))
            {
                return(OperType.Buy);
            }

            if ((deltapercent < -0.02) && (stock.EndPrice < prevStock.StartPrice))
            {
                return(OperType.Sell);
            }

            return(OperType.NoOper);
        }
Example #18
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }

            prevStock_    = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return(false);
            }

            double typicalPrice = CalcTypicalPrice(currentStock_);
            bool   isUp         = StockJudger.IsRise(currentStock_, prevStock_);

            AddTodayPrice(typicalPrice * currentStock_.Amount, isUp); // 直接保存Money Flow, 即Typical Price * Volume

            if (PriceUpDowns_.Count < MFICALCDAYS)
            {
                return(false);
            }

            CalculateMFI();
            return(true);
        }
Example #19
0
        public string CalcUpTemplate()
        {
            if (!IsWholeWeek())
            {
                return("");
            }

            string s = "";

            IStockData stock1 = dayToStocks_[DayOfWeek.Monday];

            s += GetUpDescription(stock1);
            IStockData stock2 = dayToStocks_[DayOfWeek.Tuesday];

            s += GetUpDescription(stock2);
            IStockData stock3 = dayToStocks_[DayOfWeek.Wednesday];

            s += GetUpDescription(stock3);
            IStockData stock4 = dayToStocks_[DayOfWeek.Thursday];

            s += GetUpDescription(stock4);
            IStockData stock5 = dayToStocks_[DayOfWeek.Friday];

            s += GetUpDescription(stock5);

            return(s);
        }
Example #20
0
        /// <summary>
        /// Add each stock data of a stock history
        /// </summary>
        /// <param name="dt">Stock data of one day</param>
        public void AddStockData(IStockData dt)
        {
            if (dt == null)
            {
                return;
            }

            DateTime dtFromBinary = DateTime.FromBinary(dt.TradeDateBinary);
            DateTime localDate = DateFunc.ConvertToLocal(dtFromBinary);
            int week = calendar_.GetWeekOfYear(localDate, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);

            int weekId = MakeWeekId(localDate.Year, week);

            if (Results_.ContainsKey(weekId))
            {
                Results_[weekId].AddStockData(dt);
            }
            else
            {
                WeeklyResult res = new WeeklyResult();
                res.AddStockData(dt);

                Results_.Add(weekId, res);
            }
        }
Example #21
0
        /// <summary>
        /// Categorized stock performance by each day of one week
        /// </summary>
        /// <param name="log">logger for output results</param>
        public void AnalyzeEachDayOfOneWeek(ICustomLog log)
        {
            StockWeekData mondaydata    = new StockWeekData();
            StockWeekData tuesdaydata   = new StockWeekData();
            StockWeekData wednesdaydata = new StockWeekData();
            StockWeekData thursdaydata  = new StockWeekData();
            StockWeekData fridaydata    = new StockWeekData();

            foreach (WeeklyResult res in Results_.Values)
            {
                IStockData sdMonday    = res.GetStockData(DayOfWeek.Monday);
                IStockData sdTuesday   = res.GetStockData(DayOfWeek.Tuesday);
                IStockData sdWednesday = res.GetStockData(DayOfWeek.Wednesday);
                IStockData sdThursday  = res.GetStockData(DayOfWeek.Thursday);
                IStockData sdFriday    = res.GetStockData(DayOfWeek.Friday);

                mondaydata.AddStockData(sdMonday);
                tuesdaydata.AddStockData(sdTuesday);
                wednesdaydata.AddStockData(sdWednesday);
                thursdaydata.AddStockData(sdThursday);
                fridaydata.AddStockData(sdFriday);
            }

            log.LogInfo("Monday up percent: " + mondaydata.CalcUpPercent().ToString("F03")
                        + ", Days = " + mondaydata.TotalDays);
            log.LogInfo("Tuesday up percent: " + tuesdaydata.CalcUpPercent().ToString("F03")
                        + ", Days = " + tuesdaydata.TotalDays);
            log.LogInfo("Wednesday up percent: " + wednesdaydata.CalcUpPercent().ToString("F03")
                        + ", Days = " + wednesdaydata.TotalDays);
            log.LogInfo("Thursday up percent: " + thursdaydata.CalcUpPercent().ToString("F03")
                        + ", Days = " + thursdaydata.TotalDays);
            log.LogInfo("Friday up percent: " + fridaydata.CalcUpPercent().ToString("F03")
                        + ", Days = " + fridaydata.TotalDays);
        }
Example #22
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);
        }
Example #23
0
        public void StockChangeTest()
        {
            // 8 chips were bought, 50 were there at the start
            IStockData stock = (IStockData)sut.Stock;

            Assert.Equal(42, stock.GetProductQuantity("chips"));
        }
Example #24
0
        static EngulfingType JudgeEngulfing(IStockData prevStock, IStockData todayStock)
        {
            if ((prevStock == null) || (todayStock == null))
            {
                return EngulfingType.NOT_ENGULFING;
            }

            if ((todayStock.MinPrice < prevStock.MinPrice)
                && (todayStock.MaxPrice > prevStock.MaxPrice))
            {
                if ((StockDataCalculator.GetRiseRatio(todayStock) > 0.01)
                    && StockDataCalculator.IsDifferentRiseDown(prevStock, todayStock))
                {
                    return EngulfingType.RED_ENGULFING;
                }
                else if ((StockDataCalculator.GetRiseRatio(todayStock) < -0.01)
                    && StockDataCalculator.IsDifferentRiseDown(prevStock, todayStock))
                {
                    return EngulfingType.GREEN_ENGULFING;
                }
                else
                {
                    return EngulfingType.NOT_ENGULFING;
                }
            }
            else
            {
                return EngulfingType.NOT_ENGULFING;
            }
        }
Example #25
0
        /// <summary>
        /// Add each stock data of a stock history
        /// </summary>
        /// <param name="dt">Stock data of one day</param>
        public void AddStockData(IStockData dt)
        {
            if (dt == null)
            {
                return;
            }

            DateTime dtFromBinary = DateTime.FromBinary(dt.TradeDateBinary);
            DateTime localDate    = DateFunc.ConvertToLocal(dtFromBinary);
            int      week         = calendar_.GetWeekOfYear(localDate, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);

            int weekId = MakeWeekId(localDate.Year, week);

            if (Results_.ContainsKey(weekId))
            {
                Results_[weekId].AddStockData(dt);
            }
            else
            {
                WeeklyResult res = new WeeklyResult();
                res.AddStockData(dt);

                Results_.Add(weekId, res);
            }
        }
Example #26
0
        static EngulfingType JudgeEngulfing(IStockData prevStock, IStockData todayStock)
        {
            if ((prevStock == null) || (todayStock == null))
            {
                return(EngulfingType.NOT_ENGULFING);
            }

            if ((todayStock.MinPrice < prevStock.MinPrice) &&
                (todayStock.MaxPrice > prevStock.MaxPrice))
            {
                if ((StockDataCalculator.GetRiseRatio(todayStock) > 0.01) &&
                    StockDataCalculator.IsDifferentRiseDown(prevStock, todayStock))
                {
                    return(EngulfingType.RED_ENGULFING);
                }
                else if ((StockDataCalculator.GetRiseRatio(todayStock) < -0.01) &&
                         StockDataCalculator.IsDifferentRiseDown(prevStock, todayStock))
                {
                    return(EngulfingType.GREEN_ENGULFING);
                }
                else
                {
                    return(EngulfingType.NOT_ENGULFING);
                }
            }
            else
            {
                return(EngulfingType.NOT_ENGULFING);
            }
        }
Example #27
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            prevStock_ = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return false;
            }

            EngulfingType et = JudgeEngulfing(prevStock_, currentStock_);

            if (et == EngulfingType.RED_ENGULFING)
            {
                TodayOper_ = OperType.Buy;
            }
            else if (et == EngulfingType.GREEN_ENGULFING)
            {
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }
            return true;
        }
Example #28
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);
        }
Example #29
0
        public void StudentOfficeBalanceChangeTest()
        {
            // Office balance was 237.5 before the sell
            IStockData stock = (IStockData)sut.Stock;

            Assert.Equal(251m, stock.CurrentBalance);
        }
        public string ParseChars(IStockData prevData, IStockData todayData)
        {
            if (todayData == null)
            {
                throw new ArgumentNullException();
            }

            double priseRatio = 0.0;
            if (prevData != null)
            {
                priseRatio = (todayData.StartPrice - prevData.EndPrice) / prevData.EndPrice;
            }

            if (todayData.AllPriceSame && (priseRatio < MINIMUM_RATIO))
            {
                // 处理停牌的情况
                return "";
            }

            double upRatio = (todayData.MaxPrice - todayData.StartPrice) / todayData.StartPrice;
            double downRatio = (todayData.MinPrice - todayData.StartPrice) / todayData.StartPrice;
            double endRatio = (todayData.EndPrice - todayData.StartPrice) / todayData.StartPrice;

            string todayMapping = GetRatioString(priseRatio) + GetRatioString(upRatio)
                + GetRatioString(downRatio) + GetRatioString(endRatio);

            return todayMapping;
        }
Example #31
0
        // ���ijһ��Ĺ�Ʊ��Ϣ
        public void AddDayStock(DateTime dt, IStockData stock)
        {
            StockPoint pt = new StockPoint(dt, stock.MaxPrice, stock.MinPrice,
                stock.StartPrice, stock.EndPrice, stock.VolumeHand);

            _Stocks.Add(dt, pt);
        }
Example #32
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            prevStock_ = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return false;
            }

            AddTodayPrice(sd.EndPrice, StockJudger.IsRise(sd, prevStock_));

            if (Prices_.Count < RSICALCDAYS)
            {
                return false;
            }

            double rsi = CalculateRSI();

            AnalyseOperation(rsi);
            return true;
        }
Example #33
0
 public CashRegisterService(IMapper mapper, IStockService stockService, IStockData stockData)
 {
     this.mapper       = mapper;
     this.stockService = stockService;
     this.stockData    = stockData;
     result            = new ResultVM();
 }
Example #34
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return(false);
            }

            prevStock_    = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return(false);
            }

            AddTodayPrice(sd.EndPrice, StockJudger.IsRise(sd, prevStock_));

            if (Prices_.Count < RSICALCDAYS)
            {
                return(false);
            }

            double rsi = CalculateRSI();

            AnalyseOperation(rsi);
            return(true);
        }
Example #35
0
        // 指令为前一日最低值买入,赚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);
        }
Example #36
0
        public CpuSimulation(IStockData stockData, int holding = 10, float ann = 5.0990f)
        {
            _stockData = stockData;
            _holding   = holding;
            _ann       = ann;

            _returns = new float[stockData.StocksCount, stockData.QuotesPerStock - holding];
        }
 public StockService(IStockData stockData,
                     IConnectionService connectionService,
                     IMarketDataService marketDataService)
 {
     _stockData         = stockData;
     _connectionService = connectionService;
     _marketDataService = marketDataService;
 }
Example #38
0
        public static bool IsT2(IStockData data, double ratio)
        {
            double deltaEndMin = (data.EndPrice - data.MinPrice) / data.MinPrice;
            double deltaStartMax = (data.MaxPrice - data.StartPrice) / data.StartPrice;
            double deltaEndMax = (data.MaxPrice - data.EndPrice) / data.EndPrice;

            return ((deltaEndMin >= ratio)
                && (deltaStartMax <= (ratio / 4)) && (deltaEndMax <= (ratio / 4)));
        }
Example #39
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);
        }
Example #40
0
        public static bool IsReverseT2(IStockData data, double ratio)
        {
            double deltaEndMax   = (data.MaxPrice - data.EndPrice) / data.EndPrice;
            double deltaStartMin = (data.StartPrice - data.MinPrice) / data.MinPrice;
            double deltaEndMin   = (data.EndPrice - data.MinPrice) / data.MinPrice;

            return((deltaEndMax >= ratio) &&
                   (deltaStartMin <= ratio / 4) && (deltaEndMin <= ratio / 4));
        }
Example #41
0
        public static bool IsDownCross(IStockData data)
        {
            double deltapercent = StockDataCalc.GetRisePercent(data);
            bool isCross = ((Math.Abs(deltapercent) < CROSSDELTAPERCENT)
                && (data.MaxPrice > data.StartPrice)
                && (data.MinPrice < data.EndPrice));

            return isCross && (data.EndPrice < data.StartPrice);
        }
Example #42
0
        public static bool IsDownCross(IStockData data)
        {
            double deltapercent = StockDataCalc.GetRisePercent(data);
            bool   isCross      = ((Math.Abs(deltapercent) < CROSSDELTAPERCENT) &&
                                   (data.MaxPrice > data.StartPrice) &&
                                   (data.MinPrice < data.EndPrice));

            return(isCross && (data.EndPrice < data.StartPrice));
        }
Example #43
0
        public void NotifyingTest()
        {
            // Test of the notifying : stock was at 42, 35 are sold, 40 are ordered
            IStockData stock = (IStockData)sut.Stock;

            sut.SellProduct(john, new Order(ProductGenerator.chips, 35));

            Assert.Equal(47, stock.GetProductQuantity("chips"));
        }
Example #44
0
 public StateOfStudentOffice(
     Dictionary <Client, decimal> clients,
     IStockData stock,
     List <Transaction> transactions)
 {
     _clientsSnapshot      = clients;
     _stockSnapshot        = stock;
     _transactionsSnapshot = transactions;
 }
Example #45
0
        public bool AddStock(IStockData sd)
        {
            bool totalResult = true;
            foreach (ISignalCalculator calc in IndicatorsArr_)
            {
                totalResult = totalResult && calc.AddStock(sd);
            }

            return totalResult;
        }
Example #46
0
 private bool IsWin(IStockData daystock)
 {
     if (HolderManager.Instance().Holder.HasStock())
     {
         return (daystock.EndPrice >= HolderManager.Instance().Holder.UnitPrice);
     }
     else
     {
         return true;
     }
 }
Example #47
0
        public bool AddStock(IStockData sd)
        {
            currentStatus_ = Alg_.AddValue(sd.EndPrice);

            if (currentStatus_)
            {
                macdValues_.AddValue(Alg_.GetMacd());
            }

            return true;
        }
Example #48
0
 protected static bool CheckStock(IStockData stock, DateTime day)
 {
     if (stock == null)
     {
         StrategyLog.DebugFormat("ERROR: Cannot find Stock Property of date: {0}!", day.ToShortDateString());
         return false;
     }
     else
     {
         return true;
     }
 }
        public static bool IsDifferentRiseDown(IStockData sd1, IStockData sd2)
        {
            if (IsRise(sd1) && IsDown(sd2))
            {
                return true;
            }
            else if (IsDown(sd1) && IsRise(sd2))
            {
                return true;
            }

            return false;
        }
Example #50
0
        public static bool IsCross(IStockData data)
        {
            double deltapercent = StockDataCalc.GetRisePercent(data);

            double riseRatio = StockDataCalc.GetRisePercent(data.StartPrice, data.MaxPrice);
            double downRatio = StockDataCalc.GetRisePercent(data.StartPrice, data.MinPrice);
            double swingRatio = riseRatio      + downRatio;
            return ((Math.Abs(deltapercent) < CROSSDELTAPERCENT)
                && (data.MaxPrice > data.StartPrice)
                && (data.MinPrice < data.EndPrice)
                && (swingRatio < CROSSDELTAPERCENT)
                && (riseRatio > CROSSSWINGPERCENT));
        }
Example #51
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            if (PreviousStock_ == null)
            {
                PreviousStock_ = sd;
                FirstDaySetted = true;
            }

            return true;
        }
Example #52
0
        public void AddStock(DateTime dt, IStockData stock)
        {
            if (!DailyStocks_.ContainsKey(dt))
            {
                DailyStocks_.Add(dt, stock);
            }
            else
            {
                // ???
                // 2009-08-25
            }

            MinDate = (MinDate > dt) ? dt : MinDate;
            MaxDate = (MaxDate < dt) ? dt : MaxDate;
        }
Example #53
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            stocks_.Add(sd);

            if (!stocks_.IsEnough())
            {
                return false;
            }

            TodayOper_ = Scanner_.Analyse(stocks_.GetAt(0), stocks_.GetAt(1), stocks_.GetAt(2));
            return true;
        }
Example #54
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }
            prevStock_ = currentStock_;
            currentStock_ = sd;

            if ((prevStock_ == null) || (currentStock_ == null))
            {
                return false;
            }

            TodayOper_ = Scanner_.Analyse(currentStock_, prevStock_);
            return true;
        }
Example #55
0
        public StockPresenter(IStockView stockView, IStockData stockData)
        {
            if (stockView == null)
            {
                throw new ArgumentNullException(nameof(stockView));
            }

            if (stockData == null)
            {
                throw new ArgumentNullException(nameof(stockData));
            }

            this.stockView = stockView;
            this.stockData = stockData;
            this.stockView.BuyClickAction += this.OnBuyClickAction;
            this.stockView.FindClickAction += this.OnFindClickAction;
        }
Example #56
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }

            prevStock_ = currentStock_;
            currentStock_ = sd;

            if (prevStock_ == null)
            {
                return false;
            }

            TodayOper_ = Rule_.Execute(currentStock_.EndPrice, prevStock_.EndPrice);
            return true;
        }
Example #57
0
        void CalculateSignal(DateTime dt, IStockData stock)
        {
            if (stock == null)
            {
                return;
            }

            if (!signalCalc_.AddStock(stock))
            {
                return;
            }

            OperType ot = signalCalc_.GetSignal();
            if (ot != OperType.NoOper)
            {
                DateToOpers_.Add(dt, ot);
            }
        }
Example #58
0
        public bool AddStock(IStockData sd)
        {
            if (sd == null)
            {
                return false;
            }
            if (ShapeJudger.IsT2(sd, DeltaRatio_))
            {
                TodayOper_ = OperType.Buy;
            }
            else if (ShapeJudger.IsReverseT2(sd, DeltaRatio_))
            {
                TodayOper_ = OperType.Sell;
            }
            else
            {
                TodayOper_ = OperType.NoOper;
            }

            return true;
        }
        public bool AddStock(IStockData sd)
        {
            prediction_.AddPrice(sd.EndPrice);

            if (!prediction_.IsCountEnough())
            {
                return false;
            }

            // 长周期日线和短周期日线
            double longEMA = prediction_.GetLongAverage();
            double shortEMA = prediction_.GetShortAverage();

            double diff = shortEMA - longEMA; // 短周期均值-长周期均值

            if (double.IsNaN(previousMA_))
            {
                previousMA_ = diff;
                return false;
            }

            TodayOper_ = OperType.NoOper;
            if (previousMA_ < 0)
            {
                if (prediction_.CalcNextPredictionValue() > 0)
                {
                    TodayOper_ = OperType.Buy;
                }
            }
            else if (previousMA_ > 0)
            {
                if (prediction_.CalcNextPredictionValue() < 0)
                {
                    TodayOper_ = OperType.Sell;
                }
            }

            previousMA_ = diff;
            return true;
        }
 public StockEngine(IStockData data, IClock clock)
 {
     this.Data = data;
     this.Clock = clock;
 }