private Insight GetInsight(Symbol symbol, InsightDirection direction, DateTime generatedTimeUtc, TimeSpan?period = null) { period = period ?? TimeSpan.FromDays(1); var insight = Insight.Price(symbol, period.Value, direction); insight.GeneratedTimeUtc = generatedTimeUtc; insight.CloseTimeUtc = generatedTimeUtc.Add(period.Value); return(insight); }
public static AzureSupportCenterInsight CreateInsight <TResource>(Insight insight, OperationContext <TResource> context, Definition detector) where TResource : IResource { var description = GetTextObjectFromData("description", insight.Body) ?? new Text(string.Format(DefaultDescription, detector.Name)); var recommendedAction = GetTextObjectFromData("recommended action", insight.Body) ?? DefaultRecommendedAction; var customerReadyContent = GetTextObjectFromData("customer ready content", insight.Body); return(CreateInsight <TResource>(insight.Message, insight.Status, description, recommendedAction, customerReadyContent, detector, context)); }
private static void AssertStartupOptions(Insight <InsightsStartupData> act) { Assert.AreEqual("appname", act.Data.ApplicationName); Assert.AreEqual(false, act.Data.ApplicationNameWasGenerated); Assert.AreEqual("appv1", act.Data.ApplicationVersion); Assert.AreEqual("DataStax C# Driver for Apache Cassandra", act.Data.DriverName); Assert.AreEqual("BECFE098-E462-47E7-B6A7-A21CD316D4C0", act.Data.ClientId.ToUpper()); Assert.IsFalse(string.IsNullOrWhiteSpace(act.Data.DriverVersion)); }
private Insight GetInsight(Symbol symbol, InsightDirection direction, DateTime generatedTimeUtc) { var period = TimeSpan.FromDays(1); var insight = Insight.Price(symbol, period, direction); insight.GeneratedTimeUtc = generatedTimeUtc; insight.CloseTimeUtc = generatedTimeUtc.Add(period); return(insight); }
protected override IEnumerable <Insight> ExpectedInsights() { var period = TimeSpan.FromDays(14); foreach (var direction in new[] { InsightDirection.Up, InsightDirection.Down }) { yield return(Insight.Price(Symbols.SPY, period, direction)); } }
public void SetPeriodAndCloseTimeDoesNotThrowWhenGeneratedTimeUtcIsSet() { var insight = Insight.Price(Symbols.SPY, Time.OneDay, InsightDirection.Up); var exchangeHours = SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork); insight.GeneratedTimeUtc = new DateTime(2018, 08, 07, 00, 33, 00).ConvertToUtc(TimeZones.NewYork); Assert.That(() => insight.SetPeriodAndCloseTime(exchangeHours), Throws.Nothing); }
public void HasReferenceTypeEqualitySemantics() { var one = Insight.Price(Symbols.SPY, Time.OneSecond, InsightDirection.Up); var two = Insight.Price(Symbols.SPY, Time.OneSecond, InsightDirection.Up); Assert.AreNotEqual(one, two); Assert.AreEqual(one, one); Assert.AreEqual(two, two); }
private Insight GetInsight(Symbol symbol, InsightDirection direction, DateTime generatedTimeUtc, TimeSpan?period = null, double?confidence = DefaultPercent) { period = period ?? TimeSpan.FromDays(1); var insight = Insight.Price(symbol, period.Value, direction, confidence: confidence); insight.GeneratedTimeUtc = generatedTimeUtc; insight.CloseTimeUtc = generatedTimeUtc.Add(period.Value); return(insight); }
public override IEnumerable <Insight> Update(QCAlgorithm algorithm, Slice data) { var symbolsIBS = new Dictionary <Symbol, decimal>(); var returns = new Dictionary <Symbol, decimal>(); foreach (var kvp in algorithm.ActiveSecurities) { var security = kvp.Value; if (security.HasData) { var high = security.High; var low = security.Low; var hilo = high - low; // Do not consider symbol with zero open and avoid division by zero if (security.Open * hilo != 0) { // Internal bar strength (IBS) symbolsIBS.Add(security.Symbol, (security.Close - low) / hilo); returns.Add(security.Symbol, security.Close / security.Open - 1); } } } var insights = new List <Insight>(); // Number of stocks cannot be higher than half of symbolsIBS length var numberOfStocks = Math.Min((int)(symbolsIBS.Count / 2.0), _numberOfStocks); if (numberOfStocks == 0) { return(insights); } // Rank securities with the highest IBS value var ordered = from entry in symbolsIBS orderby Math.Round(entry.Value, 6) descending, entry.Key select entry; var highIBS = ordered.Take(numberOfStocks); // Get highest IBS var lowIBS = ordered.Reverse().Take(numberOfStocks); // Get lowest IBS // Emit "down" insight for the securities with the highest IBS value foreach (var kvp in highIBS) { insights.Add(Insight.Price(kvp.Key, _predictionInterval, InsightDirection.Down, Math.Abs((double)returns[kvp.Key]))); } // Emit "up" insight for the securities with the highest IBS value foreach (var kvp in lowIBS) { insights.Add(Insight.Price(kvp.Key, _predictionInterval, InsightDirection.Up, Math.Abs((double)returns[kvp.Key]))); } return(insights); }
public void Bonus_InsightSpecified_ShouldWork() { SetupCharacter(); Skills insight = new Insight(true, true); Assert.AreEqual(-5, insight.Bonus); Assert.IsTrue(insight.Proficiency); Assert.IsTrue(insight.Expertise); }
protected override IEnumerable <Insight> ExpectedInsights() { var period = TimeSpan.FromDays(12); return(new[] { Insight.Price(Symbols.SPY, period, InsightDirection.Down), Insight.Price(Symbols.SPY, period, InsightDirection.Up) }); }
public async Task <bool> Login(string username, string password) { ChadderApp.UIHelper.ShowLoading(); var initTimer = Insight.StartTimer("Login load"); var result = await Source.Login(username, password); Insight.StopTimer(initTimer); ChadderApp.UIHelper.HideLoading(); return(ShowErrorIfNotOk(result)); }
public void ShouldReturnName() { //assign ISkill actualSkillBase = new Insight(); //act ITextObj name = actualSkillBase.Name(); //assert name.Should().Be(new TextObj("Insight")); }
private Insight GetInsight(string SourceModel, string ticker, double magnitude) { var period = Time.OneDay; var direction = (InsightDirection)Math.Sign(magnitude); var insight = Insight.Price(GetSymbol(ticker), period, direction, magnitude, sourceModel: SourceModel); insight.GeneratedTimeUtc = _algorithm.UtcTime; insight.CloseTimeUtc = _algorithm.UtcTime.Add(insight.Period); return(insight); }
public ActionResult Edit([Bind(Include = "IDGraficosInsight,SurgiuInsightSim,SurgiuInsightNao,Data")] Insight graficosInsight) { if (ModelState.IsValid) { db.Entry(graficosInsight).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(graficosInsight)); }
/// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">TradeBars IDictionary object with your stock data</param> public void OnData(TradeBars data) { // wait for our indicator to be ready if (!_macd.IsReady) { return; } var holding = Portfolio[_symbol]; var signalDeltaPercent = (_macd - _macd.Signal) / _macd.Fast; var tolerance = 0.0025m; // if our macd is greater than our signal, then let's go long if (holding.Quantity <= 0 && signalDeltaPercent > tolerance) { // 1. Call EmitInsights with insights created in correct direction, here we're going long // The EmitInsights method can accept multiple insights separated by commas EmitInsights( // Creates an insight for our symbol, predicting that it will move up within the fast ema period number of days Insight.Price(_symbol, TimeSpan.FromDays(FastEmaPeriod), InsightDirection.Up) ); // longterm says buy as well SetHoldings(_symbol, 1.0); } // if our macd is less than our signal, then let's go short else if (holding.Quantity >= 0 && signalDeltaPercent < -tolerance) { // 1. Call EmitInsights with insights created in correct direction, here we're going short // The EmitInsights method can accept multiple insights separated by commas EmitInsights( // Creates an insight for our symbol, predicting that it will move down within the fast ema period number of days Insight.Price(_symbol, TimeSpan.FromDays(FastEmaPeriod), InsightDirection.Down) ); // shortterm says sell as well SetHoldings(_symbol, -1.0); } // if we wanted to liquidate our positions // 1. Call EmitInsights with insights create in the correct direction -- Flat // EmitInsights( // Creates an insight for our symbol, predicting that it will move down or up within the fast ema period number of days, depending on our current position // Insight.Price(_symbol, TimeSpan.FromDays(FastEmaPeriod), InsightDirection.Flat); // ); // Liquidate(); // plot both lines Plot("MACD", _macd, _macd.Signal); Plot(_symbol, "Open", data[_symbol].Open); Plot(_symbol, _macd.Fast, _macd.Slow); }
public ActionResult Edit([Bind(Include = "Id,SurgiuInsightSim,SurgiuInsightNao,Data,UsuarioId")] Insight insight) { if (ModelState.IsValid) { db.Entry(insight).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UsuarioId = new SelectList(db.Usuarios, "Id", "Nome", insight.UsuarioId); return(View(insight)); }
public void IgnoresInsights(Language language) { SetPortfolioConstruction(language); var insight = Insight.Price(Symbols.AAPL, Resolution.Minute, 1, InsightDirection.Down, 1, 1, "AlphaId", 0.5); insight.GeneratedTimeUtc = _algorithm.UtcTime; insight.CloseTimeUtc = _algorithm.UtcTime.Add(insight.Period); var targets = _algorithm.PortfolioConstruction.CreateTargets(_algorithm, new[] { insight }).ToList(); Assert.AreEqual(0, targets.Count); }
public void ShouldReturnWisdomAsBaseAttribute() { //arrange ISkill skill = new Insight(); ICharacterAttribute wisdomAttribute = new WisdomAttribute(); //act ICharacterAttribute actualAttribute = skill.BaseAttribute(); //assert actualAttribute.Should().Be(wisdomAttribute); }
/// <summary> /// Helper class used to set values not required to be set by alpha models /// </summary> /// <param name="insight">The <see cref="Insight"/> to set the values for</param> /// <returns>The same <see cref="Insight"/> instance with the values set</returns> private Insight InitializeInsightFields(Insight insight) { insight.GeneratedTimeUtc = UtcTime; insight.ReferenceValue = _securityValuesProvider.GetValues(insight.Symbol).Get(insight.Type); insight.SourceModel = string.IsNullOrEmpty(insight.SourceModel) ? Alpha.GetModelName() : insight.SourceModel; var exchangeHours = MarketHoursDatabase.GetExchangeHours(insight.Symbol.ID.Market, insight.Symbol, insight.Symbol.SecurityType); insight.SetPeriodAndCloseTime(exchangeHours); return(insight); }
public async Task <IActionResult> Create([Bind("Insightid,Insighprof")] Insight insight) { if (ModelState.IsValid) { _context.Add(insight); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(insight)); }
public ActionResult Create([Bind(Include = "IDGraficosInsight,SurgiuInsightSim,SurgiuInsightNao,Data")] Insight graficosInsight) { if (ModelState.IsValid) { db.Insights.Add(graficosInsight); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(graficosInsight)); }
public void Should_InvokeInsightsRpcCall_When_SessionIsCreated() { using (var simulacronCluster = SimulacronCluster.CreateNew(new SimulacronOptions { IsDse = true, Nodes = "3" })) { simulacronCluster.Prime(InsightsIntegrationTests.InsightsRpcPrime()); using (var cluster = BuildCluster(simulacronCluster, 500)) { Assert.AreEqual(0, simulacronCluster.GetQueries("CALL InsightsRpc.reportInsight(?)").Count); var session = (IInternalSession)cluster.Connect(); RequestLog query = null; TestHelper.RetryAssert( () => { query = simulacronCluster.GetQueries("CALL InsightsRpc.reportInsight(?)").FirstOrDefault(); Assert.IsNotNull(query); }, 5, 1000); string json = string.Empty; Insight <InsightsStartupData> message = null; try { json = Encoding.UTF8.GetString( Convert.FromBase64String( (string)query.Frame.GetQueryMessage().Options.PositionalValues[0])); message = JsonConvert.DeserializeObject <Insight <InsightsStartupData> >(json); } catch (JsonReaderException ex) { Assert.Fail("failed to deserialize json: " + ex.Message + Environment.NewLine + json); } Assert.IsNotNull(message); Assert.AreEqual(InsightType.Event, message.Metadata.InsightType); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Metadata.InsightMappingId)); Assert.AreEqual("driver.startup", message.Metadata.Name); Assert.AreEqual(InsightsIntegrationTests.applicationName, message.Data.ApplicationName); Assert.AreEqual(false, message.Data.ApplicationNameWasGenerated); Assert.AreEqual(InsightsIntegrationTests.applicationVersion, message.Data.ApplicationVersion); Assert.AreEqual(InsightsIntegrationTests.clusterId.ToString(), message.Data.ClientId); Assert.AreEqual(session.InternalSessionId.ToString(), message.Data.SessionId); Assert.Greater(message.Data.PlatformInfo.CentralProcessingUnits.Length, 0); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Data.PlatformInfo.CentralProcessingUnits.Model)); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Data.PlatformInfo.OperatingSystem.Version)); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Data.PlatformInfo.OperatingSystem.Arch)); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Data.PlatformInfo.OperatingSystem.Name)); Assert.IsFalse(message.Data.PlatformInfo.Runtime.Dependencies.Any(s => string.IsNullOrWhiteSpace(s.Value.FullName))); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Data.PlatformInfo.Runtime.RuntimeFramework)); Assert.IsFalse(string.IsNullOrWhiteSpace(message.Data.PlatformInfo.Runtime.TargetFramework)); } } }
public void IsActiveUsesClosedIntervalSemantics() { var generatedTime = new DateTime(2000, 01, 01); var insight = Insight.Price(Symbols.SPY, Time.OneMinute, InsightDirection.Up); insight.GeneratedTimeUtc = generatedTime; insight.CloseTimeUtc = insight.GeneratedTimeUtc + insight.Period; Assert.IsTrue(insight.IsActive(insight.CloseTimeUtc)); Assert.IsFalse(insight.IsActive(insight.CloseTimeUtc.AddTicks(1))); }
public void ComputeCloseHandlesOffsetHourOverMarketClosuresUsingResolutionBarCount() { var symbol = Symbols.SPY; // Friday @ 3:59PM + 1 hours => Monday @ 10:29 (1 min on Friday, 59 min on Monday) var generatedTimeUtc = new DateTime(2018, 08, 03, 12 + 3, 59, 0).ConvertToUtc(TimeZones.NewYork); var expectedClosedTimeUtc = new DateTime(2018, 08, 06, 10, 29, 0).ConvertToUtc(TimeZones.NewYork); var exchangeHours = MarketHoursDatabase.FromDataFolder().GetExchangeHours(symbol.ID.Market, symbol, symbol.SecurityType); var actualCloseTimeUtc = Insight.ComputeCloseTime(exchangeHours, generatedTimeUtc, Resolution.Hour, 1); Assert.AreEqual(expectedClosedTimeUtc, actualCloseTimeUtc); }
public void StartSendPendingMessages() { if (SendPendingMessagesTask == null || SendPendingMessagesTask.Status != TaskStatus.Running) { SendPendingMessagesTask = SendPendingMessages(); } else { Insight.Track("SendPendingMessagesTask not null"); } }
public void ComputeCloseTimeHandlesFractionalDays() { var symbol = Symbols.SPY; // Friday @ 3PM + 2.5 days => Wednesday @ 12:45 by counting 2 dates (Mon, Tues@3PM) and then half a trading day (+3.25hrs) => Wed@11:45AM var generatedTimeUtc = new DateTime(2018, 08, 03, 12 + 3, 0, 0).ConvertToUtc(TimeZones.NewYork); var expectedClosedTimeUtc = new DateTime(2018, 08, 08, 11, 45, 0).ConvertToUtc(TimeZones.NewYork); var exchangeHours = MarketHoursDatabase.FromDataFolder().GetExchangeHours(symbol.ID.Market, symbol, symbol.SecurityType); var actualCloseTimeUtc = Insight.ComputeCloseTime(exchangeHours, generatedTimeUtc, TimeSpan.FromDays(2.5)); Assert.AreEqual(expectedClosedTimeUtc, actualCloseTimeUtc); }
public void ComputeCloseTimeHandlesFractionalHours() { var symbol = Symbols.SPY; // Friday @ 3PM + 2.5 hours => Monday @ 11:00 (1 hr on Friday, 1.5 hours on Monday) var generatedTimeUtc = new DateTime(2018, 08, 03, 12 + 3, 0, 0).ConvertToUtc(TimeZones.NewYork); var expectedClosedTimeUtc = new DateTime(2018, 08, 06, 11, 0, 0).ConvertToUtc(TimeZones.NewYork); var exchangeHours = MarketHoursDatabase.FromDataFolder().GetExchangeHours(symbol.ID.Market, symbol, symbol.SecurityType); var actualCloseTimeUtc = Insight.ComputeCloseTime(exchangeHours, generatedTimeUtc, TimeSpan.FromHours(2.5)); Assert.AreEqual(expectedClosedTimeUtc, actualCloseTimeUtc); }
public async Task <ActionResult> Edit([Bind(Include = "Id,UserId,insight,Url,TimeStamp,RowVersion")] Insight insight) { if (ModelState.IsValid) { db.Entry(insight).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(insight)); }
/// <summary> /// Creates a menu item for the specified insight, and returns it. /// </summary> /// <param name="insight">The insight details.</param> /// <param name="context">Information that this page requires to display content.</param> /// <returns>A menu item for the specified insight.</returns> private TreeNode CreateMenuItem(Insight insight, PageContext context) { TreeNode node = new TreeNode { Text = String.Format("<span id='node_{0}' class='ContentTreeItem' name='treeNode'>{2}<span class='Name'>{1}</span></span>", insight.CodeName.Replace('.', '_'), HTMLHelper.HTMLEncode(insight.DisplayName), UIHelper.GetAccessibleIconTag("icon-piechart", size: FontIconSizeEnum.Standard)), NavigateUrl = String.Format("~/CMSModules/SocialMarketing/Pages/InsightsReport.aspx?reportCodeNames={0}&periodType={1}&externalId={2}", HttpUtility.UrlEncode(GetReportCodeNames(insight, context)), insight.PeriodType, context.ExternalId), Target = treeElem.TargetFrame }; return(node); }
/// <summary> /// Creates a menu item for the specified insight, and returns it. /// </summary> /// <param name="insight">The insight details.</param> /// <param name="context">Information that this page requires to display content.</param> /// <returns>A menu item for the specified insight.</returns> private TreeNode CreateMenuItem(Insight insight, PageContext context) { TreeNode node = new TreeNode { Text = String.Format("<span id='node_{0}' class='ContentTreeItem' name='treeNode'>{2}<span class='Name'>{1}</span></span>", insight.CodeName.Replace('.', '_'), HTMLHelper.HTMLEncode(insight.DisplayName), UIHelper.GetAccessibleIconTag("icon-piechart", size: FontIconSizeEnum.Standard)), NavigateUrl = String.Format("~/CMSModules/SocialMarketing/Pages/InsightsReport.aspx?reportCodeNames={0}&periodType={1}&externalId={2}", URLHelper.URLEncode(GetReportCodeNames(insight, context)), insight.PeriodType, context.ExternalId), Target = treeElem.TargetFrame }; return node; }
/// <summary> /// Retrieves a collection of insights where reports are available, and returns it. /// </summary> /// <returns>A collection of insights where reports are available.</returns> private IEnumerable<Insight> GetInsights(PageContext context) { Dictionary<string, Insight> insights = new Dictionary<string, Insight>(StringComparer.InvariantCultureIgnoreCase); foreach (ReportInfo report in new ObjectQuery<ReportInfo>().Where(ReportInfo.TYPEINFO.CodeNameColumn, QueryOperator.Like, context.ReportNamePrefix + "%")) { string[] tokens = report.ReportName.Split('.'); string codeName = tokens[1]; if (!insights.ContainsKey(codeName)) { string resourceName = String.Format(context.DisplayNameResourceNameFormat, codeName); Insight insight = new Insight { CodeName = codeName, PeriodType = tokens[2], DisplayName = GetString(resourceName) }; insights.Add(codeName, insight); } } return insights.Values.OrderBy(x => x.CodeName).ToArray(); }
/// <summary> /// Creates a list of report code names for the specified insight that is compatible with the Web analytics module, and returns it. /// </summary> /// <param name="insight">The insight details.</param> /// <param name="context">Information that this page requires to display content.</param> /// <returns>A list of report code names for the specified insight that is compatible with the Web analytics module.</returns> private string GetReportCodeNames(Insight insight, PageContext context) { StringBuilder builder = new StringBuilder(); foreach (string reportType in mReportTypes) { if (builder.Length > 0) { builder.Append(';'); } builder.AppendFormat(context.ReportNameFormat, insight.CodeName, insight.PeriodType, reportType); } return builder.ToString(); }