当前位置: 首页>>代码示例>>C#>>正文


C# TimeSeries.GetIndex方法代码示例

本文整理汇总了C#中FreeQuant.Series.TimeSeries.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSeries.GetIndex方法的具体用法?C# TimeSeries.GetIndex怎么用?C# TimeSeries.GetIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FreeQuant.Series.TimeSeries的用法示例。


在下文中一共展示了TimeSeries.GetIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Crosses

		public ECross Crosses(TimeSeries series, DateTime datetime, int row = 0)
		{
			int index1 = this.GetIndex(datetime);
			int index2 = series.GetIndex(datetime);
			if (index1 <= 0 || index1 >= this.Count || index2 <= 0 || index2 >= series.Count)
			{
				return ECross.None;
			}

			DateTime dt1 = this.GetDateTime(index1 - 1);
			DateTime dt2 = series.GetDateTime(index2 - 1);
			if (dt1 == dt2)
			{
				if (this[index1-1, row] <= series[index2 - 1, row] && this[index1, row] > series[index2, row])
					return ECross.Above;
				if (this[index1-1, row] >= series[index2 - 1, row] && this[index1, row] < series[index2, row])
					return ECross.Below;
			}
			else
			{
				double num1;
				double num2;
				if (dt1 < dt2)
				{
					DateTime dateTime3 = this.GetDateTime(index1 - 1);
					num1 = this[index1 - 1, row];
					num2 = series.GetIndex(dateTime3, EIndexOption.Next) == index2 ? series[series.GetIndex(dateTime3, EIndexOption.Prev), row] : series[series.GetIndex(dateTime3, EIndexOption.Next), row];
				}
				else
				{
					DateTime dateTime3 = series.GetDateTime(index2 - 1);
					num2 = series[index2 - 1, row];
					num1 = this.GetIndex(dateTime3, EIndexOption.Next) == index1 ? this[this.GetIndex(dateTime3, EIndexOption.Prev), row] : this[this.GetIndex(dateTime3, EIndexOption.Next), row];
				}
				if (num1 <= num2 && this[index1, row] > series[index2, row])
					return ECross.Above;
				if (num1 >= num2 && this[index1, row] < series[index2, row])
					return ECross.Below;
			}
			return ECross.None;
		}
开发者ID:heber,项目名称:FreeOQ,代码行数:41,代码来源:TimeSeries.cs

示例2: GetCovariance

		public override double GetCovariance(TimeSeries series, DateTime datetime1, DateTime datetime2)
		{
			if (!(series is DoubleSeries))
				throw new ArgumentException("not a DoubleSeries");

			double mean1 = this.GetMean();
			double mean2 = series.GetMean();
			double n = 0.0;
			double sum = 0.0;
			int index1 = series.GetIndex(datetime1, EIndexOption.Next);
			int index2 = series.GetIndex(datetime2, EIndexOption.Prev);
			for (int i = index1; i <= index2; ++i)
			{
				DateTime dt = this.GetDateTime(i);
				if (series.Contains(dt))
				{
					sum += (this[i] - mean1) * ((double)series[dt] - mean2);
					++n;
				}
			}
			if (n <= 1.0)
				return 0.0;

			return sum / (n - 1.0);
		}
开发者ID:heber,项目名称:FreeOQ,代码行数:25,代码来源:DoubleSeries.cs


注:本文中的FreeQuant.Series.TimeSeries.GetIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。