private void DoRanking()
        {
            this.ShowReccount("");

            this.myValueType = ValueTypes.Amount;
            this.Amount2PercentDenominator = Settings.sysStockTotalCapAmt;

            resultTab.TabPages.Clear();
            StringCollection stockCodeList = codeListLb.myValues;
            StringCollection timeRangeList = timeRangeLb.myCheckedValues;
            string[] strategyList = common.system.Collection2List(strategyClb.myCheckedValues);
            progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = stockCodeList.Count;

            string timeScaleCode = timeScaleCb.myValue.Code;
            EstimateOptions estimateOption = new EstimateOptions();

            DataAccess.Libs.ClearCache();

            ArrayList resulTblList = new ArrayList();
            this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());
            int codeStartIdx=0, codeEndIdx=0;
            while (codeStartIdx < stockCodeList.Count)
            {
                codeEndIdx += Settings.sysNumberOfItemsInBatchProcess;
                if (codeEndIdx >= stockCodeList.Count) codeEndIdx = stockCodeList.Count - 1;

                //Create Tab and grid for each code
                resulTblList.Clear();
                string[] processCodeList = new string[codeEndIdx-codeStartIdx+1];
                for (int idx1 = codeStartIdx,idx2=0; idx1 <= codeEndIdx; idx1++,idx2++)
                {
                    resulTblList.Add(CreateDataTable(timeRangeList, strategyList));
                    CreateResultGrid(stockCodeList[idx1], resulTblList[idx2] as DataTable);
                    processCodeList[idx2] = stockCodeList[idx1];
                }

                for (int colId = 0; colId < timeRangeList.Count; colId++)
                {
                    AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(timeRangeList[colId]);
                    decimal[][] profitList = DataAccess.Libs.Estimate_Matrix_Profit(timeRange, timeScaleCode, processCodeList, strategyList, estimateOption);
                    for (int idx1 = 0; idx1 < profitList.Length; idx1++)
                    {
                        DataTable tbl = resulTblList[idx1] as DataTable;
                        for (int idx2 = 0; idx2 < profitList[idx1].Length; idx2++)
                        {
                            tbl.Rows[idx2][colId + 1] = profitList[idx1][idx2];
                        }
                    }
                    Application.DoEvents();
                }
                progressBar.Value = codeEndIdx+1;
                this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());
                codeStartIdx = codeEndIdx + 1;
            }
        }
Beispiel #2
0
        private void DoBackTesting()
        {
            this.ShowReccount("");
            this.myValueType = ValueTypes.Amount;
            this.Amount2PercentDenominator = Settings.sysStockTotalCapAmt;
            StringCollection strategyList = strategyClb.myCheckedValues;
            StringCollection stockCodeList = codeSelectLb.myValues;
            //Analysis cached data so we MUST reset to clear cache to ensure the system run correctly
            DataAccess.Libs.ClearCache();
            EstimateOptions estimateOption = new EstimateOptions();

            DataTable retsultTbl = CreateEstimateTbl(strategyList);
            SetDataGrid(resultDataGrid, retsultTbl);

            progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = stockCodeList.Count;
            AppTypes.TimeRanges timeRange = periodicityEd.myTimeRange;
            string timeScaleCode = periodicityEd.myTimeScale.Code;
            string[] strategy = common.system.Collection2List(strategyList);

            this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());

            int codeStartIdx=0, codeEndIdx=0;
            while (codeStartIdx < stockCodeList.Count)
            {
                codeEndIdx += Settings.sysNumberOfItemsInBatchProcess;
                if (codeEndIdx >= stockCodeList.Count) codeEndIdx = stockCodeList.Count - 1;

                string[] stocks = common.system.Collection2List(stockCodeList, codeStartIdx, codeEndIdx);
                decimal[][] retList = DataAccess.Libs.Estimate_Matrix_Profit(timeRange, timeScaleCode, stocks, strategy, estimateOption);
                for (int idx = 0; idx < retList.Length; idx++)
                {
                    DataRow row = retsultTbl.Rows.Add(stockCodeList[idx + codeStartIdx]);
                    for (int colId = 0; colId < retList[idx].Length; colId++)
                    {
                        row[colId + 1] = retList[idx][colId]; 
                    }
                }
                Application.DoEvents();
                codeStartIdx = codeEndIdx + 1;
                progressBar.Value = codeEndIdx+1;
                this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());
            }
            common.system.RemoveEmptyItems(retsultTbl);
            SetDataGrid(resultDataGrid, retsultTbl);

            SetEstimateDataGrid(application.Strategy.StrategyLibs.GetStrategyStats(retsultTbl));
        }
