Пример #1
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);
        }
Пример #2
0
 public DataParams Clone(DataParams dataParam)
 { 
     DataParams newDataParam = new DataParams();
     newDataParam.TimeRange = dataParam.TimeRange;
     newDataParam.MaxDataCount = dataParam.MaxDataCount;
     newDataParam.TimeScale = dataParam.TimeScale;
     return newDataParam;
 }
Пример #3
0
        public DataParams Clone(DataParams dataParam)
        {
            DataParams newDataParam = new DataParams();

            newDataParam.TimeRange    = dataParam.TimeRange;
            newDataParam.MaxDataCount = dataParam.MaxDataCount;
            newDataParam.TimeScale    = dataParam.TimeScale;
            return(newDataParam);
        }
Пример #4
0
 protected void ShowTradeTransactions(databases.tmpDS.stockCodeRow stockCodeRow, string strategyCode, DataParams dataParam)
 {
     string formName = stockCodeRow.code.Trim() + "," + dataParam.TimeRange.ToString() + "," + application.Strategy.StrategyLibs.GetMetaName(strategyCode) + "," + dataParam.TimeScale;
     profitEstimate myForm = profitEstimate.GetForm(formName);
     myForm.myDataParam = dataParam;
     myForm.myStockCode = stockCodeRow.code;
     myForm.myStrategyCode = strategyCode;
     myForm.myOptions = new EstimateOptions();
     myForm.ReLoad();
     myForm.Text = "(" + formName + ")";
     if (this.myDockedPane != null) myForm.Show(this.myDockedPane);
     else myForm.ShowDialog();
 }
Пример #5
0
        private void profitDetailMenu_Click(object sender, EventArgs e)
        {
            try
            {
                common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView;
                if (resultDataGrid == null || resultDataGrid.CurrentRow == null || resultDataGrid.CurrentCell == null) return;

                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                if (resultDataGrid.CurrentCell.ColumnIndex<0) return;
                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details

                string stockCode = resultTab.SelectedTab.Name;
                databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(stockCode);
                if (stockCodeRow == null) return;
                application.Strategy.Meta meta = application.Strategy.Libs.FindMetaByName(resultDataGrid.CurrentRow.Cells[0].Value.ToString());

                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                int colId = resultDataGrid.CurrentCell.ColumnIndex == 0 ? 1 : resultDataGrid.CurrentCell.ColumnIndex;
                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                DataParams dataParam = new DataParams(timeScaleCb.myValue.Code, AppTypes.TimeRangeFromCode(resultDataGrid.Columns[colId].DataPropertyName),0);
                ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
Пример #6
0
        private void allProfitDetailMenu_Click(object sender, EventArgs e)
        {
            try
            {
                using (new DataAccess.PleaseWait())
                {
                    common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView;
                    if (resultDataGrid == null) return;

                    string stockCode = resultTab.SelectedTab.Name;
                    databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(stockCode);
                    if (stockCodeRow == null) return;

                    DataParams dataParam = new DataParams(timeScaleCb.myValue.Code, AppTypes.TimeRanges.None,0);
                    //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                    int min = int.MaxValue;
                    int max = -1;
                    for (int i = 0; i < resultDataGrid.SelectedCells.Count; i++)                   
                    {
                        if (resultDataGrid.SelectedCells[i].RowIndex > max)
                            max = resultDataGrid.SelectedCells[i].RowIndex;
                        if (resultDataGrid.SelectedCells[i].RowIndex < min)
                            min = resultDataGrid.SelectedCells[i].RowIndex;
                    }
                    //if (resultDataGrid.SelectedRows.Count > 0)
                    if (min<max)
                    {
                        for (int rowId = min; rowId <= max; rowId++)
                        {
                            application.Strategy.Meta meta = application.Strategy.Libs.FindMetaByName(resultDataGrid.Rows[rowId].Cells[0].Value.ToString());
                            for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++)
                            {
                                dataParam.TimeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName);
                                ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
                            }
                        }
                        //for (int rowId = 0; rowId < resultDataGrid.SelectedRows.Count; rowId++)
                        //{
                        //    application.Strategy.Meta meta = application.Strategy.Libs.FindMetaByName(resultDataGrid.SelectedRows[rowId].Cells[0].Value.ToString());
                        //    for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++)
                        //    {
                        //        dataParam.TimeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName);
                        //        ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
                        //    }
                        //}
                    }
                    //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                    else
                    {
                        if (resultDataGrid.CurrentRow != null)
                        {
                            application.Strategy.Meta meta = application.Strategy.Libs.FindMetaByName(resultDataGrid.CurrentRow.Cells[0].Value.ToString());
                            for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++)
                            {
                                dataParam.TimeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName);
                                ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
Пример #7
0
        private void dataGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView;
                if (resultDataGrid == null) return;
                string stockCode = resultTab.SelectedTab.Name;  

                if (resultDataGrid.CurrentRow == null) return;
                AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[e.ColumnIndex].DataPropertyName);
                databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(stockCode);
                if (stockCodeRow == null) return;

                string strategyCode = resultDataGrid.CurrentRow.Cells[0].Value.ToString();
                DataParams dataParam = new DataParams(timeScaleCb.myValue.Code, timeRange,0);
                ShowTradeTransactions(stockCodeRow, strategyCode, dataParam);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
Пример #8
0
        private void DoScreening()
        {
            decimal weight = 0;
            StringCollection stockCodeList = stockCodeLb.myValues;

            StringCollection strategyList = new StringCollection();
            for (int idx = 0; idx < tmpDS.screeningCriteria.Count; idx++)
            {
                if (tmpDS.screeningCriteria[idx].code != "" && tmpDS.screeningCriteria[idx].selected)
                {
                    if (strategyList.Contains(tmpDS.screeningCriteria[idx].code)) continue;
                    strategyList.Add(tmpDS.screeningCriteria[idx].code);
                }
            }
            DataTable retsultTbl = CreateDataTable(strategyList);
            SetDataGrid(resultDataGrid, retsultTbl);

            //Analysis cached data so we MUST clear cache to ensure the system run correctly
            DataAccess.Libs.ClearCache();

            progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = stockCodeList.Count;
            this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());

            string[] strategy = common.system.Collection2List(strategyList);
            this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());
            int codeStartIdx=0, codeEndIdx=0;
            DataParams dataParam = new DataParams(timeScaleCb.myValue.Code, AppTypes.TimeRanges.None, (int)dataCounEd.Value);
            while (codeStartIdx < stockCodeList.Count)
            {
                codeEndIdx += Settings.sysNumberOfItemsInBatchProcess;
                if (codeEndIdx >= stockCodeList.Count) codeEndIdx = stockCodeList.Count - 1;

                string[] stocks = common.system.Collection2List(stockCodeList, codeStartIdx, codeEndIdx);
                double[][] weightList = DataAccess.Libs.Estimate_Matrix_LastBizWeight(dataParam, stocks, strategy);

                for (int idx1 = 0, rowId = codeStartIdx; idx1 < weightList.Length; idx1++, rowId++)
                {
                    bool fMatched = false;
                    DataRow row = retsultTbl.NewRow();
                    row[0] = stockCodeList[rowId];

                    for (int colId = 0; colId < weightList[idx1].Length; colId++)
                    {
                        if (double.IsNaN(weightList[idx1][colId])) continue;
                        weight = (decimal)weightList[idx1][colId];
                        DataView criteriaView = new DataView(tmpDS.screeningCriteria);
                        criteriaView.RowFilter = tmpDS.screeningCriteria.codeColumn + "='" + strategyList[colId] + "' AND " +
                                                 tmpDS.screeningCriteria.selectedColumn + "=1";
                        Data.tmpDataSet.screeningCriteriaRow criteriaRow;
                        // If there is more than one criteria for the same code,
                        // matching one criteria is viewed as MATCHED , as OR operaror. 
                        for (int idx = 0; idx < criteriaView.Count; idx++)
                        {
                            criteriaRow = (Data.tmpDataSet.screeningCriteriaRow)criteriaView[idx].Row;
                            if (weight < criteriaRow.min || weight > criteriaRow.max) continue;
                            row[colId + 1] = weight;
                            fMatched = true;
                            break;
                        }
                    }
                    if (fMatched) retsultTbl.Rows.Add(row);
                    Application.DoEvents();
                }
                codeStartIdx = codeEndIdx + 1;
                progressBar.Value = codeEndIdx + 1;
                this.ShowReccount(progressBar.Value.ToString() + "/" + progressBar.Maximum.ToString());
                Application.DoEvents();
            }
            common.system.RemoveEmptyItems(retsultTbl);
            SetDataGrid(resultDataGrid, retsultTbl);
            this.ShowReccount(resultDataGrid.Rows.Count);
        }
Пример #9
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;
 }
