using CPSYSDIBLib; using OfficeOpenXml; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace AutoSellerNS { class SimulationHelper { CybosHelper m_CybosHelper = null; RichTextBox m_tbLogView = null; public SimulationHelper(CybosHelper CybosHelper, RichTextBox tbLog) { m_CybosHelper = CybosHelper; m_tbLogView = tbLog; } public void LoadTxt() { List aItems = new List(); StockChart CPStockChart = new StockChart(); foreach(string strLine in File.ReadLines(Util.GetSimulationPath()+"/0-input.txt", Encoding.UTF8)) { var tokens = strLine.Split('\t'); var strDate = tokens[0]; var strNewTime = tokens[1]; var strSimulationTime = tokens[2]; var strCodeName = tokens[3]; var strCode = tokens[4]; var strStartPrice = tokens[5]; DateTime StartDT; DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT); uint uiStartDate; uint.TryParse(StartDT.ToString("yyyyMMdd"), out uiStartDate); string strOutFileName = Util.GetSimulationPath() + "/" + strCodeName + "-" + StartDT.ToString("yyyy-MM-dd") + ".txt"; if(File.Exists(strOutFileName) == true) continue; CPStockChart.SetInputValue(0, "A"+strCode); CPStockChart.SetInputValue(1, '1'); CPStockChart.SetInputValue(2, uiStartDate); CPStockChart.SetInputValue(3, uiStartDate); CPStockChart.SetInputValue(4, 100000); CPStockChart.SetInputValue(5, new int[] { 0, 1, 5, 8, 9, 10, 11 }); CPStockChart.SetInputValue(6, 'T'); CPStockChart.BlockRequest2(0); int iFieldCnt = CPStockChart.GetHeaderValue(1); string[] astrFieldName = CPStockChart.GetHeaderValue(2); string strOutLine = ""; for(int j = 0; j 0) { File.AppendAllText(strOutFileName, strOutLine, new UTF8Encoding(true)); strOutLine = ""; } m_tbLogView.AppendText(string.Format("[Load] " + strOutFileName + " End")); } m_tbLogView.AppendText(string.Format("[Load] All End")); } public void LoadExcel() { List aItems = new List(); StockChart CPStockChart = new StockChart(); ExcelHandler Excel = null; foreach(string strLine in File.ReadLines(Util.GetSimulationPath()+"/0-input.txt", Encoding.UTF8)) { var tokens = strLine.Split('\t'); var strDate = tokens[0]; var strNewTime = tokens[1]; var strSimulationTime = tokens[2]; var strCodeName = tokens[3]; var strCode = tokens[4]; var strStartPrice = tokens[5]; DateTime StartDT; DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT); string strOutFileName = Util.GetSimulationPath() + "/" + strCodeName + "-" + StartDT.ToString("yyyy-MM-dd") + ".xlsx"; if(File.Exists(strOutFileName) == true) continue; CPStockChart.SetInputValue(0, "A"+strCode); CPStockChart.SetInputValue(1, '1'); CPStockChart.SetInputValue(2, StartDT.ToString("yyyyMMdd")); CPStockChart.SetInputValue(3, StartDT.ToString("yyyyMMdd")); CPStockChart.SetInputValue(5, new int[] { 0, 1, 5, 8, 9, 10, 11 }); CPStockChart.SetInputValue(6, 'T'); CPStockChart.BlockRequest2(0); int iFieldCnt = CPStockChart.GetHeaderValue(1); string[] astrFieldName = CPStockChart.GetHeaderValue(2); List aRow = new List(); List aRows = new List(); Excel = new ExcelHandler(strOutFileName, astrFieldName); bool bContinue = true; while(bContinue == true) { int iCnt = CPStockChart.GetHeaderValue(3); for(int i = 0; i= StartDT && iPrice==iStartPrice) bStart = true; } else { if(bBid == false) iAskCount++; else iAskCount = 0; if(iAskCount >= Config.GetBidCount()) { m_tbLogView.AppendText(string.Format("[{0}] 시뮬레이션 매도 {1} {2} {3} ({4} : {5:n2}%)\n", strCodeName, RowDT.ToString("yyyy-MM-dd HH:mm:00"), iRow, iPrice, iPrice-iStartPrice, (iPrice-iStartPrice)*100/(float)iStartPrice )); iTotalProfit += (iPrice-iStartPrice)*iStockCount; iTotalBid += iStartPrice*iStockCount; break; } if(iPrice > iMaxPrice) iTrailingCount = 0; else if(iPrice <= iMaxPrice*(100-Config.GetTrailingRate())/100) iTrailingCount++; iMaxPrice = Math.Max(iPrice, iMaxPrice); if(iTrailingCount >= Config.GetTrailingCnt()) { m_tbLogView.AppendText(string.Format("[{0}] 트레일링 매도 {1} {2} {3} ({4} : {5:n2}%)\n", strCodeName, RowDT.ToString("yyyy-MM-dd HH:mm:00"), iRow, iPrice, iPrice-iStartPrice, (iPrice-iStartPrice)*100/(float)iStartPrice )); iTotalProfit += (iPrice-iStartPrice)*iStockCount; iTotalBid += iStartPrice*iStockCount; break; } } iPrevAskCount = iTotalAskCount; iPrevBidCount = iTotalBidCount; } } m_tbLogView.AppendText(string.Format("[시뮬레이션 종료] 총수익 : {0:n0} : {1:n2}%\n\n", iTotalProfit, iTotalProfit*100/iTotalBid)); } } }