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


C# DenseVector.ToArray方法代码示例

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


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

示例1: NormalizeNeg1to1

 public static double[] NormalizeNeg1to1(this double[] data)
 {
     var d = new DenseVector(data);
     var result = new DenseVector(d.Count);
     d.CopyTo(result);
     result = (DenseVector) (result - ((d.Max() + d.Min())/2))/((d.Max() - d.Min())/2);
     return result.ToArray();
 }
开发者ID:ifzz,项目名称:QuantSys,代码行数:8,代码来源:StatisticsExtension.cs

示例2: NormalizeZScore

 public static double[] NormalizeZScore(this double[] data)
 {
     var d = new DenseVector(data);
     var result = new DenseVector(d.Count);
     d.CopyTo(result);
     result = (DenseVector) ((result - d.Mean())/(d.StandardDeviation()));
     return result.ToArray();
 }
开发者ID:ifzz,项目名称:QuantSys,代码行数:8,代码来源:StatisticsExtension.cs

示例3: Normalize0to1

 public static double[] Normalize0to1(this double[] data)
 {
     var returnData = new double[data.Length];
     var d = new DenseVector(data);
     var result = new DenseVector(d.Count);
     d.CopyTo(result);
     result = (DenseVector) (result - d.Min())/(d.Max() - d.Min());
     return result.ToArray();
 }
开发者ID:ifzz,项目名称:QuantSys,代码行数:9,代码来源:StatisticsExtension.cs

