- 시뮬레이션 수정중 : 표준편차 이용

This commit is contained in:
2017-02-20 04:15:45 +09:00
parent 0aec121fd5
commit dd7a1322e4
4 changed files with 191 additions and 60 deletions

105
AutoSeller.Designer.cs generated
View File

@@ -35,6 +35,7 @@
this.btSell = new MaterialSkin.Controls.MaterialRaisedButton();
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.splitContainer3 = new System.Windows.Forms.SplitContainer();
this.tbLog = new System.Windows.Forms.RichTextBox();
this.btUpdate = new MaterialSkin.Controls.MaterialRaisedButton();
this.btCybos = new MaterialSkin.Controls.MaterialRaisedButton();
@@ -53,10 +54,14 @@
this.tbSubAccount = new MaterialSkin.Controls.MaterialSingleLineTextField();
this.cbAccount = new System.Windows.Forms.ComboBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.tbSMListSize = new System.Windows.Forms.TextBox();
this.tbSMSlowCnt = new System.Windows.Forms.TextBox();
this.tbSMSlowSD = new System.Windows.Forms.TextBox();
this.tbSMFastCnt = new System.Windows.Forms.TextBox();
this.tbSMFastSD = new System.Windows.Forms.TextBox();
this.tbSimulationLog = new System.Windows.Forms.RichTextBox();
this.btSimulate = new MaterialSkin.Controls.MaterialFlatButton();
this.btLoad = new MaterialSkin.Controls.MaterialFlatButton();
this.splitContainer3 = new System.Windows.Forms.SplitContainer();
this.lvItems = new AutoSellerNS.ListViewNF();
this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@@ -90,12 +95,12 @@
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit();
this.splitContainer3.Panel1.SuspendLayout();
this.splitContainer3.Panel2.SuspendLayout();
this.splitContainer3.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage3.SuspendLayout();
this.SuspendLayout();
//
// materialTabSelector1
@@ -194,6 +199,24 @@
this.splitContainer1.SplitterDistance = 455;
this.splitContainer1.TabIndex = 1;
//
// splitContainer3
//
this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer3.Location = new System.Drawing.Point(0, 0);
this.splitContainer3.Name = "splitContainer3";
this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer3.Panel1
//
this.splitContainer3.Panel1.Controls.Add(this.lvItems);
//
// splitContainer3.Panel2
//
this.splitContainer3.Panel2.Controls.Add(this.lvNCItem);
this.splitContainer3.Size = new System.Drawing.Size(804, 455);
this.splitContainer3.SplitterDistance = 300;
this.splitContainer3.TabIndex = 1;
//
// tbLog
//
this.tbLog.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -438,6 +461,11 @@
//
// tabPage3
//
this.tabPage3.Controls.Add(this.tbSMListSize);
this.tabPage3.Controls.Add(this.tbSMSlowCnt);
this.tabPage3.Controls.Add(this.tbSMSlowSD);
this.tabPage3.Controls.Add(this.tbSMFastCnt);
this.tabPage3.Controls.Add(this.tbSMFastSD);
this.tabPage3.Controls.Add(this.tbSimulationLog);
this.tabPage3.Controls.Add(this.btSimulate);
this.tabPage3.Controls.Add(this.btLoad);
@@ -449,6 +477,46 @@
this.tabPage3.Text = "Simulation";
this.tabPage3.UseVisualStyleBackColor = true;
//
// tbSMListSize
//
this.tbSMListSize.Location = new System.Drawing.Point(333, 20);
this.tbSMListSize.Name = "tbSMListSize";
this.tbSMListSize.Size = new System.Drawing.Size(36, 21);
this.tbSMListSize.TabIndex = 3;
this.tbSMListSize.Text = "20";
//
// tbSMSlowCnt
//
this.tbSMSlowCnt.Location = new System.Drawing.Point(375, 74);
this.tbSMSlowCnt.Name = "tbSMSlowCnt";
this.tbSMSlowCnt.Size = new System.Drawing.Size(36, 21);
this.tbSMSlowCnt.TabIndex = 7;
this.tbSMSlowCnt.Text = "1";
//
// tbSMSlowSD
//
this.tbSMSlowSD.Location = new System.Drawing.Point(333, 74);
this.tbSMSlowSD.Name = "tbSMSlowSD";
this.tbSMSlowSD.Size = new System.Drawing.Size(36, 21);
this.tbSMSlowSD.TabIndex = 6;
this.tbSMSlowSD.Text = "0.2";
//
// tbSMFastCnt
//
this.tbSMFastCnt.Location = new System.Drawing.Point(375, 47);
this.tbSMFastCnt.Name = "tbSMFastCnt";
this.tbSMFastCnt.Size = new System.Drawing.Size(36, 21);
this.tbSMFastCnt.TabIndex = 5;
this.tbSMFastCnt.Text = "3";
//
// tbSMFastSD
//
this.tbSMFastSD.Location = new System.Drawing.Point(333, 47);
this.tbSMFastSD.Name = "tbSMFastSD";
this.tbSMFastSD.Size = new System.Drawing.Size(36, 21);
this.tbSMFastSD.TabIndex = 4;
this.tbSMFastSD.Text = "0.75";
//
// tbSimulationLog
//
this.tbSimulationLog.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@@ -492,24 +560,6 @@
this.btLoad.UseVisualStyleBackColor = true;
this.btLoad.Click += new System.EventHandler(this.btLoad_Click);
//
// splitContainer3
//
this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer3.Location = new System.Drawing.Point(0, 0);
this.splitContainer3.Name = "splitContainer3";
this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer3.Panel1
//
this.splitContainer3.Panel1.Controls.Add(this.lvItems);
//
// splitContainer3.Panel2
//
this.splitContainer3.Panel2.Controls.Add(this.lvNCItem);
this.splitContainer3.Size = new System.Drawing.Size(804, 455);
this.splitContainer3.SplitterDistance = 300;
this.splitContainer3.TabIndex = 1;
//
// lvItems
//
this.lvItems.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@@ -700,14 +750,14 @@
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.tabPage3.ResumeLayout(false);
this.tabPage3.PerformLayout();
this.splitContainer3.Panel1.ResumeLayout(false);
this.splitContainer3.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit();
this.splitContainer3.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.tabPage3.ResumeLayout(false);
this.tabPage3.PerformLayout();
this.ResumeLayout(false);
}
@@ -764,5 +814,10 @@
private System.Windows.Forms.ColumnHeader chNCType;
private System.Windows.Forms.ColumnHeader chNCCount;
private System.Windows.Forms.ColumnHeader chNCPrice;
public System.Windows.Forms.TextBox tbSMSlowSD;
public System.Windows.Forms.TextBox tbSMFastCnt;
public System.Windows.Forms.TextBox tbSMFastSD;
public System.Windows.Forms.TextBox tbSMSlowCnt;
public System.Windows.Forms.TextBox tbSMListSize;
}
}