Beispiel #3
0
        private void ShowTradePointEstimate(Tools.Forms.tradeAnalysis sender, string strategyCode, 
                                            EstimateOptions option, databases.tmpDS.tradeEstimateDataTable tbl)
        {
            string formName = constFormNameEstimateTrade + "-" + sender.myData.DataStockCode;
            Tools.Forms.profitEstimate myForm = (Tools.Forms.profitEstimate)cachedForms.Find(formName);
            if (myForm == null || myForm.IsDisposed)
            {
                myForm = new Tools.Forms.profitEstimate();
                myForm.Name = formName;
                cachedForms.Add(formName, myForm);

                MapForm(myForm, strategyEstimationiMenuItem);
            }
            //myForm.CheckTradepoints(sendder.myData, tradePoints);

            myForm.myDataParam = new DataParams(sender.myData.DataTimeScale.Code,sender.myData.DataTimeRange,0);
            myForm.myStockCode = sender.myData.DataStockCode;
            myForm.myStrategyCode = strategyCode;
            myForm.myOptions = option;
            myForm.SetData(tbl);
            myForm.IsShowChart = true;
            myForm.PlotProfitChart();
            myForm.IsShowAllTransactions = false;
            myForm.Show(dockPanel, DockState.DockBottom);
            myForm.BringToFront();
        }
        public void PlotStrategyTradepoints(application.Strategy.Meta meta, bool showEstimation)
        {
            ShowMessage("");
            EstimateOptions estOption = new EstimateOptions();
            data.tmpDS.tradeEstimateDataTable tbl = new data.tmpDS.tradeEstimateDataTable();
            TradePointInfo[] tradePoints = DataAccess.Libs.GetTradePointWithEstimationDetail(myData.DataTimeRange,myData.DataTimeScale.Code,myData.DataStockCode,meta.Code,
                                                                                             estOption, out tbl); 
            /// Estimate trade points and set tradepoint's [isValid] property to mark whether a tradepoint is valid or not.
            for (int idx = 0; idx < tradePoints.Length; idx++)
            {
                tradePoints[idx].isValid = !tbl[idx].ignored; 
            }
            PlotStrategyTradepoints(application.Strategy.Libs.ToTradePoints(tradePoints), pricePanel);

            //Call estimation handler if any.
            if (showEstimation && myEstimateTradePoints != null) 
                myEstimateTradePoints(this,meta.Code,estOption, tbl);
        }
Beispiel #5
0
 public static decimal[][] Estimate_Matrix_Profit(AppTypes.TimeRanges timeRange, string timeScaleCode,
                                                  string[] stocks, string[] strategyList, EstimateOptions option)
 {
     try
     {
         lock (myClient)
         {
             return myClient.Estimate_Matrix_Profit(timeRange, timeScaleCode, stocks, strategyList, option);
         }
     }
     catch (Exception er)
     {
         if (OnError != null) OnError(er);
     }
     return null;
 }
Beispiel #6
0
 public static TradePointInfo[] GetTradePointWithEstimationDetail(DataParams dataParam,string stockCode, string strategyCode, 
                                                                  EstimateOptions options,out databases.tmpDS.tradeEstimateDataTable toTbl)
 {
     try
     {
         lock (myClient)
         {
             return myClient.GetTradePointWithEstimationDetail(out toTbl, dataParam, stockCode, strategyCode, options);
         }
     }
     catch (Exception er)
     {
         toTbl = null;
         if (OnError != null) OnError(er);
     }
     return null;
 }
