Exemple #1
0
        /// <summary>
        /// Gets syrah term signals (short and long)
        /// </summary>
        /// <returns>Item1 - syrah short term signals, Item2 - syrah long term signals</returns>
        public Tuple <List <Signal>, List <Signal> > GetSentiments(List <HistoricalQuote> historicalQuotes2Years)
        {
            IIndicator     syrahSentimentShortTerm = new SyrahSentiment(SyrahSentiment.TermValue.ShortTerm);
            IIndicator     syrahSentimenLongTerm   = new SyrahSentiment(SyrahSentiment.TermValue.LongTerm);
            HistoricalData historicalData2Years    = new HistoricalData(historicalQuotes2Years);

            List <Signal> signals = _signalsProxyService.GetSignals(historicalData2Years,
                                                                    new List <IIndicator>
            {
                syrahSentimentShortTerm, syrahSentimenLongTerm
            }, null);
            List <Signal> syrahShortTermSignals = signals.ForIndicator(syrahSentimentShortTerm).OrderBy(signal => signal.Date).ToList();
            List <Signal> syrahLongTermSignals  = signals.ForIndicator(syrahSentimenLongTerm).OrderBy(signal => signal.Date).ToList();

            Tuple <List <Signal>, List <Signal> > result = new Tuple <List <Signal>, List <Signal> >(syrahShortTermSignals, syrahLongTermSignals);

            return(result);
        }
Exemple #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
            });
        }
        internal static TradeIdeasGeneratorArgument Create(List <Signal> signals, HistoricalData historicalData)
        {
            TradeIdeasGeneratorArgument result = new TradeIdeasGeneratorArgument();

            SmaVol smaVol20 = new SmaVol(20);
            Sma    sma50    = new Sma(50);
            Rsi    stRsi5   = new Rsi(5);
            Rsi    rsi14    = new Rsi(14);
            Rsi    ltrsi50  = new Rsi(50);
            Cci    stCci5   = new Cci(5);
            Cci    cci14    = new Cci(14);
            Cci    ltCci50  = new Cci(50);
            Stoch  stoch14  = new Stoch(14, 14, 3);
            WillR  willr14  = new WillR(14);
            Mfi    mfi14    = new Mfi(14);
            Adx    adx20    = new Adx(20);
            Atr    atr20    = new Atr(20);

            //Assuming that signals are sorted by dates descending and all signals are present. otherwize an exception will be thrown during fetching signals (First())

            #region Indicators

            result.Rsi14           = GetValue(signals.LatestForIndicator(rsi14));
            result.YesterdayRsi14  = GetValue(signals.PreviousForIndicator(rsi14, 1));
            result.StRsi5          = GetValue(signals.LatestForIndicator(stRsi5));
            result.YesterdayStRsi5 = GetValue(signals.PreviousForIndicator(stRsi5, 1));
            result.LtRsi50         = GetValue(signals.LatestForIndicator(ltrsi50));

            result.Cci14           = GetValue(signals.LatestForIndicator(cci14));
            result.YesterdayCci14  = GetValue(signals.PreviousForIndicator(cci14, 1));
            result.StCci5          = GetValue(signals.LatestForIndicator(stCci5));
            result.YesterdayStCci5 = GetValue(signals.PreviousForIndicator(stCci5, 1));
            result.LtCci50         = GetValue(signals.LatestForIndicator(ltCci50));

            result.Stoch14          = GetValue(signals.LatestForIndicator(stoch14));
            result.YesterdayStoch14 = GetValue(signals.PreviousForIndicator(stoch14, 1));

            result.WillR14          = GetValue(signals.LatestForIndicator(willr14));
            result.YesterdayWillR14 = GetValue(signals.PreviousForIndicator(willr14, 1));

            result.Mfi14          = GetValue(signals.LatestForIndicator(mfi14));
            result.YesterdayMfi14 = GetValue(signals.PreviousForIndicator(mfi14, 1));

            result.SmaVol20 = GetValue(signals.LatestForIndicator(smaVol20));
            result.Sma50    = GetValue(signals.LatestForIndicator(sma50));

            result.Adx20 = GetValue(signals.LatestForIndicator(adx20));

            result.Atr20 = GetValue(signals.LatestForIndicator(atr20));

            //Long Term Sentiment(6 months)
            Signal syrahSentiment = signals.LatestForIndicator(LongTermSentimentForDependencies);
            int?   sentimentValue = syrahSentiment == null
                ? null
                : (int?)syrahSentiment.Value;
            result.LongTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue);

            //Short Term Sentiment(1 month)
            syrahSentiment = signals.LatestForIndicator(ShortTermSentimentForDependencies);
            sentimentValue = syrahSentiment == null
                ? null
                : (int?)syrahSentiment.Value;
            result.ShortTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue);

            #endregion

            //if (expandedQuote == null)
            //{
            //    result.LastPrice = historicalData.Close[historicalData.Count - 1];
            //}
            //else
            //{
            //    result.LastPrice = expandedQuote.Last;
            //    result.HasOption = expandedQuote.HasOption;
            //}

            result.RangeStdDev = historicalData.GetPriceRangeStdDevFor6Months();

            //result.NearestSupport = supportAndResistance.GetClosestSupport(expandedQuote.Last);
            //result.NearestResistance = supportAndResistance.GetClosestResistance(expandedQuote.Last);

            //TODO: check
            int yesterdayIndex = historicalData.High.Length - 2;
            result.YesterdayHigh = historicalData.High[yesterdayIndex];
            result.YesterdayLow  = historicalData.Low[yesterdayIndex];

            return(result);
        }