/// <summary> /// Gets the current values for all the algorithm securities (price/volatility) /// </summary> /// <returns>The insight target values for all the algorithm securities</returns> public ReadOnlySecurityValuesCollection GetAllValues() { var values = new Dictionary <Symbol, SecurityValues>(); foreach (var kvp in _algorithm.Securities) { var security = kvp.Value; var volume = security.Cache.GetData <TradeBar>()?.Volume ?? 0; var value = new SecurityValues(security.Symbol, _algorithm.UtcTime, security.Exchange.Hours, security.Price, security.VolatilityModel.Volatility, volume, security.QuoteCurrency.ConversionRate); values[security.Symbol] = value; } return(new ReadOnlySecurityValuesCollection(values)); }
public void RecordsPopulationAverageScoresOnInsightAnalysisCompleted() { var time = new DateTime(2000, 01, 01); var stats = new StatisticsInsightManagerExtension(new TestAccountCurrencyProvider()); var insight = Insight.Price(Symbols.SPY, Time.OneDay, InsightDirection.Up); var spySecurityValues = new SecurityValues(insight.Symbol, time, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), 100m, 1m, 125000, 1m); var context = new InsightAnalysisContext(insight, spySecurityValues, insight.Period); context.Score.SetScore(InsightScoreType.Direction, .55, time); context.Score.SetScore(InsightScoreType.Magnitude, .25, time); stats.OnInsightAnalysisCompleted(context); Assert.AreEqual(context.Score.Direction, stats.Statistics.RollingAveragedPopulationScore.Direction); Assert.AreEqual(context.Score.Magnitude, stats.Statistics.RollingAveragedPopulationScore.Magnitude); }
public void IgnoresFlatInsightsWithScore(InsightScoreType scoreType, InsightType insightType, double?magnitude) { var time = new DateTime(2000, 01, 01); var stats = new StatisticsInsightManagerExtension(new TestAccountCurrencyProvider()); var insight = new Insight(Symbols.SPY, TimeSpan.FromDays(1), insightType, InsightDirection.Flat, magnitude, null); var spySecurityValues = new SecurityValues(insight.Symbol, time, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), 100m, 1m, 125000, 1m); var context = new InsightAnalysisContext(insight, spySecurityValues, insight.Period); context.Score.SetScore(InsightScoreType.Direction, .55, time); context.Score.SetScore(InsightScoreType.Magnitude, .25, time); stats.OnInsightAnalysisCompleted(context); Assert.AreEqual(0.0, stats.Statistics.RollingAveragedPopulationScore.Direction); Assert.AreEqual(0.0, stats.Statistics.RollingAveragedPopulationScore.Magnitude); }
private void TryParse002(string dataFeedMsg) { try { string source = dataFeedMsg.Substring(0, 3); string notSymbolData = dataFeedMsg.Substring(3, dataFeedMsg.Length - 3); string[] svalues = Split(notSymbolData); if (svalues.Length != 3) { HandleLog("Wrong 002 Message : " + dataFeedMsg); return; } string id = svalues[0]; string origSymbol = svalues[1]; Security sec; if (!SecurityValues.TryGetValue(origSymbol, out sec)) { sec = new Security(); sec.OrgSecurity = origSymbol; } sec.Source = source; sec.Id = id; sec.OrgSecurity = origSymbol; sec.IsDeleted = true; sec.LastUpdate = DateTime.Now; SecurityValues.AddOrUpdate(origSymbol, sec, (k, v) => { v.IsDeleted = true; return(v); }); HandleSecurityChanged(new SecurityEventArgs(sec, dataFeedMsg)); } catch (Exception ex) { TBYException tex = new TBYException(MethodInfo.GetCurrentMethod().GetFullName(), "Matrkiks symbol delete mesajı işlenirken hatası oluştu", ex); HandleException(tex); } }
public List <ISecurityValues> ProcessFile(string responseFileName) { var SecuritiesValues = new List <ISecurityValues>(); var startReadingData = false; var lineNumber = 0; var lines = File.ReadLines(responseFileName); var columnNames = new List <string>(); foreach (var line in lines) { if (line == "START-OF-DATA") { startReadingData = true; } if (line == "END-OF-DATA") { startReadingData = false; } if (startReadingData) { var securityValues = new SecurityValues() { RawValue = line }; lineNumber++; if (lineNumber == 1) { continue; } if (lineNumber == 2) { columnNames = line.Split( Options.RequestFileDelimiter.ToCharArray()).ToList(); } if (lineNumber > 2) { var columnValues = line.Split(Options.RequestFileDelimiter.ToCharArray()).ToList(); var securityName = columnValues[0]; securityValues.ProviderInternalSecurityName = securityName; securityValues.SecurityName = SecuritiesList.FirstOrDefault( p => p.ProviderInternalName == securityName)?.Name; securityValues.ErrorCode = columnValues[1]; if (securityValues.ErrorCode == "0") { for (int colindex = 3; colindex < columnValues.Count; colindex++) { var fieldValue = new FieldValue() { Name = columnNames[colindex], Value = columnValues[colindex] }; if (!string.IsNullOrWhiteSpace(fieldValue.Name)) { securityValues.FieldValues.Add(fieldValue); } } } SecuritiesValues.Add(securityValues); } } } Console.WriteLine("File was processed"); return(SecuritiesValues); }
private void TryParse060(string dataFeedMsg)//Genel veri update paketi { try { string source = dataFeedMsg.Substring(0, 3); string tmp1 = dataFeedMsg.Substring(3, 1); int tmpInt1; string notSymbolData = dataFeedMsg.Substring(3, dataFeedMsg.Length - 3); List <string> vals = new List <string>(notSymbolData.Split(MATRIKS_SEPERATOR)); string origSymbol = vals[0]; vals.RemoveAt(0); if (int.TryParse(tmp1, out tmpInt1)) { HandleLog("Wrong 060 Message : " + dataFeedMsg); return; } if (string.IsNullOrEmpty(origSymbol)) { HandleLog("Missing Symbol Field 060 Message : " + dataFeedMsg); return; } Security sec; if (!SecurityValues.TryGetValue(origSymbol, out sec))//if (sec == null) { sec = new Security(); sec.OrgSecurity = origSymbol; } SetSecuritySembol(sec, null, null); sec.LastUpdate = DateTime.Now; sec.Source = source; for (int i = 0; i < vals.Count; i++) { if (i % 2 == 0) { string key = vals[i]; if (!string.IsNullOrEmpty(key)) { string val = vals[i + 1]; SecurityPropertySetter.Set(sec, new KeyValuePair <string, string>(key, val)); sec.Dictionary.AddOrUpdate(key, val, (k, v) => { return(val); }); } } } SecurityValues.AddOrUpdate(origSymbol, sec, (k, v) => { return(sec); }); HandleSecurityChanged(new SecurityEventArgs(sec, dataFeedMsg)); } catch (Exception ex) { TBYException tex = new TBYException(MethodInfo.GetCurrentMethod().GetFullName(), "Matrkiks sembol verisi işlenirken hata oluştu", ex); HandleException(tex); } }
private void TryParse001(string dataFeedMsg) { try { string source = dataFeedMsg.Substring(0, 3); string notSymbolData = dataFeedMsg.Substring(3, dataFeedMsg.Length - 3); string[] svalues = Split(notSymbolData); if (svalues.Length != 12) { HandleLog("Wrong 001 Message : " + dataFeedMsg); return; } string origSymbol = svalues[1]; if (string.IsNullOrEmpty(origSymbol)) { HandleLog("Missing 001 Symbol Field 001 Message : " + dataFeedMsg); return; } int symbolCount = origSymbol.Length; if (symbolCount < 3) { HandleLog("Wrong 001 Symbol Count " + symbolCount + " 001 Message : " + dataFeedMsg); return; } string id = svalues[0]; string description = svalues[2]; string exchangeID = svalues[3]; string marketCode = svalues[4]; string depth = svalues[5]; string sectorID = svalues[6]; string decimalPlace = svalues[7]; string endexes = svalues[8]; string symbol = svalues[9]; string sfx = svalues[10]; Security sec; if (!SecurityValues.TryGetValue(origSymbol, out sec)) { sec = new Security(); sec.OrgSecurity = origSymbol; } sec.Source = source; sec.LastUpdate = DateTime.Now; sec.Id = id; sec.OrgSecurity = origSymbol; sec.Description = description; sec.ExchangeID = exchangeID; SetSecuritySembol(sec, symbol, sfx); Exchange exch; if (ExchangeDefinitions.TryGetValue(exchangeID, out exch)) { sec.ExchangeDescription = exch.Description; } sec.MarketCode = marketCode; string mrktDef; if (MarketDefinitions.TryGetValue(marketCode, out mrktDef)) { sec.MarketDescription = mrktDef; } sec.Depth = short.Parse(depth); sec.SectorID = sectorID; sec.DecimalPlace = short.Parse(decimalPlace); sec.Endexes = endexes; char[] eList = endexes.ToCharArray(); if (eList[0] == '0') { sec.IsBist30 = false; } else { sec.IsBist30 = true; } if (eList[1] == '0') { sec.IsBist50 = false; } else { sec.IsBist50 = true; } if (eList[2] == '0') { sec.IsBist100 = false; } else { sec.IsBist100 = true; } sec.LastUpdate = DateTime.Now; SecurityValues.AddOrUpdate(origSymbol, sec, (k, v) => { sec.IsDeleted = v.IsDeleted; return(sec); }); HandleSecurityChanged(new SecurityEventArgs(sec, dataFeedMsg)); } catch (Exception ex) { TBYException tex = new TBYException(MethodInfo.GetCurrentMethod().GetFullName(), "Matrkiks symbol create mesajı işlenirken hatası oluştu", ex); HandleException(tex); } }