Пример #1
0
        public static List <double[]> Estimate_Matrix_LastBizWeight(AppTypes.TimeRanges timeRange, AppTypes.TimeScale timeScale,
                                                                    StringCollection stockCodeList, StringCollection strategyList)
        {
            List <double[]> retList = new List <double[]>();

            for (int rowId = 0; rowId < stockCodeList.Count; rowId++)
            {
                Data.ClearCache();
                AnalysisData analysisData = new AnalysisData(timeRange, timeScale, stockCodeList[rowId], DataAccessMode.Local);
                double[]     rowRetList   = new double[strategyList.Count];
                for (int colId = 0; colId < strategyList.Count; colId++)
                {
                    Data.TradePoints tradePoints = Analysis(analysisData, strategyList[colId]);
                    if (tradePoints != null && tradePoints.Count > 0)
                    {
                        rowRetList[colId] = (tradePoints[tradePoints.Count - 1] as TradePointInfo).BusinessInfo.Weight;
                    }
                    else
                    {
                        rowRetList[colId] = double.NaN;
                    }
                }
                retList.Add(rowRetList);
            }
            return(retList);
        }
Пример #2
0
        public static List <decimal[]> Estimate_Matrix_Profit(AppTypes.TimeRanges timeRange, AppTypes.TimeScale timeScale,
                                                              StringCollection stockCodeList, StringCollection strategyList, EstimateOptions option)
        {
            List <decimal[]> retList = new List <decimal[]>();

            for (int rowId = 0; rowId < stockCodeList.Count; rowId++)
            {
                Data.ClearCache();
                AnalysisData analysisData = new AnalysisData(timeRange, timeScale, stockCodeList[rowId], DataAccessMode.Local);
                decimal[]    rowRetList   = new decimal[strategyList.Count];
                for (int colId = 0; colId < strategyList.Count; colId++)
                {
                    Data.TradePoints advices = Analysis(analysisData, strategyList[colId]);
                    if (advices != null)
                    {
                        rowRetList[colId] = EstimateTrading_Profit(analysisData, ToTradePointInfo(advices), option);
                    }
                    else
                    {
                        rowRetList[colId] = 0;
                    }
                }
                retList.Add(rowRetList);
            }
            return(retList);
        }
Пример #3
0
        /// <summary>
        /// Calculated primary strategy data. If an strategy has several output,one is called "primary data"
        /// and others are calles "exatra data".
        /// </summary>
        /// <param name="myData"> Data used to calculate strategy data.</param>
        /// <param name="meta">strategy meta data</param>
        /// <returns>Null if error</returns>
        public static Data.TradePoints Analysis(AnalysisData myData, Meta meta)
        {
            string cacheName = "data-" + myData.DataStockCode + "-" +
                               myData.DataTimeRange.ToString() + "-" +
                               myData.DataTimeScale.Code + "-" +
                               meta.ClassType.Name;

            object[] processParas = new object[2];
            processParas[0] = myData;
            processParas[1] = meta.Parameters;
            //First , find in cache
            Data.TradePoints tradePoints = (Data.TradePoints)Data.FindInCache(cacheName);
            if (tradePoints != null)
            {
                return(tradePoints);
            }

            //Then, Call Execute() method to get trading points.
            object strategyInstance = GetStrategyInstance(meta.ClassType);

            if (strategyInstance == null)
            {
                return(null);
            }
            tradePoints = (Data.TradePoints)meta.ClassType.InvokeMember("Execute",
                                                                        BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, strategyInstance, processParas);

            Data.AddToCache(cacheName, tradePoints);
            return(tradePoints);
        }
Пример #4
0
        public static List <double[]> Estimate_Matrix_LastBizWeight(commonClass.DataParams dataParm, StringCollection stockCodeList, StringCollection strategyList)
        {
            //System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            //stopWatch.Start();
            List <double[]> retList = new List <double[]>();

            for (int rowId = 0; rowId < stockCodeList.Count; rowId++)
            {
                Data.ClearCache();
                AnalysisData analysisData = new AnalysisData(stockCodeList[rowId], dataParm);
                double[]     rowRetList   = new double[strategyList.Count];
                for (int colId = 0; colId < strategyList.Count; colId++)
                {
                    Data.TradePoints tradePoints = Analysis(analysisData, strategyList[colId]);
                    if (tradePoints != null && tradePoints.Count > 0)
                    {
                        rowRetList[colId] = (tradePoints[tradePoints.Count - 1] as TradePointInfo).BusinessInfo.Weight;
                        //if (common.Settings.sysDebugMode && (tradePoints[tradePoints.Count - 1] as TradePointInfo).DataIdx != analysisData.Close.Count - 1)
                        //{
                        //    commonClass.SysLibs.WriteSysLog( AppTypes.SyslogTypes.Others,stockCodeList[rowId], strategyList[colId]);
                        //}
                    }
                    else
                    {
                        rowRetList[colId] = double.NaN;
                    }
                }
                retList.Add(rowRetList);
            }
            //stopWatch.Stop();
            //string tmp = common.dateTimeLibs.TimeSpan2String(stopWatch.Elapsed);
            return(retList);
        }
Пример #5
0
 public static TradePointInfo[] ToTradePointInfo(Data.TradePoints tradePoints)
 {
     TradePointInfo[] tradePointInfos = new TradePointInfo[tradePoints.Count];
     for (int idx = 0; idx < tradePoints.Count; idx++)
     {
         tradePointInfos[idx] = (TradePointInfo)tradePoints[idx];
     }
     return(tradePointInfos);
 }
Пример #6
0
 //Convert
 public static Data.TradePoints ToTradePoints(TradePointInfo[] tradePointInfos)
 {
     Data.TradePoints tradePointList = new Data.TradePoints();
     for (int idx = 0; idx < tradePointInfos.Length; idx++)
     {
         tradePointList.Add(tradePointInfos[idx]);
     }
     return(tradePointList);
 }