MathNet.Numerics
Пример использования функций математической статистики:
using System;
using TraderAPI;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using MathNet.Numerics.Statistics;
namespace uAlgo.Bots
{
public class NewBot : Bot
{
//------------------------------------------------
//
//------------------------------------------------
private void Print(string f, string l)
{
// получаем путь к папке с нашим роботом
string AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar.ToString();
// полный путь к файлу для записи служебной информации
string mLog = AssemblyPath + f;
using (StreamWriter sw = new StreamWriter(mLog, true))
sw.WriteLine(l);
}
//------------------------------------------------
//
//------------------------------------------------
public void OnTick()
{
}
public void OnStart()
{
IEnumerable<double> data = new double[] {
7,
2,
3,
4,
5
};
IEnumerable<double> data2 = new double[] {
4,
5,
5,
5,
5
};
double minimum = data.Minimum();
double maximum = data.Maximum();
double mean = data.Mean();
double sd = data.StandardDeviation();
double median = data.Median();
double gmean = data.GeometricMean();
double covar = data.Covariance(data2);
Print("result.txt",
"\nMean = " + mean.ToString() +
"\nMinimum = " + minimum.ToString() +
"\nMaximum = " + maximum.ToString() +
"\nSD = " + sd.ToString() +
"\nMedian = " + median.ToString() +
"\ngMean = " + gmean.ToString() +
"\nCovar = " + covar.ToString()
);
}
public void OnStop()
{
// Put your deinitialization logic here
}
}
}
Результат: