public void FinishAndProcess() { try { var priceData = new DenseMatrix(symbols.Length, numTicks); for (int j = 0; j < symbols.Length; j++) { SortedList <DateTime, Tick> d = mktData[j].data.Data; for (int k = 0; k < d.Count; k++) { //if (!symbols[j].Substring(0, 3).Equals("USD")) priceData[j, k] = 1/d.Values[k].BidClose; priceData[j, k] = d.Values[k].BidOpen; } } Vector <double> price1 = priceData.Row(0); Vector <double> price2 = priceData.Row(1); //Statistics.ApplyFunction((DenseVector)price1, Math.Log); //Statistics.ApplyFunction((DenseVector)price2, Math.Log); DenseVector norm1 = price1.ToArray().NormalizeZScore(); DenseVector norm2 = price2.ToArray().NormalizeZScore(); var newsym = new string[symbols.Length + 4]; for (int i = 0; i < symbols.Length; i++) { newsym[i] = symbols[i]; } newsym[2] = "spread"; newsym[3] = "EMA5"; newsym[4] = "EMA15"; newsym[5] = "EMA30"; var m = new DenseMatrix(6, norm1.Count); m.SetRow(0, norm1); m.SetRow(1, norm2); m.SetRow(2, (norm1 - norm2).ToArray().NormalizeZScore()); m.SetRow(3, EMA.CalcEMA(m.Row(2).ToArray(), 5)); m.SetRow(4, EMA.CalcEMA(m.Row(2).ToArray(), 15)); m.SetRow(5, EMA.CalcEMA(m.Row(2).ToArray(), 30)); string filename = symbols[0].Replace('/', '_') + "-" + symbols[1].Replace('/', '_') + ".html"; ((DenseVector)m.Row(0)).GenerateSimpleGraph("C:\\Sangar\\result.html"); Visualize.GenerateMultiSymbolGraph(newsym, m, DateTime.Now.AddSeconds(-60 * 5 * 300), new TimeSpan(0, 5, 0), "C:\\Sangar\\" + filename); FileUpload.UploadFileToFTP("C:\\Sangar\\" + filename, filename); Spread = m[2, m.ColumnCount - 1]; if (Spread > 2.0 && m[2, m.ColumnCount - 2] <= 2.0) { Emailer.SendEmail(symbols[0] + "-" + symbols[1] + " Spread Above 2.0", "Test"); } if (Spread < -2.0 && m[2, m.ColumnCount - 2] >= -2.0) { Emailer.SendEmail(symbols[0] + "-" + symbols[1] + " Spread Below -2.0", "Test"); } //if (m[2, m.ColumnCount - 1] < 0.5 && m[2, m.ColumnCount - 2] >= 0.5) // Emailer.SendEmail(symbols[0] + "-" + symbols[1] + " Spread Below 0.5", "Test"); //if (m[2, m.ColumnCount - 1] > -0.5 && m[2, m.ColumnCount - 2] <= -0.5) // Emailer.SendEmail(symbols[0] + "-" + symbols[1] + " Spread Above -0.5", "Test"); } catch (Exception e) { Console.WriteLine(e.Message); } }