예제 #1
0
        public void SetData(string str, string scv, byte[] dealsInfo, byte[] dealsData)
        {
            this.CurrentTestRet    = WekaUtils.StringToDoubleArray(str);
            this.CurrentClassValue = WekaUtils.StringToDoubleArray(scv);

            var deals = Feng.Windows.Utils.SerializeHelper.Deserialize <DealsInfo>(dealsInfo);

            if (dealsData != null)
            {
                System.IO.MemoryStream outStream = new System.IO.MemoryStream();
                var inStream = new System.IO.MemoryStream(dealsData);
                System.IO.Compression.GZipStream zipStream = new System.IO.Compression.GZipStream(inStream, System.IO.Compression.CompressionMode.Decompress);
                zipStream.CopyTo(outStream);

                deals.Deals = Feng.Windows.Utils.SerializeHelper.Deserialize <List <DealInfo> >(outStream.ToArray());
            }
            else
            {
                deals.Deals = new List <DealInfo>();
            }
            if (deals != null)
            {
                this.Deals  = deals;
                Initialized = true;
            }
        }
예제 #2
0
파일: DealsInfo.cs 프로젝트: vseledkin/MLEA
        public void CloseAll()
        {
            m_nowCloseManually = m_deals.Count;
            foreach (var i in m_deals)
            {
                if (i.DealType == 'B')
                {
                    float cost = ((float)m_nowPrice.close - i.OpenPrice - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                    m_nowCost -= cost * i.Volume;
                }
                else if (i.DealType == 'S')
                {
                    float cost = (i.OpenPrice - (float)m_nowPrice.close - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                    m_nowCost -= cost * i.Volume;
                }
                m_nowVolume += i.Volume;
            }

            m_deals.Clear();
        }
예제 #3
0
파일: DealsInfo.cs 프로젝트: vseledkin/MLEA
        private void CalculateCurrent()
        {
            m_currentProfit = 0;
            m_currentCost   = 0;
            m_currentVolume = 0;



            foreach (var i in m_deals)
            {
                m_currentVolume += i.Volume;
                m_currentCost   += i.Cost * i.Volume;

                if (m_nowPrice.close > 0)
                {
                    if (i.DealType == 'B')
                    {
                        float cost = ((float)m_nowPrice.close - i.OpenPrice - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                        m_currentProfit -= cost * i.Volume;
                    }
                    else if (i.DealType == 'S')
                    {
                        float cost = (i.OpenPrice - (float)m_nowPrice.close - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                        m_currentProfit -= cost * i.Volume;
                    }
                }
            }
        }
예제 #4
0
파일: DealsInfo.cs 프로젝트: vseledkin/MLEA
        //private void CalculateDealClose(DealInfo i)
        //{
        //    if (m_nowPrice.low == 0 || m_nowPrice.high == 0)
        //    {
        //        throw new AssertException("nowPrice low or high is not set.");
        //    }
        //    if (i.DealType == 'B')
        //    {
        //        if (m_nowPrice.low <= i.ClosePriceSl + spread)
        //        {
        //            m_nowFp++;
        //            float cost = (i.ClosePriceSl - i.OpenPrice - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else if (m_nowPrice.high >= i.ClosePriceTp - spread)
        //        {
        //            m_nowTp++;
        //            float cost = (i.ClosePriceTp - i.OpenPrice - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else
        //        {
        //            float cost = (float)(m_nowPrice.close - i.OpenPrice - spread) * GetPointInv(m_nowPrice.close);
        //            m_currentProfit -= cost * i.Volume;
        //        }
        //    }
        //    else
        //    {
        //        if (m_nowPrice.high + spread > i.ClosePriceSl)
        //        {
        //            m_nowFp++;
        //            float cost = ((i.OpenPrice - i.ClosePriceSl) - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else if (m_nowPrice.low + spread < i.ClosePriceTp)
        //        {
        //            m_nowTp++;
        //            float cost = ((i.OpenPrice - i.ClosePriceTp) - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else
        //        {
        //            float cost = (float)((i.OpenPrice - m_nowPrice.close) - spread) * GetPointInv(m_nowPrice.close);
        //            m_currentProfit -= cost * i.Volume;
        //        }
        //    }
        //}
        public void CloseAll()
        {
            m_nowCost       = 0;
            m_currentProfit = 0;
            m_nowTp         = 0;
            m_nowFp         = 0;

            m_totalVolume = 0;
            m_totalDeal   = 0;

            foreach (var i in m_deals)
            {
                if (i.CloseTime.HasValue)
                {
                    if (i.CloseTime <= m_nowTime)
                    {
                        if (i.Cost < 0)
                        {
                            m_nowTp++;
                        }
                        else
                        {
                            m_nowFp++;
                        }

                        m_nowCost += i.Cost * i.Volume;
                    }
                    else
                    {
                        if (i.DealType == 'B')
                        {
                            float cost = (float)(m_nowPrice.close - i.OpenPrice - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                            m_nowCost -= cost * i.Volume;
                            if (cost < 0)
                            {
                                m_nowTp++;
                            }
                            else
                            {
                                m_nowFp++;
                            }
                        }
                        else if (i.DealType == 'S')
                        {
                            float cost = (float)(i.OpenPrice - m_nowPrice.close - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                            m_nowCost -= cost * i.Volume;
                            if (cost < 0)
                            {
                                m_nowTp++;
                            }
                            else
                            {
                                m_nowFp++;
                            }
                        }
                    }
                }
            }


            m_deals.Clear();
        }
예제 #5
0
파일: DealsInfo.cs 프로젝트: vseledkin/MLEA
 public RealDealsInfo()
 {
     spread = 5 * DealsInfo.GetPoint(0);
 }