Beispiel #7
0
 public static TradePointInfo[] GetTradePointWithEstimationDetail(AppTypes.TimeRanges timeRange, string timeScaleCode,
                                                                  string stockCode, string strategyCode, EstimateOptions options,
                                                                  out data.tmpDS.tradeEstimateDataTable toTbl)
 {
     return myClient.GetTradePointWithEstimationDetail(out toTbl, timeRange, timeScaleCode, stockCode, strategyCode, options);
 }
        public void PlotStrategyTradepoints(application.Strategy.StrategyMeta meta, bool showEstimation, EstimateTradePointFunc estimateFunc)
        {
            int idx;
            ShowMessage("");
            EstimateOptions estOption = new EstimateOptions();
            databases.tmpDS.tradeEstimateDataTable tbl = new databases.tmpDS.tradeEstimateDataTable();
            application.StrategyStatistics statistics=new StrategyStatistics();
            //TradePointInfo[]
            tradePoints = DataAccess.Libs.GetTradePointWithEstimationDetail(myData.myDataParam,myData.DataStockCode,meta.Code,
                                                                                             estOption, out tbl,out statistics);
            /// Estimate trade points and set tradepoint's [isValid] property to mark whether a tradepoint is valid or not.
            for (idx = 0; idx < tradePoints.Length; idx++)
            {
                tradePoints[idx].isValid = !tbl[idx].ignored;
            }

            for (idx = tradePoints.Length - 1; idx > 0; idx--)
                if (tradePoints[idx].isValid) break;

            TradePointInfo tpiTradePointInfo = (TradePointInfo)tradePoints[idx];
            BusinessInfo biLastTrade = tpiTradePointInfo.BusinessInfo;
            BusinessInfo biLastPoint=tradePoints[tradePoints.Length-1].BusinessInfo;

            double price= myData.Close[myData.Close.Count-1];
            double risk = (biLastPoint.Short_Resistance - price) / (price - biLastPoint.Short_Support);
            //string sResult = "Close price=" + price+
            //                 "Target="+biLastTrade.Short_Target+
            //                 "Resistance=" + biLastPoint.Short_Resistance +
            //                 " Support=" + biLastPoint.Short_Support +
            //                 " Risk return=" +risk+
            //                 " Winning Percentage:"+ String.Format("{0:P2}",statistics.dWinningPercentagePerTrade)+
            //                 " Max %Win Per Trade:" +  String.Format("{0:P2}",statistics.dMaxWinningPercentage)+
            //                 " Max %Lose Per Trade" + String.Format("{0:P2}", statistics.dMaxLosingPercentage)+
            //                 " Average %Win Per Trade" + String.Format("{0:P2}", statistics.dAverageWinningPercentage)+
            //                 " Average %Lose Per Trade" + String.Format("{0:P2}", statistics.dAverageLosingPercentage); ;

            PlotStrategyTradepoints(application.Strategy.StrategyLibs.ToTradePoints(tradePoints), pricePanel);

            //MessageBox.Show(sResult);
            //Show form
            //Tools.Forms.TradeStatistics formStatistic = (client.main)this.ParentForm;
            if (formStatistic == null)
            {
                formStatistic = new Tools.Forms.TradeStatistics();
                formStatistic.AddStatisticInfo("Close price", price);
                formStatistic.AddStatisticInfo("Target", biLastTrade.Short_Target);
                formStatistic.AddStatisticInfo("Resistance", biLastPoint.Short_Resistance);
                formStatistic.AddStatisticInfo("Support", biLastPoint.Short_Support);
                formStatistic.AddStatisticInfo("Risk return", String.Format("{0:0.0%}", risk));
                formStatistic.AddStatisticInfo("Winning Percentage", String.Format("{0:0.0%}", statistics.dWinningPercentagePerTrade));
                formStatistic.AddStatisticInfo("Max %Win Per Trade", String.Format("{0:0.0%}", statistics.dMaxWinningPercentage));
                formStatistic.AddStatisticInfo("Max %Lose Per Trade", String.Format("{0:0.0%}", statistics.dMaxLosingPercentage));
                formStatistic.AddStatisticInfo("Average %Win Per Trade", String.Format("{0:0.0%}", statistics.dAverageWinningPercentage));
                formStatistic.AddStatisticInfo("Average %Lose Per Trade", String.Format("{0:0.0%}", statistics.dAverageLosingPercentage));

                formStatistic.Show(this.DockPanel, DockState.DockRight);
            }
            else
            {
                formStatistic.ReAssignInfo(0,price);
                formStatistic.ReAssignInfo(1, biLastTrade.Short_Target);
                formStatistic.ReAssignInfo(2, biLastPoint.Short_Resistance);
                formStatistic.ReAssignInfo(3, biLastPoint.Short_Support);
                formStatistic.ReAssignInfo(4, String.Format("{0:0.0%}", risk));
                formStatistic.ReAssignInfo(5, String.Format("{0:0.0%}", statistics.dWinningPercentagePerTrade));
                formStatistic.ReAssignInfo(6, String.Format("{0:0.0%}", statistics.dMaxWinningPercentage));
                formStatistic.ReAssignInfo(7, String.Format("{0:0.0%}", statistics.dMaxLosingPercentage));
                formStatistic.ReAssignInfo(8, String.Format("{0:0.0%}", statistics.dAverageWinningPercentage));
                formStatistic.ReAssignInfo(9, String.Format("{0:0.0%}", statistics.dAverageLosingPercentage));
                formStatistic.Refresh();
            }
            //Call estimation handler if any.
            if (showEstimation && estimateFunc != null)
                estimateFunc(this, meta.Code, estOption, tbl);
        }