View File

@@ -197,6 +197,11 @@ namespace AutoSellerNS
AddItem(Item);
// 미체결
UpdateNC();
}
void UpdateNC()
{
var NCItems = m_CybosHelper.UpdateNC();
lvNCItem.Items.Clear();
if(lvNCItem.InvokeRequired)
@@ -208,8 +213,8 @@ namespace AutoSellerNS
NCItem.m_strCode,
NCItem.m_strCodeName,
NCItem.m_strDesc,
string.Format("{0:0n}", NCItem.m_iOrderPrice),
string.Format("{0:0n}", NCItem.m_iRemainCnt),
string.Format("{0:n0}", NCItem.m_iOrderPrice),
string.Format("{0:n0}", NCItem.m_iRemainCnt),
}));
}
}));
@@ -222,8 +227,8 @@ namespace AutoSellerNS
NCItem.m_strCode,
NCItem.m_strCodeName,
NCItem.m_strDesc,
string.Format("{0:0n}", NCItem.m_iOrderPrice),
string.Format("{0:0n}", NCItem.m_iRemainCnt),
string.Format("{0:n0}", NCItem.m_iOrderPrice),
string.Format("{0:n0}", NCItem.m_iRemainCnt),
}));
}
}
@@ -252,6 +257,11 @@ namespace AutoSellerNS
//}
}
public void OnReceipt()
{
UpdateNC();
}
private void btSell_Click(object sender, EventArgs e)
{
btSell.Primary = !btSell.Primary;
@@ -408,13 +418,13 @@ namespace AutoSellerNS
#region Simulation
private void btLoad_Click(object sender, EventArgs e)
{
SimulationHelper helper = new SimulationHelper(m_CybosHelper, tbSimulationLog);
SimulationHelper helper = new SimulationHelper(this, m_CybosHelper, tbSimulationLog);
helper.LoadExcel2();
}
private void btSimulate_Click(object sender, EventArgs e)
{
SimulationHelper helper = new SimulationHelper(m_CybosHelper, tbSimulationLog);
SimulationHelper helper = new SimulationHelper(this, m_CybosHelper, tbSimulationLog);
helper.StartSimuation2();
return;

View File

@@ -277,6 +277,7 @@ namespace AutoSellerNS
break;
case 4: // 접수
m_Listener.OnReceipt();
Util.Log(bBid ? Util.LOG_TYPE.BUY : Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 접수 ({3:n0}원 {4}주)", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt));
break;
}
@@ -345,7 +346,7 @@ namespace AutoSellerNS
}
}
int GetUnitValue(int iValue)
public int GetUnitValue(int iValue)
{
int iUnit = 1;
if(iValue < 1000)

View File

@@ -15,11 +15,13 @@ namespace AutoSellerNS
{
class SimulationHelper
{
AutoSeller m_AutoSeller = null;
CybosHelper m_CybosHelper = null;
RichTextBox m_tbLogView = null;
public SimulationHelper(CybosHelper CybosHelper, RichTextBox tbLog)
public SimulationHelper(AutoSeller autoSeller, CybosHelper CybosHelper, RichTextBox tbLog)
{
m_AutoSeller = autoSeller;
m_CybosHelper = CybosHelper;
m_tbLogView = tbLog;
}
@@ -130,7 +132,7 @@ namespace AutoSellerNS
DateTime StartDT;
DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
string strOutFileName = Util.GetSimulationPath() + "/" + strCodeName + "-" + StartDT.ToString("yyyy-MM-dd") + ".xlsx";
string strOutFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-" + strCodeName + "StockChart" + ".xlsx";
if(File.Exists(strOutFileName) == true)
{
if(StartDT.DayOfYear == DateTime.Now.DayOfYear)
@@ -216,7 +218,7 @@ namespace AutoSellerNS
DateTime StartDT;
DateTime.TryParse(strDate+" "+strSimulationTime, out StartDT);
string strOutFileName = Util.GetSimulationPath() + "/" + strCodeName + "-" + StartDT.ToString("yyyy-MM-dd") + ".xlsx";
string strOutFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-" + strCodeName + "StockChart" + ".xlsx";
if(File.Exists(strOutFileName) == true)
{
if(StartDT.DayOfYear == DateTime.Now.DayOfYear)
@@ -298,7 +300,7 @@ namespace AutoSellerNS
int iStartPrice;
int.TryParse(strStartPrice, NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out iStartPrice);
string strFileName = Util.GetSimulationPath() + "/" + strCodeName + "-" + StartDT.ToString("yyyy-MM-dd") + ".xlsx";
string strFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-JpBid-" + strCodeName + ".xlsx";
FileInfo newFile = new FileInfo(strFileName);
@@ -414,6 +416,7 @@ namespace AutoSellerNS
var strNewTime = tokens[1];
var strSimulationTime = tokens[2];
var strCodeName = tokens[3];
strCodeName = strCodeName.Trim();
var strCode = tokens[4];
var strStartPrice = tokens[5];
@@ -423,7 +426,7 @@ namespace AutoSellerNS
int iStartPrice;
int.TryParse(strStartPrice, NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out iStartPrice);
string strFileName = Util.GetSimulationPath() + "/" + strCodeName + "-" + StartDT.ToString("yyyy-MM-dd") + ".xlsx";
string strFileName = Util.GetSimulationPath() + "/" + StartDT.ToString("yyyy-MM-dd") + "-JpBid-" + strCodeName + ".xlsx";
FileInfo newFile = new FileInfo(strFileName);
@@ -448,10 +451,27 @@ namespace AutoSellerNS
bool bPrevAsk = false;
int iMaxAskPrice = 0;
int iCheckCount = 50;
List<int> m_PriceList = new List<int>();
int iListCnt;
double dFastSD;
int iFastCnt;
double dSlowSD;
int iSlowCnt;
int.TryParse(m_AutoSeller.tbSMListSize.Text, out iListCnt);
double.TryParse(m_AutoSeller.tbSMFastSD.Text, out dFastSD);
int.TryParse(m_AutoSeller.tbSMFastCnt.Text, out iFastCnt);
double.TryParse(m_AutoSeller.tbSMSlowSD.Text, out dSlowSD);
int.TryParse(m_AutoSeller.tbSMSlowCnt.Text, out iSlowCnt);
int iPrevAskPrice = 0;
for(int iRow = 2; iRow<=iMaxRow; iRow++)
{
if(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;
@@ -469,10 +489,39 @@ namespace AutoSellerNS
iStartRow = iRow;
iMaxAskPrice = iAskPrice;
iPrevAskPrice = iAskPrice;
m_PriceList.Clear();
m_PriceList.Add(iPrice);
}
}
else
{
m_PriceList.Add(iPrice);
if(m_PriceList.Count > iListCnt)
m_PriceList.RemoveAt(0);
double dAverage = (float)m_PriceList.Average();
double sumOfSquaresOfDifferences = m_PriceList.Select(val => Math.Pow((val-dAverage)/m_CybosHelper.GetUnitValue(val), 2)).Sum();
double sd = Math.Sqrt(sumOfSquaresOfDifferences / m_PriceList.Count);
if(sd >= dFastSD)
{
if(iPrice >= m_PriceList[m_PriceList.Count-2])
iCheckCount += iFastCnt;
else if(iCheckCount > 30)
iCheckCount -= iFastCnt;
}
else if(sd <= dSlowSD)
{
if(iPrice >= m_PriceList[m_PriceList.Count-2])
iCheckCount += iSlowCnt;
else if(iCheckCount > 30)
iCheckCount -= iSlowCnt;
}
int k = 0;
//// 체결가 비교
//if(iPrice > iPrevPrice)
//{
@@ -545,20 +594,28 @@ namespace AutoSellerNS
//else
// iDealCountInSec = 1;
if(iAskCount >= Config.GetBidCount())
if(iAskCount >= Math.Round(iCheckCount/10.0f))
{
m_tbLogView.AppendText(string.Format("[{0,-10}] 조건1 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, {7}, line:{8})\n",
int iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice);
m_tbLogView.AppendText(string.Format("[{0}] 조건1 매도 (매수 : {1:n0}원, {2}, line:{3}) (매도 : {4:n0}원(매도가:{5:n0}원) {6} line:{7}) ({8}, {9:n0} : {10:n2}%) {11} \n",
strCodeName,
RowDT.ToString("yyyy-MM-dd HH:mm:ss"),
iRow,
iPrice,
iPrice-iStartPrice,
(iPrice-iStartPrice)*100/(float)iStartPrice,
iStartPrice,
StartDT.ToString("yyyy-MM-dd HH:mm:ss"),
iStartRow
StartDT.ToString("HH:mm:ss"),
iStartRow,
iPrice,
iSellPrice,
RowDT.ToString("HH:mm:ss"),
iRow,
iSellPrice-iStartPrice,
(iSellPrice-iStartPrice)*iStockCount,
(iSellPrice-iStartPrice)*100/(float)iStartPrice,
iCheckCount
));
iTotalProfit += (iPrice-iStartPrice)*iStockCount;
iTotalProfit += (iSellPrice-iStartPrice)*iStockCount;
iTotalBid += iStartPrice*iStockCount;
break;
}
@@ -566,15 +623,15 @@ namespace AutoSellerNS
//if(aPrevDT.Count > 3 && aPrevDT.Last() - aPrevDT[aPrevDT.Count-3] > TimeSpan.FromSeconds(1) && iAskDownCount >= Config.GetBidCount())
//if(iAskDownCount >= 5)
//{
// m_tbLogView.AppendText(string.Format("[{0,-10}] 조건2 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, {7}, line:{8})\n",
// m_tbLogView.AppendText(string.Format("[{0}] 조건2 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, {7}, line:{8})\n",
// strCodeName,
// RowDT.ToString("yyyy-MM-dd HH:mm:ss"),
// RowDT.ToString("HH:mm:ss"),
// iRow,
// iPrice,
// iPrice-iStartPrice,
// (iPrice-iStartPrice)*100/(float)iStartPrice,
// iStartPrice,
// StartDT.ToString("yyyy-MM-dd HH:mm:ss"),
// StartDT.ToString("HH:mm:ss"),
// iStartRow
// ));
// iTotalProfit += (iPrice-iStartPrice)*iStockCount;
@@ -590,18 +647,26 @@ namespace AutoSellerNS
if(iTrailingCount >= Config.GetTrailingCnt())
{
m_tbLogView.AppendText(string.Format("[{0}] 트레일링 매도 {1} line:{2} {3:n0}원 ({4} : {5:n2}%) (매수 : {6:n0}원, {7} line:{8})\n",
int iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice);
m_tbLogView.AppendText(string.Format("[{0}] 트레일링 매도 (매수 : {1:n0}원, {2}, line:{3}) (매도 : {4:n0}원(매도가:{5:n0}원) {6} line:{7}) ({8}, {9:n0} : {10:n2}%) \n",
strCodeName,
RowDT.ToString("yyyy-MM-dd HH:mm:ss"),
iRow,
iPrice,
iPrice-iStartPrice,
(iPrice-iStartPrice)*100/(float)iStartPrice,
iStartPrice,
StartDT.ToString("yyyy-MM-dd HH:mm:ss"),
iStartRow
StartDT.ToString("HH:mm:ss"),
iStartRow,
iPrice,
iSellPrice,
RowDT.ToString("HH:mm:ss"),
iRow,
iSellPrice-iStartPrice,
(iSellPrice-iStartPrice)*iStockCount,
(iSellPrice-iStartPrice)*100/(float)iStartPrice
));
iTotalProfit += (iPrice-iStartPrice)*iStockCount;
iTotalProfit += (iSellPrice-iStartPrice)*iStockCount;
iTotalBid += iStartPrice*iStockCount;
break;
}
@@ -615,7 +680,7 @@ namespace AutoSellerNS
}
}
m_tbLogView.AppendText(string.Format("[시뮬레이션 종료] 총수익 : {0:n0}원 : {1:n2}%\n\n", iTotalProfit, iTotalProfit*100/(float)iTotalBid));
m_tbLogView.AppendText(string.Format("[시뮬레이션 종료] 총수익 : {0:n0}원 : {1:n2}%\n\n", iTotalProfit, iTotalProfit*100/(float)1000000));
m_tbLogView.SelectionStart = m_tbLogView.TextLength;
m_tbLogView.ScrollToCaret();
}