Пример #1
0
        /// <summary>
        /// Represents the strategy in a readable form.
        /// </summary>
        public override string ToString()
        {
            string str = String.Empty;
            string nl  = Environment.NewLine;
            string nl2 = Environment.NewLine + Environment.NewLine;

            str += "Strategy Name - " + strategyName + nl;
            str += "Symbol - " + Symbol + nl;
            str += "Period - " + DataPeriod.ToString() + nl;
            str += "Same dir signal - " + sameDirSignlAct.ToString() + nl;
            str += "Opposite dir signal - " + oppDirSignlAct.ToString() + nl;
            str += "Use account % entry - " + UseAccountPercentEntry + nl;
            str += "Max open lots - " + MaxOpenLots + nl;
            str += "Entry lots - " + EntryLots + nl;
            str += "Adding lots - " + AddingLots + nl;
            str += "Reducing lots - " + ReducingLots + nl;
            str += "Use Permanent S/L - " + usePermanentSL.ToString() + nl;
            str += "Permanent S/L - " + permanentSLType.ToString() + " " + permanentSL.ToString() + nl;
            str += "Use Permanent T/P - " + usePermanentTP.ToString() + nl;
            str += "Permanent T/P - " + permanentTPType.ToString() + " " + permanentTP.ToString() + nl;
            str += "Use Break Even - " + useBreakEven.ToString() + nl;
            str += "Break Even - " + breakEven.ToString() + " " + permanentTP.ToString() + nl2;
            str += "Description" + nl2 + nl;

            for (int iSlot = 0; iSlot < Slots; iSlot++)
            {
                str += Slot[iSlot].SlotType.ToString() + nl;
                str += indicatorSlot[iSlot].IndParam.ToString() + nl2;
            }

            return(str);
        }
Пример #2
0
        //public List<sp_Forecast_GetDailyAvereageProductTransactions_Result> GetDailyAvereageProductTransactions()
        //{
        //    var result = db.sp_Forecast_GetDailyAvereageProductTransactions();
        //    return result.ToList();
        //}

        //public List<sp_Forecast_GetDailyTimeSpecificAvereageProductTransactions_Result> GetDailyTimeSpecificAvereageProductTransactions()
        //{
        //    var result = db.sp_Forecast_GetDailyTimeSpecificAvereageProductTransactions();
        //    return result.ToList();
        //}

        //public List<sp_Forecast_GetWeeklyAverageTransactions_Result> GetWeeklyAverageTransactions()
        //{
        //    var result = db.sp_Forecast_GetWeeklyAverageTransactions();
        //    return result.ToList();
        //}

        //public List<sp_Forecast_GetWeeklyAvereageProductTransactions_Result> GetWeeklyAvereageProductTransactions()
        //{
        //    var result = db.sp_Forecast_GetWeeklyAvereageProductTransactions();
        //    return result.ToList();
        //}

        //public List<sp_Forecast_GetProductCountYearDayByProductId_Result> GetProductCountYearDayByProductId(int productId)
        //{
        //    var result = db.sp_Forecast_GetProductCountYearDayByProductId(productId);
        //    return result.ToList();
        //}

        //public List<sp_Forecast_GetProductCountMonthDayByProductId_Result> GetProductCountMonthDayByProductId(int productId)
        //{
        //    var result = db.sp_Forecast_GetProductCountMonthDayByProductId(productId);
        //    return result.ToList();
        //}

        //public List<sp_Forecast_GetProductCountDayByProductId_Result> GetProductCountDayByProductId(int productId)
        //{
        //    var result = db.sp_Forecast_GetProductCountDayByProductId(productId);
        //    return result.ToList();
        //}
        #endregion

        #region R_Related

        public ForecastResult ForecastByMethod(int branchId, int productId, string method, string dataType, int periods)
        {
            ForecastResult forecastResult = new ForecastResult();

            //Methods method1 = (Methods)Enum.Parse(typeof(Methods), method, true);
            DataPeriod datatype1 = (DataPeriod)Enum.Parse(typeof(DataPeriod), dataType, true);

            //int productId = 1;
            //Methods method = Methods.rwf; //meanf(YYMMDD,MMDD,MMWWDD,DD), rtw, rtw(with Drift), Moving AVG,ets, Arima, HoltWinters, msts
            //DataPeriod dataType = DataPeriod.Daily;
            //int periods = 50;

            var values = GetCorrespondingDataByPeriod(datatype1, productId);

            //FFCEntities db = new FFCEntities();
            //var list = db.sp_Forecast_GetProductCountYearDayByProductId(productId).ToList();
            //List<double> values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();
            //REngine.SetEnvironmentVariables(@"C:\Program Files\R\R-2.13.1\bin\i386");

            //SetupPath();
            //Log();

            REngine.SetEnvironmentVariables();

            // There are several options to initialize the engine, but by default the following suffice:
            REngine engine = REngine.GetInstance();

            //engine.Initialize();

            // .NET Framework array to R vector.
            //NumericVector testTs = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99, 1000 });
            //NumericVector testTs = engine.CreateNumericVector(new double[] { 10, 20, 30, 40, 50 });
            NumericVector data = engine.CreateNumericVector(values);

            engine.SetSymbol("data", data);
            //auto arima for monthly
            engine.Evaluate("tsValue <- ts(data, frequency=160, start=c(2013.5))");
            engine.Evaluate("library(forecast)");
            engine.Evaluate(String.Format("Fit <- {0}(tsValue)", method.ToString())); // Fit <- Arima(tsValue)
            //MethodManipulation(engine, method);
            engine.Evaluate(String.Format("fcast <- forecast(Fit, h={0})", periods));

            string image = PlotForecast(engine, method.ToString());

            //var a = engine.Evaluate("fcast <- forecast(tsValue, h=5)").AsCharacter();
            NumericVector forecasts = engine.Evaluate("fcast$mean").AsNumeric();

            //NumericVector forecasts = engine.Evaluate("fcast$lower[,2]").AsNumeric();

            forecastResult.BranchId       = branchId;
            forecastResult.ProductId      = productId;
            forecastResult.Method         = db.Forecast_Methods.Where(r => r.ForecastIdentifier == method).Select(a => a.ForecastMethod).FirstOrDefault();
            forecastResult.DatePeriod     = datatype1.ToString();
            forecastResult.ForecastPeriod = periods;
            forecastResult.Values         = forecasts.ToList();
            forecastResult.ImagePath      = "~/Content/Images/" + image;

            //foreach (var item in forecasts)
            //{
            //    Console.WriteLine(item);
            //}

            //engine.Dispose();

            return(forecastResult);
        }