Beispiel #9
0
        private void DoBackTestUseDB()
        {
            this.myValueType = ValueTypes.Amount;
            this.Amount2PercentDenominator = Settings.sysStockTotalCapAmt;
            StringCollection strategyList = strategyClb.myCheckedValues;
            StringCollection stockCodeList = codeSelectLb.myValues;
            DataTable testRetsultTbl = CreateEstimateTbl(strategyList);
            SetDataGrid(resultDataGrid, testRetsultTbl);

            progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = stockCodeList.Count;

            EstimateOptions estOptions = new EstimateOptions();
            for (int rowId = 0; rowId < stockCodeList.Count; rowId++)
            {
                application.AnalysisData analysisData = new application.AnalysisData(periodicityEd.myTimeRange, periodicityEd.myTimeScale,
                                                                     stockCodeList[rowId], commonClass.DataAccessMode.WebService);
                DataRow row = testRetsultTbl.Rows.Add(stockCodeList[rowId]);
                for (int colId = 0; colId < strategyList.Count; colId++)
                {
                    try
                    {
                        //Analysis cached data so we MUST clear cache to ensure the system run correctly
                        application.Strategy.Data.ClearCache();
                        application.Strategy.Data.TradePoints advices = application.Strategy.Libs.Analysis(analysisData, strategyList[colId]);
                        if (advices != null)
                        {
                            row[colId + 1] = application.Strategy.Libs.EstimateTrading_Profit(analysisData, application.Strategy.Libs.ToTradePointInfo(advices), estOptions);
                        }
                        else row[colId + 1] = 0;
                    }
                    catch (Exception er)
                    {
                        this.WriteError(stockCodeList[rowId] + " : " + strategyList[colId], er.Message);
                        this.ShowError(er);
                    }
                }
                progressBar.Value++;
                this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());
                Application.DoEvents();
            }
            SetEstimateDataGrid(application.Strategy.Libs.GetStrategyStats(testRetsultTbl));
        }