示例4: Run

        /// <summary>
        /// Run example
        /// </summary>
        public void Run()
        {
            // Format vector output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Create new empty vector
            var vectorA = new DenseVector(10);
            Console.WriteLine(@"Empty vector A");
            Console.WriteLine(vectorA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();
            
            // 1. Fill vector by data using indexer []
            for (var i = 0; i < vectorA.Count; i++)
            {
                vectorA[i] = i;
            }

            Console.WriteLine(@"1. Fill vector by data using indexer []");
            Console.WriteLine(vectorA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Fill vector by data using SetValues method
            vectorA.SetValues(new[] { 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0 });
            Console.WriteLine(@"2. Fill vector by data using SetValues method");
            Console.WriteLine(vectorA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Convert Vector to double[]
            var data = vectorA.ToArray();
            Console.WriteLine(@"3. Convert vector to double array");
            for (var i = 0; i < data.Length; i++)
            {
                Console.Write(data[i].ToString("#0.00\t", formatProvider) + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 4. Convert Vector to column matrix. A matrix based on this vector in column form (one single column)
            var columnMatrix = vectorA.ToColumnMatrix();
            Console.WriteLine(@"4. Convert vector to column matrix");
            Console.WriteLine(columnMatrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 5. Convert Vector to row matrix. A matrix based on this vector in row form (one single row)
            var rowMatrix = vectorA.ToRowMatrix();
            Console.WriteLine(@"5. Convert vector to row matrix");
            Console.WriteLine(rowMatrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 6. Clone vector
            var cloneA = vectorA.Clone();
            Console.WriteLine(@"6. Clone vector");
            Console.WriteLine(cloneA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 7. Clear vector
            cloneA.Clear();
            Console.WriteLine(@"7. Clear vector");
            Console.WriteLine(cloneA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 8. Copy part of vector into another vector. If you need to copy all data then use CopoTy(vector) method.
            vectorA.CopySubVectorTo(cloneA, 3, 3, 4);
            Console.WriteLine(@"8. Copy part of vector into another vector");
            Console.WriteLine(cloneA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 9. Get part of vector as another vector
            var subvector = vectorA.SubVector(0, 5);
            Console.WriteLine(@"9. Get subvector");
            Console.WriteLine(subvector.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

           // 10. Enumerator usage
            Console.WriteLine(@"10. Enumerator usage");
            foreach (var value in vectorA)
            {
                Console.Write(value.ToString("#0.00\t", formatProvider) + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 11. Indexed enumerator usage
            Console.WriteLine(@"11. Enumerator usage");
            foreach (var value in vectorA.GetIndexedEnumerator())
            {
                Console.WriteLine(@"Index = {0}; Value = {1}", value.Item1, value.Item2.ToString("#0.00\t", formatProvider));
            }

            Console.WriteLine();
        }
开发者ID:hickford,项目名称:mathnet-numerics-native,代码行数:97,代码来源:VectorDataAccessor.cs

示例5: OnTick

        public override void OnTick(params Tick[] t)
        {
            
            data1.Enqueue(t[0].BidClose);
            data2.Enqueue(t[1].BidClose);

            double STOP = 1.005;

            if (counter++ >= n)
            {
                var d1 = new DenseVector(data1.ToArray().NormalizeZScore());
                var d2 = new DenseVector(data2.ToArray().NormalizeZScore());

                double spread;
                //spread= (d1 - d2).ToArray().NormalizeZScore()[d1.Count - 1];


                List<double[]> mat = new List<double[]>();
                mat.Add(d1.ToArray());
                mat.Add(d2.ToArray());
                List<MaxEigenData> maxEigen = new List<MaxEigenData>();
                double[] maxEigenValues;
                double[,] eigenMatrix;

                JohansenHelper.DoMaxEigenValueTest(mat, 5, out maxEigen, out maxEigenValues, out eigenMatrix);

                spread = (maxEigenValues[0]*d1 - maxEigenValues[1]*d2).ToArray().NormalizeZScore()[d1.Count-1];


                TEMA.HandleNextTick(spread);

                ((GenericContainer)indicatorList["Container"]).HandleNextTick(spread);

                /*
                //t[0] hit stop / limit
                if ( (IAccountManager.ExistsShortPositionForSymbol(t[1].Symbol) &&
                    !IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
                    ||
                    (IAccountManager.ExistsLongPositionForSymbol(t[1].Symbol) &&
                    !IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
                    )
                {
                    if(!IAccountManager.GetStopOrder(t[1].Symbol).Trailing)
                        IAccountManager.ModifyTrailingStop(t[1], STOP/2);
                }

                //t[1] positiong hit stop/limit
                if ((IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol) &&
                    !IAccountManager.ExistsLongPositionForSymbol(t[1].Symbol))
                    ||
                    (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol) &&
                    !IAccountManager.ExistsShortPositionForSymbol(t[1].Symbol))
                    )
                {
                    if (!IAccountManager.GetStopOrder(t[0].Symbol).Trailing)
                        IAccountManager.ModifyTrailingStop(t[0], STOP/2);
                }
                */

                if (spread < -1 && IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol) &&
                         IAccountManager.ExistsLongPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.ClosePosition(t[0].Symbol);
                    IAccountManager.ClosePosition(t[1].Symbol);

                    
                    Console.WriteLine("Closed Pair Trade.");

                }
                if (spread > 1 && IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol) &&
                        IAccountManager.ExistsShortPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.ClosePosition(t[0].Symbol);
                    IAccountManager.ClosePosition(t[1].Symbol);


                    Console.WriteLine("Closed Pair Trade.");

                }


                //short d1, long d2 if spread > 2.0
                if (TEMA[0] < 3  && TEMA[1] > 3 && !IAccountManager.ExistsPositionForSymbol(t[0].Symbol) &&
                    !IAccountManager.ExistsPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Short, STOP);
                    IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Long, STOP);


                    Console.WriteLine("Placed Pair Trade.");

                }

                if (TEMA[0] > -3 && TEMA[1] < -3 && !IAccountManager.ExistsPositionForSymbol(t[0].Symbol) &&
                  !IAccountManager.ExistsPositionForSymbol(t[1].Symbol))
                {
                    IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Long, STOP);
                    IAccountManager.PlaceMarketOrder(t[1].Symbol, 10000, Position.PositionSide.Short, STOP);


//.........这里部分代码省略.........
开发者ID:ifzz,项目名称:QuantSys,代码行数:101,代码来源:Cointegration.cs


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