- 시간에 따른 감소폭 추가

- 정정주문 수정
- crash 수정
This commit is contained in:
2017-03-07 15:40:25 +09:00
parent f4872096c6
commit 592fc7a365
5 changed files with 601 additions and 450 deletions

View File

@@ -27,178 +27,178 @@ namespace AutoSellerNS
m_tbLogView = tbLog;
}
public void LoadTxt()
{
List<string> aItems = new List<string>();
StockChart CPStockChart = new StockChart();
//public void LoadTxt()
//{
// List<string> aItems = new List<string>();
// StockChart CPStockChart = new StockChart();
foreach(string strLine in File.ReadLines(Util.GetSimulationPath()+"/0-input.txt", Encoding.UTF8))
{
var tokens = strLine.Split('\t');
// 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];
// 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);
// 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;
// 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);
// 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);
// int iFieldCnt = CPStockChart.GetHeaderValue(1);
// string[] astrFieldName = CPStockChart.GetHeaderValue(2);
string strOutLine = "";
for(int j = 0; j<iFieldCnt; j++)
{
strOutLine += astrFieldName[j];
strOutLine += '\t';
}
File.AppendAllText(strOutFileName, strOutLine+Environment.NewLine, new UTF8Encoding(true));
strOutLine = "";
// string strOutLine = "";
// for(int j = 0; j<iFieldCnt; j++)
// {
// strOutLine += astrFieldName[j];
// strOutLine += '\t';
// }
// File.AppendAllText(strOutFileName, strOutLine+Environment.NewLine, new UTF8Encoding(true));
// strOutLine = "";
bool bContinue = true;
while(bContinue == true)
{
int iCnt = CPStockChart.GetHeaderValue(3);
for(int i = 0; i<iCnt; i++)
{
for(int j = 0; j<iFieldCnt; j++)
{
strOutLine += CPStockChart.GetDataValue(j, i);
strOutLine += '\t';
}
// bool bContinue = true;
// while(bContinue == true)
// {
// int iCnt = CPStockChart.GetHeaderValue(3);
// for(int i = 0; i<iCnt; i++)
// {
// for(int j = 0; j<iFieldCnt; j++)
// {
// strOutLine += CPStockChart.GetDataValue(j, i);
// strOutLine += '\t';
// }
strOutLine += Environment.NewLine;
// strOutLine += Environment.NewLine;
if(i % 1000 == 999)
{
File.AppendAllText(strOutFileName, strOutLine, new UTF8Encoding(true));
strOutLine = "";
}
}
// if(i % 1000 == 999)
// {
// File.AppendAllText(strOutFileName, strOutLine, new UTF8Encoding(true));
// strOutLine = "";
// }
// }
bContinue = (CPStockChart.Continue==1);
if(bContinue == true)
CPStockChart.BlockRequest2(0);
// bContinue = (CPStockChart.Continue==1);
// if(bContinue == true)
// CPStockChart.BlockRequest2(0);
m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
}
// m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
// }
if(strOutLine.Length > 0)
{
File.AppendAllText(strOutFileName, strOutLine, new UTF8Encoding(true));
strOutLine = "";
}
// if(strOutLine.Length > 0)
// {
// File.AppendAllText(strOutFileName, strOutLine, new UTF8Encoding(true));
// strOutLine = "";
// }
m_tbLogView.AppendText(string.Format("[Load] " + strOutFileName + " End"));
}
// m_tbLogView.AppendText(string.Format("[Load] " + strOutFileName + " End"));
// }
m_tbLogView.AppendText(string.Format("[Load] All End"));
}
// m_tbLogView.AppendText(string.Format("[Load] All End"));
//}
public void LoadExcel()
{
List<string> aItems = new List<string>();
StockChart CPStockChart = new StockChart();
ExcelHandler Excel = null;
//public void LoadExcel()
//{
// List<string> aItems = new List<string>();
// 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');
// 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];
strCodeName = strCodeName.Trim();
var strCode = tokens[4];
var strStartPrice = tokens[5];
// var strDate = tokens[0];
// var strNewTime = tokens[1];
// var strSimulationTime = tokens[2];
// var strCodeName = tokens[3];
// strCodeName = strCodeName.Trim();
// var strCode = tokens[4];
// var strStartPrice = tokens[5];
DateTime StartDT;
DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
// DateTime StartDT;
// DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
string strOutFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-StockChart-" + strCodeName + ".xlsx";
if(File.Exists(strOutFileName) == true)
{
if(StartDT.DayOfYear == DateTime.Now.DayOfYear)
File.Delete(strOutFileName);
else
continue;
}
// string strOutFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-StockChart-" + strCodeName + ".xlsx";
// if(File.Exists(strOutFileName) == true)
// {
// if(StartDT.DayOfYear == DateTime.Now.DayOfYear)
// File.Delete(strOutFileName);
// else
// 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);
// 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<object> aRow = new List<object>();
List<object[]> aaRows = new List<object[]>();
// int iFieldCnt = CPStockChart.GetHeaderValue(1);
// string[] astrFieldName = CPStockChart.GetHeaderValue(2);
// List<object> aRow = new List<object>();
// List<object[]> aaRows = new List<object[]>();
Excel = new ExcelHandler(strOutFileName, astrFieldName);
// Excel = new ExcelHandler(strOutFileName, astrFieldName);
bool bContinue = true;
while(bContinue == true)
{
int iCnt = CPStockChart.GetHeaderValue(3);
for(int i = 0; i<iCnt; i++)
{
for(int j = 0; j<iFieldCnt; j++)
aRow.Add(CPStockChart.GetDataValue(j, i));
// bool bContinue = true;
// while(bContinue == true)
// {
// int iCnt = CPStockChart.GetHeaderValue(3);
// for(int i = 0; i<iCnt; i++)
// {
// for(int j = 0; j<iFieldCnt; j++)
// aRow.Add(CPStockChart.GetDataValue(j, i));
if(aaRows.Count == 0)
{
aRow.Add(0);
aRow.Add(0);
}
else
{
aRow.Add((uint)aaRows.Last()[5]-(uint)aRow[5]);
aRow.Add((uint)aaRows.Last()[6]-(uint)aRow[6]);
}
// if(aaRows.Count == 0)
// {
// aRow.Add(0);
// aRow.Add(0);
// }
// else
// {
// aRow.Add((uint)aaRows.Last()[5]-(uint)aRow[5]);
// aRow.Add((uint)aaRows.Last()[6]-(uint)aRow[6]);
// }
aaRows.Add(aRow.ToArray());
aRow.Clear();
}
// aaRows.Add(aRow.ToArray());
// aRow.Clear();
// }
bContinue = (CPStockChart.Continue==1);
if(bContinue == true)
CPStockChart.BlockRequest2(0);
// bContinue = (CPStockChart.Continue==1);
// if(bContinue == true)
// CPStockChart.BlockRequest2(0);
m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
}
// m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
// }
aaRows.Reverse();
Excel.AddRows(aaRows.ToArray());
// aaRows.Reverse();
// Excel.AddRows(aaRows.ToArray());
m_tbLogView.AppendText(string.Format("[Load] " + strOutFileName + " End\n"));
}
// m_tbLogView.AppendText(string.Format("[Load] " + strOutFileName + " End\n"));
// }
m_tbLogView.AppendText(string.Format("[Load] All End\n\n"));
m_tbLogView.SelectionStart = m_tbLogView.TextLength;
m_tbLogView.ScrollToCaret();
}
// m_tbLogView.AppendText(string.Format("[Load] All End\n\n"));
// m_tbLogView.SelectionStart = m_tbLogView.TextLength;
// m_tbLogView.ScrollToCaret();
//}
public void LoadExcel2()
{
@@ -221,6 +221,8 @@ namespace AutoSellerNS
DateTime StartDT;
DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
string strOutFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-JpBid-" + strCodeName + ".xlsx";
if(File.Exists(strOutFileName) == true)
{
@@ -279,131 +281,136 @@ namespace AutoSellerNS
m_tbLogView.ScrollToCaret();
}
public void StartSimuation()
{
m_tbLogView.AppendText(string.Format("[시뮬레이션 시작] 조건 : {0}회, 트레일링 : {1}%, {2}회\n", Config.GetBidCount(), Config.GetTrailingRate(), Config.GetTrailingCnt()));
//public void StartSimuation()
//{
// m_tbLogView.AppendText(string.Format("[시뮬레이션 시작] 조건 : {0}회, 트레일링 : {1}%, {2}회\n", Config.GetBidCount(), Config.GetTrailingRate(), Config.GetTrailingCnt()));
int iTotalProfit = 0;
int iTotalBid = 0;
// int iTotalProfit = 0;
// int iTotalBid = 0;
foreach(string strLine in File.ReadLines(Util.GetSimulationPath()+"/0-input.txt", Encoding.UTF8))
{
var tokens = strLine.Split('\t');
// 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];
strCodeName = strCodeName.Trim();
var strCode = tokens[4];
var strStartPrice = tokens[5];
// var strDate = tokens[0];
// var strNewTime = tokens[1];
// var strSimulationTime = tokens[2];
// var strCodeName = tokens[3];
// strCodeName = strCodeName.Trim();
// var strCode = tokens[4];
// var strStartPrice = tokens[5];
DateTime StartDT;
DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
// DateTime StartDT;
// DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
int iStartPrice;
int.TryParse(strStartPrice, NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out iStartPrice);
// int iStartPrice;
// int.TryParse(strStartPrice, NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out iStartPrice);
string strFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-StockChart-" + strCodeName + ".xlsx";
// string strFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-StockChart-" + strCodeName + ".xlsx";
FileInfo newFile = new FileInfo(strFileName);
ExcelPackage package = new ExcelPackage(newFile);
ExcelWorksheet Sheet = package.Workbook.Worksheets["sheet"];
// FileInfo newFile = new FileInfo(strFileName);
// ExcelPackage package = new ExcelPackage(newFile);
// ExcelWorksheet Sheet = package.Workbook.Worksheets["sheet"];
int iMaxRow = Sheet.Dimension.Rows;
// int iMaxRow = Sheet.Dimension.Rows;
DateTime RowDT;
bool bStart = false;
int iTotalAskCount = 0;
int iTotalBidCount = 0;
int iPrevAskCount = 0;
int iPrevBidCount = 0;
bool bBid = false;
int iAskCount = 0;
int iTrailingCount = 0;
int iMaxPrice = int.MinValue;
int iStockCount = 0;
int iStartRow = 0;
int iPrevPrice = 0;
for(int iRow = 2; iRow<=iMaxRow; iRow++)
{
int iTime = (int)(double)Sheet.Cells[iRow, 2].Value;
int iPrice = (int)(double)Sheet.Cells[iRow, 3].Value;
iTotalAskCount = (int)(double)Sheet.Cells[iRow, 6].Value;
iTotalBidCount = (int)(double)Sheet.Cells[iRow, 7].Value;
// DateTime RowDT;
// bool bStart = false;
// int iTotalAskCount = 0;
// int iTotalBidCount = 0;
// int iPrevAskCount = 0;
// int iPrevBidCount = 0;
// bool bBid = false;
// int iAskCount = 0;
// int iTrailingCount = 0;
// int iMaxPrice = int.MinValue;
// int iStockCount = 0;
// int iStartRow = 0;
// int iPrevPrice = 0;
// for(int iRow = 2; iRow<=iMaxRow; iRow++)
// {
// int iTime = (int)(double)Sheet.Cells[iRow, 2].Value;
// int iPrice = (int)(double)Sheet.Cells[iRow, 3].Value;
// iTotalAskCount = (int)(double)Sheet.Cells[iRow, 6].Value;
// iTotalBidCount = (int)(double)Sheet.Cells[iRow, 7].Value;
bBid = (iTotalAskCount == iPrevAskCount);
DateTime.TryParse(strDate+" "+string.Format("{0}:{1}:{2}", iTime/100, iTime%100, 59), out RowDT);
// bBid = (iTotalAskCount == iPrevAskCount);
// DateTime.TryParse(strDate+" "+string.Format("{0}:{1}:{2}", iTime/100, iTime%100, 59), out RowDT);
iStockCount = 1000000/iStartPrice;
// iStockCount = 1000000/iStartPrice;
if(bStart == false)
{
if(RowDT >= StartDT && iPrice==iStartPrice)
{
bStart = true;
iStartRow = iRow;
}
}
else
{
if(bBid == false)
iAskCount++;
else
iAskCount = 0;
// if(bStart == false)
// {
// if(RowDT >= StartDT && iPrice==iStartPrice)
// {
// bStart = true;
// iStartRow = iRow;
// }
// else if((RowDT-StartDT).Minutes > 10)
// {
// InsertLog(string.Format("[{0,-10}] 매수 가격 찾기 실패", strCodeName));
// break;
// }
// }
// else
// {
// if(bBid == false)
// iAskCount++;
// else
// iAskCount = 0;
if(iAskCount >= Config.GetBidCount())
{
m_tbLogView.AppendText(string.Format("[{0,-10}] 조건 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, line:{7})\n",
strCodeName,
RowDT.ToString("yyyy-MM-dd HH:mm:00"),
iRow,
iPrice,
iPrice-iStartPrice,
(iPrice-iStartPrice)*100/(float)iStartPrice,
iStartPrice,
iStartRow
));
iTotalProfit += (iPrice-iStartPrice)*iStockCount;
iTotalBid += iStartPrice*iStockCount;
break;
}
// if(iAskCount >= Config.GetBidCount())
// {
// m_tbLogView.AppendText(string.Format("[{0,-10}] 조건 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, line:{7})\n",
// strCodeName,
// RowDT.ToString("yyyy-MM-dd HH:mm:00"),
// iRow,
// iPrice,
// iPrice-iStartPrice,
// (iPrice-iStartPrice)*100/(float)iStartPrice,
// iStartPrice,
// iStartRow
// ));
// 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(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} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, line:{7})\n",
strCodeName,
RowDT.ToString("yyyy-MM-dd HH:mm:00"),
iRow,
iPrice,
iPrice-iStartPrice,
(iPrice-iStartPrice)*100/(float)iStartPrice,
iStartPrice,
iStartRow
));
iTotalProfit += (iPrice-iStartPrice)*iStockCount;
iTotalBid += iStartPrice*iStockCount;
break;
}
}
// if(iTrailingCount >= Config.GetTrailingCnt())
// {
// m_tbLogView.AppendText(string.Format("[{0}] 트레일링 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, line:{7})\n",
// strCodeName,
// RowDT.ToString("yyyy-MM-dd HH:mm:00"),
// iRow,
// iPrice,
// iPrice-iStartPrice,
// (iPrice-iStartPrice)*100/(float)iStartPrice,
// iStartPrice,
// iStartRow
// ));
// iTotalProfit += (iPrice-iStartPrice)*iStockCount;
// iTotalBid += iStartPrice*iStockCount;
// break;
// }
// }
iPrevPrice = iPrice;
iPrevAskCount = iTotalAskCount;
iPrevBidCount = iTotalBidCount;
}
}
// iPrevPrice = iPrice;
// iPrevAskCount = iTotalAskCount;
// iPrevBidCount = iTotalBidCount;
// }
// }
m_tbLogView.AppendText(string.Format("[시뮬레이션 종료] 총수익 : {0:n0}원 : {1:n2}%\n\n", iTotalProfit, iTotalProfit*100/(float)iTotalBid));
m_tbLogView.SelectionStart = m_tbLogView.TextLength;
m_tbLogView.ScrollToCaret();
}
// m_tbLogView.AppendText(string.Format("[시뮬레이션 종료] 총수익 : {0:n0}원 : {1:n2}%\n\n", iTotalProfit, iTotalProfit*100/(float)iTotalBid));
// m_tbLogView.SelectionStart = m_tbLogView.TextLength;
// m_tbLogView.ScrollToCaret();
//}
void InsertLog(string strMsg)
{
@@ -437,10 +444,11 @@ namespace AutoSellerNS
double dSlowSD = (double)aParams[4];
double dSlowUpCnt = (double)aParams[5];
double dSlowDownCnt = (double)aParams[6];
bool bAverageCompare = (bool)aParams[7];
int iCompareType = (int)aParams[7];
string strMethod = (string)aParams[8];
string strLine = (string)aParams[9];
double dTimeSub = (double)aParams[10];
int iTimeDiffLimit = (int)aParams[11];
var tokens = strLine.Split('\t');
@@ -484,28 +492,36 @@ namespace AutoSellerNS
double dCheckCount = 5.0;
List<int> m_PriceList = new List<int>();
//Sheet.Column(7).Style.Font.Color.SetColor(Color.Black);
//Sheet.DeleteColumn(8, 11);
Sheet.Column(7).Style.Font.Color.SetColor(Color.Black);
Sheet.DeleteColumn(8, 11);
//Sheet.Cells[1, 8].Value = "평균";
//Sheet.Cells[1, 9].Value = "표준편차";
//Sheet.Cells[1, 10].Value = "매도 제한";
//Sheet.Cells[1, 11].Value = "매도 수";
//Sheet.View.FreezePanes(2, 1);
Sheet.Cells[1, 8].Value = "평균";
Sheet.Cells[1, 9].Value = "표준편차";
Sheet.Cells[1, 10].Value = "매도 제한";
Sheet.Cells[1, 11].Value = "매도 수";
Sheet.View.FreezePanes(2, 1);
double dPrevStdDev = 0;
string strReturnMsg = "";
int iPrevTime = 0;
for(int iRow = 2; iRow<=iMaxRow; iRow++)
{
if((string)Sheet.Cells[iRow, 2].Value == "*")
continue;
int iTime = (int)(double)Sheet.Cells[iRow, 1].Value;
int iPrice = (int)(double)Sheet.Cells[iRow, 3].Value;
int iAskPrice = (int)(double)Sheet.Cells[iRow, 4].Value;
int iBidPrice = (int)(double)Sheet.Cells[iRow, 5].Value;
int iTimeDiff = 0;
if(iPrevTime > 0)
iTimeDiff = ((iTime/10000)*60*60 + ((iTime%10000)/100)*60 + (iTime%100)) - ((iPrevTime/10000)*60*60 + ((iPrevTime%10000)/100)*60 + (iPrevTime%100));
if((string)Sheet.Cells[iRow, 2].Value == "*")
{
iPrevTime = iTime;
continue;
}
DateTime.TryParse(strDate+" "+string.Format("{0}:{1}:{2}", iTime/10000, (iTime/100)%100, iTime%100), out RowDT);
iStockCount = 1000000/iStartPrice;
@@ -520,6 +536,13 @@ namespace AutoSellerNS
m_PriceList.Clear();
m_PriceList.Add(iPrice);
}
else if((RowDT-StartDT).Minutes > 10)
{
InsertLog(string.Format("[{0}] [{1}] 매수 가격 찾기 실패\n",
StartDT.ToString("yyyy-MM-dd"),
strCodeName));
break;
}
}
else
{
@@ -530,53 +553,68 @@ namespace AutoSellerNS
double dAverage = (float)m_PriceList.Average();
double sumOfSquaresOfDifferences = m_PriceList.Select(val => Math.Pow((val-dAverage)/m_CybosHelper.GetUnitValue(val), 2)).Sum();
double dStdDev = Math.Sqrt(sumOfSquaresOfDifferences / m_PriceList.Count);
//if(dStdDev < dPrevStdDev)
//{
// dCheckCount -= dSlowDownCnt;
//}
//else
if(dStdDev >= dFastSD)
{
if(bAverageCompare == true)
switch(iCompareType)
{
if(iPrice >= dAverage)
dCheckCount += dFastUpCnt;
else// if(dCheckCount > 3)
dCheckCount -= dFastDownCnt;
}
else
{
if(iPrice >= m_PriceList[m_PriceList.Count-2])
dCheckCount += dFastUpCnt;
else// if(dCheckCount > 3)
dCheckCount -= dFastDownCnt;
}
case 1:
if(iPrice >= dAverage)
dCheckCount += dFastUpCnt;
else
dCheckCount -= dFastDownCnt;
break;
case 2:
if(iPrice >= m_PriceList[m_PriceList.Count-2])
dCheckCount += dFastUpCnt;
else
dCheckCount -= dFastDownCnt;
break;
case 3:
if(iPrice <= iBidPrice)
dCheckCount -= dFastDownCnt;
else
dCheckCount += dFastUpCnt;
break;
}
}
else if(dStdDev <= dSlowSD)
{
if(bAverageCompare == true)
switch(iCompareType)
{
if(iPrice >= dAverage)
dCheckCount += dSlowUpCnt;
else// if(dCheckCount > 3)
dCheckCount -= dSlowDownCnt;
}
else
{
if(iPrice >= m_PriceList[m_PriceList.Count-2])
dCheckCount += dSlowUpCnt;
else// if(dCheckCount > 3)
dCheckCount -= dSlowUpCnt;
case 1:
if(iPrice >= dAverage)
dCheckCount += dSlowUpCnt;
else
dCheckCount -= dSlowDownCnt;
break;
case 2:
if(iPrice >= m_PriceList[m_PriceList.Count-2])
dCheckCount += dSlowUpCnt;
else
dCheckCount -= dSlowDownCnt;
break;
case 3:
if(iPrice <= iBidPrice)
dCheckCount -= dSlowDownCnt;
else
dCheckCount += dSlowUpCnt;
break;
}
}
dCheckCount -= iTimeDiff*dTimeSub;
//dCheckCount = Math.Min(Math.Max(dCheckCount, 0), 15);
//Sheet.Cells[iRow, 8].Value = dAverage;
//Sheet.Cells[iRow, 9].Value = dStdDev;
//Sheet.Cells[iRow, 9].Style.Numberformat.Format = "0.00";
//Sheet.Cells[iRow, 10].Value = dCheckCount;
Sheet.Cells[iRow, 8].Value = dAverage;
Sheet.Cells[iRow, 9].Value = dStdDev;
Sheet.Cells[iRow, 9].Style.Numberformat.Format = "0.00";
Sheet.Cells[iRow, 10].Value = dCheckCount;
// 호가 비교 - 매수호가 기준
if(iPrice <= iBidPrice)
@@ -590,7 +628,7 @@ namespace AutoSellerNS
Sheet.Cells[iRow, 7].Style.Font.Color.SetColor(Color.Red);
}
//Sheet.Cells[iRow, 11].Value = iAskCount;
Sheet.Cells[iRow, 11].Value = iAskCount;
if(iAskCount >= Math.Round(dCheckCount))
{
@@ -650,33 +688,32 @@ namespace AutoSellerNS
break;
}
//if(iPrice < iStartPrice)
//{
// iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice);
// strReturnMsg = string.Format("[{0}] 손절 매도 (매수: {1:n0}원, {2}, line:{3}) (매도: {4:n0}원(매도가:{5:n0}원) {6} line:{7}) (손익: {8}, {9:n0} : {10:n2}%) {11} \n",
// strCodeName,
if(iTimeDiff >= iTimeDiffLimit)
{
iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice);
strReturnMsg = string.Format("[{0}] [{1}] 제한시간 매도 (매수: {2:n0}원, {3}, line:{4}) (매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8}) (손익: {9}, {10:n0} : {11:n2}%) {12} \n",
StartDT.ToString("yyyy-MM-dd"),
strCodeName,
// iStartPrice,
// StartDT.ToString("HH:mm:ss"),
// iStartRow,
iStartPrice,
StartDT.ToString("HH:mm:ss"),
iStartRow,
// iPrice,
// iSellPrice,
// RowDT.ToString("HH:mm:ss"),
// iRow,
iPrice,
iSellPrice,
RowDT.ToString("HH:mm:ss"),
iRow,
// iSellPrice-iStartPrice,
// (iSellPrice-iStartPrice)*iStockCount,
// (iSellPrice-iStartPrice)*100/(float)iStartPrice,
iSellPrice-iStartPrice,
(iSellPrice-iStartPrice)*iStockCount,
(iSellPrice-iStartPrice)*100/(float)iStartPrice,
// dCheckCount
dCheckCount
// );
);
// iTotalProfit += (iSellPrice-iStartPrice)*iStockCount;
// iTotalBid += iStartPrice*iStockCount;
// break;
//}
break;
}
dPrevStdDev = dStdDev;
}
@@ -709,12 +746,13 @@ namespace AutoSellerNS
}
iPrevPrice = iPrice;
iPrevTime = iTime;
}
//Sheet.Cells.AutoFitColumns(0);
//Sheet.Select(ExcelAddress.GetAddress(Math.Max(iStartRow, 1), 1), true);
Sheet.Cells.AutoFitColumns(0);
Sheet.Select(ExcelAddress.GetAddress(Math.Max(iStartRow, 1), 1), true);
//package.Save();
package.Save();
return new object[] { strReturnMsg, (iSellPrice-iStartPrice)*iStockCount };
}
@@ -730,12 +768,16 @@ namespace AutoSellerNS
double dSlowSD = (double)aParams[4];
double dSlowUpCnt = (double)aParams[5];
double dSlowDownCnt = (double)aParams[6];
bool bAverageCompare = (bool)aParams[7];
int iCompareType = (int)aParams[7];
string strMethod = (string)aParams[8];
double dTimeSub = (double)aParams[9];
int iTimeDiffLimit = (int)aParams[10];
InsertLog(string.Format("[시뮬레이션 시작] 조건 : {0}회, 트레일링 : {1}%, {2}회\n \t\t리스트 크기:{3}, Fast : {4}, {5}, {6}, Slow : {7}, {8}, {9}, 비교 방식 : {10}\n",
InsertLog(string.Format("[시뮬레이션 시작] 조건 : {0}회, 트레일링 : {1}%, {2}회\n \t\t리스트 크기:{3}, Fast : {4}, {5}, {6}, Slow : {7}, {8}, {9}, 초당 {10} 감소, 제한 시간: {11} 비교 방식 : {12}\n",
Config.GetBidCount(), Config.GetTrailingRate(), Config.GetTrailingCnt(),
iListCnt, dFastSD, dFastUpCnt, dFastDownCnt, dSlowSD, dSlowUpCnt, dSlowDownCnt, strMethod
iListCnt, dFastSD, dFastUpCnt, dFastDownCnt, dSlowSD, dSlowUpCnt, dSlowDownCnt,
dTimeSub, iTimeDiffLimit,
strMethod
));
@@ -748,8 +790,8 @@ namespace AutoSellerNS
iListCnt,
dFastSD, dFastUpCnt, dFastDownCnt,
dSlowSD, dSlowUpCnt, dSlowDownCnt,
bAverageCompare, strMethod,
strLine }));
iCompareType, strMethod,
strLine, dTimeSub, iTimeDiffLimit }));
aTasks.Add(task);
}
@@ -776,6 +818,8 @@ namespace AutoSellerNS
double dSlowSD;
double dSlowUpCnt;
double dSlowDownCnt;
double dTimeSub;
int iTimeDiffLimit;
int.TryParse(m_AutoSeller.tbSMListSize.Text, out iListCnt);
double.TryParse(m_AutoSeller.tbSMFastSD.Text, out dFastSD);
@@ -784,17 +828,22 @@ namespace AutoSellerNS
double.TryParse(m_AutoSeller.tbSMSlowSD.Text, out dSlowSD);
double.TryParse(m_AutoSeller.tbSMSlowUpCnt.Text, out dSlowUpCnt);
double.TryParse(m_AutoSeller.tbSMSlowDownCnt.Text, out dSlowDownCnt);
double.TryParse(m_AutoSeller.tbSMTimeSub.Text, out dTimeSub);
int.TryParse(m_AutoSeller.tbSMTimeDiffLimit.Text, out iTimeDiffLimit);
string strMethod = "";
m_AutoSeller.cbSMMethod.Invoke(new Action(() => {
strMethod = (string)m_AutoSeller.cbSMMethod.SelectedItem;
}));
bool bAverageCompare;
int iCompareType;
if(strMethod == "평균 비교")
bAverageCompare = true;
iCompareType = 1;
else if(strMethod == "마지막 비교")
iCompareType = 2;
else
bAverageCompare = false;
iCompareType = 3;
Task.Factory.StartNew(() => {
// for(double dFastSD = 0.75; dFastSD<=0.75; dFastSD+=0.05)
@@ -807,9 +856,9 @@ namespace AutoSellerNS
// {
Simulation(new object[] {
iListCnt,
dFastSD, dFastUpCnt, dFastUpCnt,
dSlowSD, dSlowUpCnt, dSlowUpCnt,
bAverageCompare, strMethod
dFastSD, dFastUpCnt, dFastDownCnt,
dSlowSD, dSlowUpCnt, dSlowDownCnt,
iCompareType, strMethod, dTimeSub, iTimeDiffLimit
});
// }
// }