/// <summary> /// Gets signals interpretation based on symbol, list of indicators and timeframe /// </summary> public async Task <List <SignalInterpretation> > GetSignalsInterpretation(string symbol, List <IIndicator> indicators, DateTime?forDate = null) { // todo: calculate timeFrame based on forDate parameter List <HistoricalQuote> historicalQuotes = MarketDataService.GetHistoricalQuotes(symbol); if (historicalQuotes.IsNullOrEmpty()) { return(null); } HistoricalData historicalData = new HistoricalData(historicalQuotes); DependencyScope dependencyScope = indicators.GetDependencies(); StockQuoteInfo quote = null; if (dependencyScope.IsQuoteNeeded) { quote = MarketDataService.GetStockQuote(historicalData.SecurityCode).Entity; } List <SignalInterpretation> interpretations = GetSignalsInterpretation(historicalData, indicators, quote, forDate); return(interpretations); }
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 }); }
public static bool IsEquals(this StockQuoteInfo stockQuote1, StockQuoteInfo stockQuote2) { foreach (PropertyInfo significantProperty in SignificantProperties) { object value1 = significantProperty.GetValue(stockQuote1); object value2 = significantProperty.GetValue(stockQuote2); if ((value1 == null && value2 != null) || (value1 != null && value2 == null) || (value1 != null && !value1.Equals(value2))) { return(false); } } return(true); }
//todo: not sure if we need entity response here public async Task <EntityResponse <SupportAndResistance> > GetSupportAndResistance(string symbol, string timeFrame = null) { if (timeFrame == null) { timeFrame = AppConfigManager.SupportAndResistanceDefaultTimeFrame; } StockQuoteInfo expandedQuote = MarketDataService.GetStockQuote(symbol); List <HistoricalQuote> historicalQuotes = MarketDataService.GetHistoricalQuotes(symbol, timeFrame); SupportAndResistance supportAndResistance = new SupportAndResistanceMath(new HistoricalData(historicalQuotes)).GetSupportAndResistance(); return(supportAndResistance); }
public async Task <string> GetEnglishRepresentationOfSignals(string symbol, string timeFrame = null) { if (timeFrame == null) { timeFrame = AppConfigManager.SupportAndResistanceDefaultTimeFrame; } StockQuoteInfo expandedQuote = MarketDataService.GetStockQuote(symbol); List <HistoricalQuote> historicalQuotes = MarketDataService.GetHistoricalQuotes(symbol, timeFrame); if (historicalQuotes.IsNullOrEmpty()) { return(null); } string representation = null; //SentenceGenerator.GetSummary(new HistoricalData(historicalQuotes), expandedQuote); return(representation); }
public static void AddOrUpdateStockQuoteInfoCache(string underlying, StockQuoteInfo info) { if (underlying == null) { return; } if (MemoryCache.StockQuoteInfoCache.ContainsKey(underlying)) { MemoryCache.StockQuoteInfoCache[underlying].StockQuoteInfos = info; MemoryCache.StockQuoteInfoCache[underlying].StockQuoteInfoLastUpdate = DateTime.UtcNow; } else { ListStockQuoteInfo lsqi = new ListStockQuoteInfo { StockQuoteInfoLastUpdate = DateTime.UtcNow, StockQuoteInfos = info }; MemoryCache.StockQuoteInfoCache.Add(underlying, lsqi); } }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null) { Signal roc = signals.LatestForIndicator(this); if (roc == null) { return(null); } double rocD = roc.Value; switch (AvgPeriod) { case 20: result = new SignalInterpretation(this); if (rocD < -8) { result.Interpretation = SignalInterpretationValue.Oversold; } else if (rocD >= -8 && rocD < 0) { result.Interpretation = SignalInterpretationValue.Bearish; } else if (rocD.Equals(0)) { result.Interpretation = SignalInterpretationValue.Neutral; } else if (rocD > 0 && rocD < 8) { result.Interpretation = SignalInterpretationValue.Bullish; } else { result.Interpretation = SignalInterpretationValue.Overbought; } break; case 125: result = new SignalInterpretation(this); if (rocD < 0) { result.Interpretation = SignalInterpretationValue.Bearish; } else if (rocD.Equals(0)) { result.Interpretation = SignalInterpretationValue.Neutral; } else { result.Interpretation = SignalInterpretationValue.Bullish; } break; } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { if (signals == null) { return(null); } Signal signal = signals.FirstOrDefault(x => x.Name == Name); if (signal == null) { return(null); } SignalInterpretation result = new SignalInterpretation(this); double willrValue = signal.Value; if (willrValue >= -20) { result.Interpretation = SignalInterpretationValue.Overbought; } else if (willrValue > -80 && willrValue < -20) { result.Interpretation = SignalInterpretationValue.Neutral; } else { result.Interpretation = SignalInterpretationValue.Oversold; } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null) { Signal mfi = signals.LatestForIndicator(this); if (mfi != null) { double mfiD = mfi.Value; result = new SignalInterpretation(this); if (mfiD <= 10) { result.Interpretation = SignalInterpretationValue.OversoldUnsustainable; } else if (mfiD > 10 && mfiD <= 20) { result.Interpretation = SignalInterpretationValue.Oversold; } else if (mfiD > 20 && mfiD < 80) { result.Interpretation = SignalInterpretationValue.Neutral; } else if (mfiD >= 80 && mfiD < 90) { result.Interpretation = SignalInterpretationValue.Overbought; } else { result.Interpretation = SignalInterpretationValue.OverboughtUnsustainable; } } } return(result); }
protected override SignalInterpretation MakeInterpretation(System.Collections.Generic.List <Model.Signal> signals, StockQuoteInfo quote = null) { return(null); }
public EntityResponse <StockQuoteInfo> GetStockQuote(string securityCode) { StockQuoteInfo result = _uow.StockQuotesInfo.GetAll().FirstOrDefault(item => item.SecurityCode.Equals(securityCode)); return(result); }
public static List <StockQuoteInfo> ParseDbfFile(byte[] data) { Stream stream = new MemoryStream(data); Table table = Table.Open(stream); const string chineseSimplifiedEncodingCodepage = "gb2312"; Reader reader = table.OpenReader(Encoding.GetEncoding(chineseSimplifiedEncodingCodepage)); List <StockQuoteInfo> result = new List <StockQuoteInfo>(); DateTime tradeTime = DateTime.Now; // ignore the first row and read the current trade time. //todo: should be reviewed---------------------- //if (reader.Read()) //{ // string timeString = reader.GetString("S2"); // string dateString = reader.GetString("S6"); // DateTime.TryParseExact(dateString + timeString, "yyyyMMddHHmmss", null, DateTimeStyles.None, out tradeTime); //} while (reader.Read()) { StockQuoteInfo stockQuoteInfo = new StockQuoteInfo(); stockQuoteInfo.TradeDate = tradeTime; foreach (KeyValuePair <string, PropertyInfo> column in DbfFileMapping) { object value; try { value = reader.GetValue(column.Key); } // todo: column "S13" always throws FormatException catch (FormatException) { value = null; } column.Value.SetValue(stockQuoteInfo, value, null); } // todo: split serial task to fill the value into stockQuoteInfo //if (DbfFileMapping.Count > 4000) //{ // System.Threading.Tasks.Parallel.ForEach(DbfFileMapping, (index) => { // object value; // try // { // value = reader.GetValue(index.Key); // } // // todo: column "S13" always throws FormatException // catch (FormatException) // { // value = null; // } // index.Value.SetValue(stockQuoteInfo, value, null); // }); //} result.Add(stockQuoteInfo); } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null && AvgPeriod == 20) { List <Signal> maxs = signals.ForIndicatorAndOffset(this, new[] { 0, -1 }); if (maxs != null && maxs.Count == 2) { Signal max0 = maxs[0]; Signal max1 = maxs[1]; double max0D = max0.Value; double max1D = max1.Value; result = new SignalInterpretation(this); result.Interpretation = max0D > max1D ? SignalInterpretationValue.Bullish : SignalInterpretationValue.Nothing; } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { if (signals == null) { return(null); } Signal signal = signals.FirstOrDefault(x => x.Name == Name); if (signal == null) { return(null); } SignalInterpretation result = MakeInterpretationBasedOnValue(this, (int)signal.Value); return(result); }
public List <SignalInterpretation> GetSignalsInterpretation(HistoricalData historicalData, List <IIndicator> indicators, StockQuoteInfo quote, DateTime?forDate = null) { DependencyScope dependencyScope = indicators.GetDependencies(); DateTime startDate = forDate ?? DateTime.UtcNow.Date; List <Signal> signals = GetSignalsByDependencies(historicalData, dependencyScope, startDate); List <SignalInterpretation> interpretations = new List <SignalInterpretation>(); foreach (ICalculatableIndicator indicator in indicators.OfType <ICalculatableIndicator>()) { SignalInterpretation interpretation = indicator.MakeInterpretation(signals, quote); if (interpretation != null) { interpretations.Add(interpretation); } } return(interpretations); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null && AvgPeriod == 20) { Signal adxSignal = signals.LatestForIndicator(new Adx(AvgPeriod)); Signal plusDiSignal = signals.LatestForIndicator(new PlusDi(AvgPeriod)); Signal minusDiSignal = signals.LatestForIndicator(new MinusDi(AvgPeriod)); if (adxSignal != null && plusDiSignal != null && minusDiSignal != null) { double adxD = adxSignal.Value; double plusDiD = plusDiSignal.Value; double minusDiD = minusDiSignal.Value; result = new SignalInterpretation(this); if (adxD < 25) { result.Interpretation = SignalInterpretationValue.Neutral; } else if (adxD >= 25 && adxD < 35) { if (plusDiD >= minusDiD) { result.Interpretation = SignalInterpretationValue.TrendingBullish; } else if (plusDiD < minusDiD) { result.Interpretation = SignalInterpretationValue.TrendingBearish; } } else if (adxD >= 35) { if (plusDiD >= minusDiD) { result.Interpretation = SignalInterpretationValue.StrongTrendBullish; } else if (plusDiD < minusDiD) { result.Interpretation = SignalInterpretationValue.StrongTrendBearish; } } } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (quote != null && signals != null) { Signal wma = signals.LatestForIndicator(this); if (wma != null) { double wmaD = wma.Value; double lastPrice = (double)quote.LastPrice.Value; result = new SignalInterpretation(this) { Interpretation = lastPrice > wmaD ? SignalInterpretationValue.Bullish : SignalInterpretationValue.Bearish }; } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null) { List <Signal> macds = signals.ForIndicatorAndOffset(this, new[] { 0, -3 }); if (macds != null && macds.Count == 2) { Signal macd0 = macds[0]; Signal macd3 = macds[1]; double macd0D = macd0.Value; double macd3D = macd3.Value; result = new SignalInterpretation(this); if (macd0D > 0) { result.Interpretation = (macd0D - macd3D) < 0 ? SignalInterpretationValue.BullishTurningBearish : SignalInterpretationValue.Bullish; } else { result.Interpretation = (macd0D - macd3D) >= 0 ? SignalInterpretationValue.BearishTurningBullish : SignalInterpretationValue.Bearish; } } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null) { Signal cci = signals.LatestForIndicator(this); if (cci != null) { double cciD = cci.Value; result = new SignalInterpretation(this); if (cciD <= -200) { result.Interpretation = SignalInterpretationValue.Overbought; } else if (cciD > -200 && cciD <= -100) { result.Interpretation = SignalInterpretationValue.Bearish; } else if (cciD > -100 && cciD < -0) { result.Interpretation = SignalInterpretationValue.MildlyBearish; } else if (cciD >= 0 && cciD < 100) { result.Interpretation = SignalInterpretationValue.MildlyBullish; } else if (cciD >= 100 && cciD < 200) { result.Interpretation = SignalInterpretationValue.Bullish; } else { result.Interpretation = SignalInterpretationValue.Oversold; } } } return(result); }
SignalInterpretation ICalculatableIndicator.MakeInterpretation(List <Signal> signals, StockQuoteInfo quote) { return(MakeInterpretation(signals, quote)); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { return(null); }
//TODO: use dependencies inside each realisation to get needed signals protected abstract SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null);
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { throw new System.NotImplementedException(); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null && AvgPeriod == 20) { Signal signal = signals.LatestForIndicator(this); if (signal != null) { result = new SignalInterpretation(this); double rsiD = signal.Value; if (rsiD <= 30) { result.Interpretation = SignalInterpretationValue.Oversold; } else if (rsiD > 30 && rsiD <= 40) { result.Interpretation = SignalInterpretationValue.Bearish; } else if (rsiD > 40 && rsiD < 50) { result.Interpretation = SignalInterpretationValue.MildlyBearish; } else if (rsiD >= 50 && rsiD < 60) { result.Interpretation = SignalInterpretationValue.MildlyBullish; } else if (rsiD >= 60 && rsiD < 70) { result.Interpretation = SignalInterpretationValue.Bullish; } else if (rsiD >= 70) { result.Interpretation = SignalInterpretationValue.Overbought; } } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null) { List <Signal> pros = signals.ForIndicatorAndOffset(this, new[] { 0, -3 }); if (pros != null && pros.Count == 2) { Signal pro0 = pros[0]; Signal pro3 = pros[1]; double pro0D = pro0.Value; double pro3D = pro3.Value; result = new SignalInterpretation(this); if (pro0D > 0) { result.Interpretation = (pro0D - pro3D) < 0 ? SignalInterpretationValue.TurningBearish : SignalInterpretationValue.Bullish; } else { result.Interpretation = (pro0D - pro3D) >= 0 ? SignalInterpretationValue.BearishTurningBullish : SignalInterpretationValue.Bearish; } } } return(result); }
protected override SignalInterpretation MakeInterpretation(List <Signal> signals, StockQuoteInfo quote = null) { SignalInterpretation result = null; if (signals != null) { Signal stoch = signals.LatestForIndicator(this); if (stoch != null) { double stochD = stoch.Value; result = new SignalInterpretation(this); if (stochD <= 20) { result.Interpretation = SignalInterpretationValue.Oversold; } else if (stochD > 20 && stochD <= 35) { result.Interpretation = SignalInterpretationValue.Bearish; } else if (stochD > 35 && stochD < 50) { result.Interpretation = SignalInterpretationValue.MildlyBearish; } else if (stochD >= 50 && stochD < 65) { result.Interpretation = SignalInterpretationValue.MildlyBullish; } else if (stochD >= 65 && stochD < 80) { result.Interpretation = SignalInterpretationValue.Bullish; } else { result.Interpretation = SignalInterpretationValue.Overbought; } } } return(result); }