Beispiel #10
0
 public static decimal[][] Estimate_Matrix_Profit(AppTypes.TimeRanges timeRange, string timeScaleCode,
                                                  string[] stocks, string[] strategyList, EstimateOptions option)
 {
     return myClient.Estimate_Matrix_Profit(timeRange, timeScaleCode, stocks, strategyList, option);
 }
        private void DoRankingDB()
        {
            this.myValueType = ValueTypes.Amount;
            this.Amount2PercentDenominator = Settings.sysStockTotalCapAmt;

            resultTab.TabPages.Clear();
            StringCollection stockCodeList = codeListLb.myValues;
            StringCollection timeRangeList = timeRangeLb.myCheckedValues;
            string[] strategyList = common.system.Collection2List(strategyClb.myCheckedValues);
            progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = stockCodeList.Count * timeRangeList.Count;

            EstimateOptions  estimateOption = new EstimateOptions();

            for (int stockCodeId = 0; stockCodeId < stockCodeList.Count; stockCodeId++)
            {
                string stockCode = stockCodeList[stockCodeId].ToString();
                DataTable testRetsultTbl = CreateDataTable(timeRangeList, strategyList);
                common.controls.baseDataGridView resultGrid = CreateResultGrid(stockCode, testRetsultTbl);

                for (int colId = 0; colId < timeRangeList.Count; colId++)
                {
                    try
                    {
                        progressBar.Value++;
                        Application.DoEvents();
                        this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());

                        AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(timeRangeList[colId]);
                        application.AnalysisData analysisData = new application.AnalysisData(timeRange, timeScaleCb.myValue, stockCode,
                                                                             commonClass.DataAccessMode.WebService);
                        for (int rowId = 0; rowId < strategyList.Length; rowId++)
                        {
                            testRetsultTbl.Rows[rowId][colId + 1] = 0;
                            //Analysis cached data so we MUST clear cache to ensure the system run correctly
                            application.Strategy.Data.ClearCache();
                            application.Strategy.Data.TradePoints advices = application.Strategy.Libs.Analysis(analysisData, strategyList[rowId]);
                            if (advices != null)
                            {
                                testRetsultTbl.Rows[rowId][colId + 1] = 
                                    application.Strategy.Libs.EstimateTrading_Profit(analysisData,application.Strategy.Libs.ToTradePointInfo(advices),estimateOption);
                            }
                        }
                    }
                    catch (Exception er)
                    {
                        this.WriteError(stockCodeList[stockCodeId] + " : " + timeRangeList[colId] + " : " + strategyList[colId], er.Message);
                        //this.ShowError(er);
                    }
                }
            }
        }
 public List<decimal[]> Estimate_Matrix_Profit(AppTypes.TimeRanges timeRange, string timeScaleCode,
     string[] stockCodeList, string[] strategyList,
     EstimateOptions option)
 {
     try
     {
         return application.Strategy.StrategyLibs.Estimate_Matrix_Profit(timeRange, AppTypes.TimeScaleFromCode(timeScaleCode),
                                                     common.system.List2Collection(stockCodeList),
                                                     common.system.List2Collection(strategyList), option);
     }
     catch (Exception ex)
     {
         WriteSysLogLocal("WS005", ex);
     }
     return null;
 }
 public TradePointInfo[] GetTradePointWithEstimationDetail(DataParams dataParam,string stockCode, string strategyCode, EstimateOptions options,
     out databases.tmpDS.tradeEstimateDataTable toTbl, out application.StrategyStatistics statistics)
 {
     toTbl = null;
     statistics = null;
     try
     {
         string dataKey = LoadAnalysisData(stockCode, dataParam, false);
         TradePointInfo[] tradePoints = Analysis(dataKey, strategyCode);
         statistics = new application.StrategyStatistics();
         toTbl = application.Strategy.StrategyLibs.EstimateTrading_Details(sysDataCache.Find(dataKey) as application.AnalysisData, tradePoints, options,out statistics);
         return tradePoints;
     }
     catch (Exception ex)
     {
         WriteSysLogLocal("WS083", ex);
     }
     return null;
 }
Beispiel #14
0
 public TradePointInfo[] GetTradePointWithEstimationDetail(AppTypes.TimeRanges timeRange, string timeScaleCode,
                                                           string stockCode, string strategyCode, EstimateOptions options,
                                                           out data.tmpDS.tradeEstimateDataTable toTbl)
 {
     string dataKey = LoadAnalysisData(timeRange, timeScaleCode, stockCode, false);
     TradePointInfo[] tradePoints = Analysis(dataKey, strategyCode);
     toTbl = application.Strategy.Libs.EstimateTrading_Details(sysDataCache.Find(dataKey) as AnalysisData, tradePoints, options);
     return tradePoints;
 }
Beispiel #15
0
 public List<decimal[]> Estimate_Matrix_Profit(AppTypes.TimeRanges timeRange, string timeScaleCode,
                                               string[] stockCodeList, string[] strategyList,
                                               EstimateOptions option)
 {
     return application.Strategy.Libs.Estimate_Matrix_Profit(timeRange, AppTypes.TimeScaleFromCode(timeScaleCode), 
                                                 common.system.List2Collection(stockCodeList),
                                                 common.system.List2Collection(strategyList), option);
 }