public static double[] PriceDataFE_pred(Series <DateTime, double> input) { int shiftn = 0; var data = input.Shift(shiftn); var MA3 = data.Window(3).Select(x => x.Value.Mean()); var MA5 = data.Window(5).Select(x => x.Value.Mean()); var MA10 = data.Window(10).Select(x => x.Value.Mean()); var dataMA3 = (data / MA3).Select(x => Math.Log(x.Value)); var dataMA5 = (data / MA5).Select(x => Math.Log(x.Value)); var dataMA10 = (data / MA10).Select(x => Math.Log(x.Value)); var MA3MA5 = (MA3 / MA5).Select(x => Math.Log(x.Value)); var MA3MA10 = (MA3 / MA10).Select(x => Math.Log(x.Value)); var MA5MA10 = (MA5 / MA10).Select(x => Math.Log(x.Value)); var MMP3 = data.Window(3).Select(x => Math.Log(x.Value.Max() / x.Value.Min())); var MMP5 = data.Window(5).Select(x => Math.Log(x.Value.Max() / x.Value.Min())); var MMP10 = data.Window(10).Select(x => Math.Log(x.Value.Max() / x.Value.Min())); string dataMA3column = "PriceMA3" + Convert.ToString(shiftn); string dataMA5column = "PriceMA5" + Convert.ToString(shiftn); string dataMA10column = "PriceMA10" + Convert.ToString(shiftn); string MA3MA5column = "MA3MA5PRICE" + Convert.ToString(shiftn); string MA3MA10column = "MA3MA10PRICE" + Convert.ToString(shiftn); string MA5MA10column = "MA5MA10PRICE" + Convert.ToString(shiftn); string MMP3column = "MMP3" + Convert.ToString(shiftn); string MMP5column = "MMP5" + Convert.ToString(shiftn); string MMP10column = "MMP10" + Convert.ToString(shiftn); var Features = new FrameBuilder.Columns <DateTime, string> { { dataMA3column, dataMA3 }, { dataMA5column, dataMA5 }, { dataMA10column, dataMA10 }, { MA3MA5column, MA3MA5 }, { MA3MA10column, MA3MA10 }, { MA5MA10column, MA5MA10 }, { MMP3column, MMP3 }, { MMP5column, MMP5 }, { MMP10column, MMP10 } }.Frame; var row_length = Features.RowCount; var col_length = Features.ColumnCount; double[] delay_1 = Features.GetRowAt <double>(row_length - 1).Values.ToArray <double>(); double[] features_pred = new double[col_length]; for (int i = 0; i < col_length; i++) { features_pred[i] = delay_1[i]; } return(features_pred); }
public static double[] Features_engineering_pred(Series <DateTime, double> input) { // Features engineering function for generating prediction input int shiftn = 0; var data = input.Shift(shiftn); var data2 = data.Select(x => Math.Pow(x.Value, 2)); var MA3 = data.Window(3).Select(x => x.Value.Mean()); var MA5 = data.Window(5).Select(x => x.Value.Mean()); var MA10 = data.Window(10).Select(x => x.Value.Mean()); var diffdataMA3 = (data / MA3).Select(x => x.Value - 1); var diffdataMA5 = (data / MA5).Select(x => x.Value - 1); var diffdataMA10 = (data / MA10).Select(x => x.Value - 1); var diffMA3MA5 = (MA3 / MA5).Select(x => x.Value - 1); var diffMA3MA10 = (MA3 / MA10).Select(x => x.Value - 1); var diffMA5MA10 = (MA5 / MA10).Select(x => x.Value - 1); var SD3 = data.Window(3).Select(x => x.Value.StdDev()); var SD5 = data.Window(5).Select(x => x.Value.StdDev()); var SD10 = data.Window(10).Select(x => x.Value.StdDev()); var RSI3 = data.Window(3).Select(x => RSI_func(x, 3)); var RSI5 = data.Window(5).Select(x => RSI_func(x, 5)); var RSI10 = data.Window(10).Select(x => RSI_func(x, 10)); var K3 = data.Window(3).Select(x => K_func(x, 3)); var K5 = data.Window(5).Select(x => K_func(x, 5)); var K10 = data.Window(10).Select(x => K_func(x, 10)); string Returncolumn = "Return" + Convert.ToString(shiftn); string Powercolumn = "Power" + Convert.ToString(shiftn); string MA3column = "MA3" + Convert.ToString(shiftn); string MA5column = "MA5" + Convert.ToString(shiftn); string MA10column = "MA10" + Convert.ToString(shiftn); string SD3column = "SD3" + Convert.ToString(shiftn); string SD5column = "SD5" + Convert.ToString(shiftn); string SD10column = "SD10" + Convert.ToString(shiftn); string CompareDataColumn1 = "dataMA3" + Convert.ToString(shiftn); string CompareDataColumn2 = "dataMA5" + Convert.ToString(shiftn); string CompareDataColumn3 = "dataMA10" + Convert.ToString(shiftn); string Compare1column = "MA3MA5" + Convert.ToString(shiftn); string Compare2column = "MA3MA10" + Convert.ToString(shiftn); string Compare3column = "MA5MA10" + Convert.ToString(shiftn); string RSI3column = "RSI3" + Convert.ToString(shiftn); string RSI5column = "RSI5" + Convert.ToString(shiftn); string RSI10column = "RSI10" + Convert.ToString(shiftn); string K3column = "K3" + Convert.ToString(shiftn); string K5column = "K5" + Convert.ToString(shiftn); string K10column = "K10" + Convert.ToString(shiftn); var Features = new FrameBuilder.Columns <DateTime, string> { { Returncolumn, data }, { Powercolumn, data2 }, { MA3column, MA3 }, { MA5column, MA5 }, { MA10column, MA10 }, { Compare1column, diffMA3MA5 }, { Compare2column, diffMA3MA10 }, { Compare3column, diffMA5MA10 }, { CompareDataColumn1, diffdataMA3 }, { CompareDataColumn2, diffdataMA5 }, { CompareDataColumn3, diffdataMA10 }, { SD3column, SD3 }, { SD5column, SD5 }, { SD10column, SD10 }, { RSI3column, RSI3 }, { RSI5column, RSI5 }, { RSI10column, RSI10 }, { K3column, K3 }, { K5column, K5 }, { K10column, K10 } }.Frame; var row_length = Features.RowCount; var col_length = Features.ColumnCount; double[] delay_1 = Features.GetRowAt <double>(row_length - 1).Values.ToArray <double>(); double[] delay_2 = Features.GetRowAt <double>(row_length - 2).Values.ToArray <double>(); double[] delay_3 = Features.GetRowAt <double>(row_length - 3).Values.ToArray <double>(); double[] features_pred = new double[col_length * 3]; for (int i = 0; i < col_length; i++) { features_pred[i] = delay_1[i]; } for (int i = 0; i < col_length; i++) { features_pred[i + col_length] = delay_2[i]; } for (int i = 0; i < col_length; i++) { features_pred[i + col_length * 2] = delay_3[i]; } return(features_pred); }