Пример #10
0
 public static bool LoadAnalysisData(commonClass.BaseAnalysisData dataObj)
 {
     try
     {
         AnalysisDataCache data;
         string cacheKey = MakeAnalysisDataCacheKey(dataObj);
         object obj = GetCache(cacheKey);
         if (obj != null)
         {
             data = (AnalysisDataCache)obj;
             dataObj.priceDataTbl = (databases.baseDS.priceDataDataTable)data.dataTbl.Copy();
             return true;
         }
         using (new PleaseWait())
         {
             lock (myClient)
             {
                 data = new AnalysisDataCache();
                 int firstData = 0;
                 DataParams dataParam = new DataParams(dataObj.DataTimeScale.Code, dataObj.DataTimeRange, dataObj.DataMaxCount);
                 data.dataTbl = myClient.GetAnalysis_Data(out firstData, dataObj.DataStockCode, dataParam);
                 data.firstData = firstData;
                 AddCache(cacheKey, data);
                 dataObj.priceDataTbl = (databases.baseDS.priceDataDataTable)data.dataTbl.Copy();
                 dataObj.FirstDataStartAt = firstData;
             }
         }
         return true;
     }
     catch (Exception er)
     {
         if (OnError != null) OnError(er);
     }
     return false;
 }
Пример #11
0
 public static double[][] Estimate_Matrix_LastBizWeight(DataParams dataParam,string[] stockCodeList, string[] strategyList)
 {
     try
     {
         lock (myClient)
         {
             return myClient.Estimate_Matrix_LastBizWeight(dataParam, stockCodeList, strategyList);
         }
     }
     catch (Exception er)
     {
         if (OnError != null) OnError(er);
     }
     return null;
 }
Пример #12
0
 public List<double[]> Estimate_Matrix_LastBizWeight(DataParams dataParam,string[] stockCodeList, string[] strategyList)
 {
     try
     {
         WriteLog(1, "InvestorCode", "Estimate_Matrix_LastBizWeight", stockCodeList.ToString(), strategyList.ToString());
         return application.Strategy.StrategyLibs.Estimate_Matrix_LastBizWeight(dataParam, common.system.List2Collection(stockCodeList),
                                                                        common.system.List2Collection(strategyList));
     }
     catch (Exception ex)
     {
         WriteSysLogLocal("WS006", ex);
     }
     return null;
 }
Пример #13
0
 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;
 }
Пример #14
0
 public AnalysisData(string code, DataParams dataParam) :
     base(code,AppTypes.TimeScaleFromCode(dataParam.TimeScale), dataParam.TimeRange, dataParam.MaxDataCount) { }