public object GetSyrahSentiments(string stockCode)
        {
            List <HistoricalQuote> historicalQuotes2YearsResponse = _marketDataService.GetHistoricalQuotes(stockCode, "2y");

            List <Signal> syrahShortTermSignals;
            List <Signal> syrahLongTermSignals;

            int?sentimentShortTermValue = null;
            int?sentimentLongTermValue  = null;

            int?technicalRank = null;
            SupportAndResistance supportAndResistance = null;
            string sentence = string.Empty;

            Tuple <List <Signal>, List <Signal> > signals = _signalHelpers.GetSentiments(historicalQuotes2YearsResponse);

            syrahShortTermSignals = signals.Item1;
            syrahLongTermSignals  = signals.Item2;

            Tuple <int?, int?> sentimentTermValues = _signalHelpers.GetSentimentTermValues(syrahShortTermSignals, syrahLongTermSignals);

            sentimentShortTermValue = sentimentTermValues.Item1;
            sentimentLongTermValue  = sentimentTermValues.Item2;

            DateTime yearAgo = DateTime.UtcNow.Date.AddYears(-1);
            List <HistoricalQuote> historicalQuotes1Year = historicalQuotes2YearsResponse.Where(h => h.TradeDate >= yearAgo).ToList();
            HistoricalData         historicalData1Year   = null;

            if (!historicalQuotes1Year.IsNullOrEmpty())
            {
                historicalData1Year = new HistoricalData(historicalQuotes1Year);
            }

            StockQuoteInfo quote = _marketDataService.GetStockQuote(stockCode);

            technicalRank = _signalHelpers.GetTechnicalRank(historicalData1Year);
            var last = 0d;

            if (quote.LastPrice != null)
            {
                last = (double)quote.LastPrice.Value;
            }
            SupportAndResistanceMath srCalc = new SupportAndResistanceMath(historicalData1Year);

            supportAndResistance = srCalc.GetSupportAndResistance();
            return(new
            {
                quote = quote,
                technicalRank = technicalRank,
                supportAndResistance = supportAndResistance,
                sentimentShortTermValue = sentimentShortTermValue,
                sentimentLongTermValue = sentimentLongTermValue,
                syrahShortTermSignals = syrahShortTermSignals,
                syrahLongTermSignals = syrahLongTermSignals,
                historicalQuotes2Years = historicalQuotes2YearsResponse
            });
        }
Esempio n. 2
0
        private SentimentViewModel GetPartWhy(string stockCode)
        {
            List <HistoricalQuote> historicalQuotes2YearsResponse = _marketDataService.GetHistoricalQuotes(stockCode, "2y");

            List <Signal> syrahShortTermSignals;
            List <Signal> syrahLongTermSignals;

            int?sentimentShortTermValue = null;
            int?sentimentLongTermValue  = null;

            Sentiment?sentiment = null;

            if (historicalQuotes2YearsResponse.Count == 0)
            {
                return(new SentimentViewModel()
                {
                    Sentiment = sentiment,
                    Signal = stockCode
                });
            }

            Tuple <List <Signal>, List <Signal> > signals = _signalHelpers.GetSentiments(historicalQuotes2YearsResponse);

            syrahShortTermSignals = signals.Item1;
            syrahLongTermSignals  = signals.Item2;

            Tuple <int?, int?> sentimentTermValues = _signalHelpers.GetSentimentTermValues(syrahShortTermSignals, syrahLongTermSignals);

            sentimentShortTermValue = sentimentTermValues.Item1;
            sentimentLongTermValue  = sentimentTermValues.Item2;

            Tuple <int?, int?> sentimentValues = new Tuple <int?, int?>(sentimentShortTermValue, sentimentLongTermValue);

            sentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValues);

            //return new { sentiment, stockCode };
            return(new SentimentViewModel()
            {
                Sentiment = sentiment,
                Signal = stockCode
            });
        }