/// <summary> /// Initializes a new instance of the <see cref="InsightAnalysisContext"/> class /// </summary> /// <param name="insight">The insight to be analyzed</param> /// <param name="initialValues">The initial security values from when the insight was generated</param> /// <param name="analysisPeriod">The period over which to perform analysis of the insight. This should be /// greater than or equal to <see cref="Alphas.Insight.Period"/>. Specify null for default, insight.Period</param> public InsightAnalysisContext(Insight insight, SecurityValues initialValues, TimeSpan analysisPeriod) { Insight = insight; _contextStorage = new Dictionary <string, object>(); CurrentValues = InitialValues = initialValues; _previousEvaluationTimeUtc = CurrentValues.TimeUtc; // this will always be equal when the InsightManager is initialized with extraAnalysisPeriodRatio == 0 // this is the way LEAN run in the cloud and locally, but support for non-zero ratios are left in for posterity // by short-circuiting this here, we guarantee that analysis end time and close time are identical if (analysisPeriod == insight.Period) { AnalysisEndTimeUtc = insight.CloseTimeUtc; } else { var barSize = Time.Max(analysisPeriod.ToHigherResolutionEquivalent(false).ToTimeSpan(), Time.OneMinute); var barCount = (int)(insight.Period.Ticks / barSize.Ticks); AnalysisEndTimeUtc = Time.GetEndTimeForTradeBars(initialValues.ExchangeHours, insight.CloseTimeUtc, analysisPeriod.ToHigherResolutionEquivalent(false).ToTimeSpan(), barCount, false); } _analysisPeriod = AnalysisEndTimeUtc - initialValues.TimeUtc; }
/// <summary> /// Sets the <see cref="CurrentValues"/> /// </summary> internal void SetCurrentValues(SecurityValues values) { _previousEvaluationTimeUtc = CurrentValues.TimeUtc; if (values.TimeUtc >= InsightPeriodEndTimeUtc) { InsightPeriodClosed = true; } CurrentValues = values; }
/// <summary> /// Initializes a new instance of the <see cref="AlphaAnalysisContext"/> class /// </summary> /// <param name="alpha">The alpha to be analyzed</param> /// <param name="initialValues">The initial security values from when the alpha was generated</param> /// <param name="analysisPeriod">The period over which to perform analysis of the alpha. This should be /// greater than or equal to <see cref="Alpha.Period"/>. Specify null for default, alpha.Period</param> public AlphaAnalysisContext(Alpha alpha, SecurityValues initialValues, TimeSpan analysisPeriod) { Alpha = alpha; AnalysisPeriod = analysisPeriod; _contextStorage = new Dictionary <string, object>(); CurrentValues = InitialValues = initialValues; _previousEvaluationTimeUtc = CurrentValues.TimeUtc; AnalysisEndTimeUtc = Alpha.GeneratedTimeUtc + analysisPeriod; }
/// <summary> /// Initializes a new instance of the <see cref="InsightAnalysisContext"/> class /// </summary> /// <param name="insight">The insight to be analyzed</param> /// <param name="initialValues">The initial security values from when the insight was generated</param> /// <param name="analysisPeriod">The period over which to perform analysis of the insight. This should be /// greater than or equal to <see cref="Alphas.Insight.Period"/>. Specify null for default, insight.Period</param> public InsightAnalysisContext(Insight insight, SecurityValues initialValues, TimeSpan analysisPeriod) { Insight = insight; _contextStorage = new Dictionary <string, object>(); CurrentValues = InitialValues = initialValues; _previousEvaluationTimeUtc = CurrentValues.TimeUtc; var barSize = Time.Max(analysisPeriod.ToHigherResolutionEquivalent(false).ToTimeSpan(), Time.OneMinute); var barCount = (int)(insight.Period.Ticks / barSize.Ticks); AnalysisEndTimeUtc = Time.GetEndTimeForTradeBars(initialValues.ExchangeHours, insight.CloseTimeUtc, analysisPeriod.ToHigherResolutionEquivalent(false).ToTimeSpan(), barCount, false); _analysisPeriod = AnalysisEndTimeUtc - initialValues.TimeUtc; }
/// <summary> /// Initializes a new instance of the <see cref="AlphaAnalysisContext"/> class /// </summary> /// <param name="alpha">The alpha to be analyzed</param> /// <param name="initialValues">The initial security values from when the alpha was generated</param> /// <param name="analysisPeriod">The period over which to perform analysis of the alpha. This should be /// greater than or equal to <see cref="Alphas.Alpha.Period"/>. Specify null for default, alpha.Period</param> public AlphaAnalysisContext(Alpha alpha, SecurityValues initialValues, TimeSpan analysisPeriod) { Alpha = alpha; _contextStorage = new Dictionary <string, object>(); CurrentValues = InitialValues = initialValues; _previousEvaluationTimeUtc = CurrentValues.TimeUtc; AlphaPeriodEndTimeUtc = alpha.GeneratedTimeUtc + alpha.Period; var barSize = Time.Max(analysisPeriod.ToHigherResolutionEquivalent(false).ToTimeSpan(), Time.OneMinute); var barCount = (int)(alpha.Period.Ticks / barSize.Ticks); AnalysisEndTimeUtc = Time.GetEndTimeForTradeBars(initialValues.ExchangeHours, alpha.CloseTimeUtc, analysisPeriod.ToHigherResolutionEquivalent(false).ToTimeSpan(), barCount, false); _analysisPeriod = AnalysisEndTimeUtc - initialValues.TimeUtc; }
/// <summary> /// Sets the <see cref="CurrentValues"/> /// </summary> internal void SetCurrentValues(SecurityValues values) { _previousEvaluationTimeUtc = CurrentValues.TimeUtc; if (values.TimeUtc >= Insight.CloseTimeUtc) { InsightPeriodClosed = true; if (Insight.Period == Time.EndOfTimeTimeSpan) { // Special case, see OrderBasedInsightGenerator AnalysisEndTimeUtc = Insight.CloseTimeUtc; Insight.Period = Insight.CloseTimeUtc - Insight.GeneratedTimeUtc; } } CurrentValues = values; }
/// <summary> /// Sets the <see cref="CurrentValues"/> /// </summary> internal void SetCurrentValues(SecurityValues values) { _previousEvaluationTimeUtc = CurrentValues.TimeUtc; CurrentValues = values; }