Пример #1
0
        ///We remove identical lines
        public static List <IntradayTransfer> GetDataFromDb()
        {
            List <IntradayTransfer> intradayList = new List <IntradayTransfer>();
            double previousPrice = -999;

            using (var db = new ApplicationDbContext())
            {
                //3 - We add each item to our final list (26 first doesn;t contain RSI neither MACD calulation)
                foreach (var item in db.Intraday)
                {
                    if (item.P == previousPrice)
                    {
                        continue;
                    }
                    IntradayTransfer newIntraday = new IntradayTransfer()
                    {
                        Price = item.P,
                    };
                    intradayList.Add(newIntraday);
                    previousPrice = item.P;
                }
            }

            //Calculate change from next day to current day
            intradayList.Where((p, index) => CalculateFuture(p, index, intradayList)).ToList();

            //Add RSI calculation to the list
            TradeIndicator.CalculateRsiList(14, ref intradayList);
            TradeIndicator.CalculateMacdList(ref intradayList);

            return(intradayList.Skip(26).ToList());
        }
Пример #2
0
        private static bool CalculateFuture(IntradayTransfer p, int index, List <IntradayTransfer> intradayList)
        {
            ///Used to do mlti-classification alo / not working well
            // if (index > intradayList.Count - 4) return true;
            // int b1 = 0;
            // int b2 = 0;
            // if (intradayList[index + 1].Price - p.Price > 0) {b1 = 1;} else {b1 = -1;};
            // if (intradayList[index + 2].Price - intradayList[index + 1].Price > 0) {b2 = 1;} else {b2 = -1;};

            // if (b1 + b2 == 2)
            // {
            //     p.Future = 1;
            //     return true;
            // }

            // if (b1 + b2 == -2)
            // {
            //     p.Future = -1;
            //     return true;
            // }

            // p.Future = 0;
            // return true;

            // if (index > intradayList.Count - 4) return true;
            // int b1 = 0;
            // int b2 = 0;
            // if (intradayList[index + 1].Price - p.Price > 0) {b1 = 1;} else {b1 = -1;};
            // if (intradayList[index + 2].Price - intradayList[index + 1].Price > 0) {b2 = 1;} else {b2 = -1;};

            // if (b1 + b2 == 2)
            // {
            //     p.Future = 1;
            //     return true;
            // }

            // if (b1 + b2 == -2)
            // {
            //     p.Future = -1;
            //     return true;
            // }
            if (index < 1)
            {
                return(true);
            }
            if (index > intradayList.Count - 2)
            {
                return(true);
            }

            p.Future = intradayList[index - 1].Price - p.Price;
            return(true);
        }