Ejemplo n.º 1
0
 public KtbSpotPosition(KtbSpotPosition origin)
 {
     this.TradingDate = origin.TradingDate;
     this.Long_2_Short_1 = origin.Long_2_Short_1;
     this.Rate = origin.Rate;
     this.Count = origin.Count;
     this.Price = origin.Price;
     this.Notional = origin.Notional;
 }
Ejemplo n.º 2
0
        void WriteRemainLongBody(KtbSpotPosition longPos, CsvFileWriter writer)
        {
            CsvRow row = new CsvRow();

            row.Add(longPos.TradingDate.ToString("yyyy-MM-dd"));
            row.Add("" + longPos.Count);
            row.Add(longPos.Rate.ToString("n5"));
            row.Add("" + longPos.Price);
            row.Add("" + longPos.Notional);

            writer.WriteRow(row);
        }
Ejemplo n.º 3
0
        void LoadYesterdayLongRemains()
        {
            try
            {
                const string kRemainsFolder = @"remains\";
                string fileName = String.Format("{0}_remains.csv", _yesterday.ToString("yyyy_MM_dd"));
                string remains_path = String.Format("{0}{1}{2}", kFolder, kRemainsFolder, fileName);

                logger.Info("{0} 읽기 시도", remains_path);

                CsvFileReader reader = new CsvFileReader(remains_path);

                Boolean header = true;
                while (true)
                {
                    CsvRow row = new CsvRow();
                    if (reader.ReadRow(row))
                    {
                        if (header)
                        {
                            header = false;
                            continue;
                        }

                        DateTime dt = DateTime.ParseExact(row[0], "yyyy-MM-dd", null);
                        long count = Convert.ToInt64(TextUtil.RemoveComma(row[1]));
                        double rate = Math.Round(Convert.ToDouble(row[2]), 5);
                        int price = Convert.ToInt32(TextUtil.RemoveComma(row[3]));
                        long notional = Convert.ToInt64(TextUtil.RemoveComma(row[4]));

                        KtbSpotPosition pos = new KtbSpotPosition();
                        pos.TradingDate = dt;
                        pos.Long_2_Short_1 = 2;
                        pos.Count = count;
                        pos.Rate = rate;
                        pos.Price = price;
                        pos.Notional = notional;

                        this.Longs.Add(pos);
                    }
                    else
                    {
                        break;
                    }
                }
                reader.Close();

                logger.Info("Yesterday Long Remain Position Load complete.");
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
            }
        }
Ejemplo n.º 4
0
        void LoadInput_KtsTLog()
        {
            const string kSubFolder = @"input_kts_tlog\";
            string fileName = String.Format("{0}_kts_tlog.xls", _today.ToString("yyyy_MM_dd"));
            string kts_tlog_path = String.Format("{0}{1}{2}", kFolder, kSubFolder, fileName);

            List<KtbSpotPosition> todayLongs = new List<KtbSpotPosition>();
            List<KtbSpotPosition> todayShorts = new List<KtbSpotPosition>();

            logger.Info("{0} 읽기 시도", kts_tlog_path);

            Workbook book = Workbook.Load(kts_tlog_path);
            Worksheet sheet = book.Worksheets[0];

            CellCollection cells = sheet.Cells;
            int x = cells.LastColIndex;
            int yCount = cells.LastRowIndex;

            for (int y = 0; y <= yCount; ++y)
            {
                if (y == 0)
                {
                    //skip header
                    continue;
                }

                string value = cells[y, 0].StringValue;
                if (value.Length == 0)
                {
                    //skip
                    continue;
                }
                //0     거래원,	X
                //1     주문 번호,	X
                //2     호가 구분,X
                //3     종목 구분,	X
                //4     종목명,	X
                //5     만기,	X
                //6     매도 매수,	O
                //7     결제 딜러,	X
                //8     체결가 (원),	O
                //9     수익률 (%),	O
                //10   체결량 (억원),	O
                //11   결제대금(원), 	O
                //12   체결 번호,	O
                //13   체결시각,X
                string longShort = cells[y, 6].StringValue;
                int price = Convert.ToInt32(cells[y, 8].Value);
                double rate = Convert.ToDouble(cells[y, 9].Value);
                long count = Convert.ToInt64(cells[y, 10].Value) * CommonConst._100_000_000;
                long notional = Convert.ToInt64(cells[y, 11].Value);
                string id = cells[y, 12].StringValue;

                KtbSpotPosition spot = new KtbSpotPosition();
                spot.TradingDate = _today;
                spot.Long_2_Short_1 = longShort.CompareTo("매수") == 0 ? 2: 1;
                spot.Rate = rate;
                spot.Count = count;
                spot.Price = price;
                spot.Notional = notional;

                if (spot.Long_2_Short_1 == 1)
                {
                    todayShorts.Add(spot);
                }
                else
                {
                    todayLongs.Add(spot);
                }
            }

            todayShorts.Reverse();
            todayLongs.Reverse();

            this.Shorts.AddRange(todayShorts);
            this.Longs.AddRange(todayLongs);

            foreach (KtbSpotPosition spot in todayLongs)
            {
                KtbSpotPosition cloneSpot = new KtbSpotPosition(spot);
                this.TodayLongs.Add(cloneSpot);
            }

            logger.Info("Today kts_tlog load complete...");
        }
Ejemplo n.º 5
0
        KtbSpotPosition GetShortRemainPos(KtbSpotPosition shortPos, KtbSpotDonePosition done)
        {
            long remainCount = shortPos.Count - done.ShortPosition.Count;
            Trace.Assert(remainCount >= 0);

            KtbSpotPosition ret = new KtbSpotPosition(shortPos);
            ret.ChangeCountAndNotional(remainCount);
            return ret;
        }
Ejemplo n.º 6
0
        KtbSpotPosition GetLongRemainPos(KtbSpotPosition longPos, KtbSpotDonePosition done)
        {
            long remainCount = longPos.Count - done.LongPosition.Count;
            Trace.Assert(remainCount >= 0);

            KtbSpotPosition ret = new KtbSpotPosition(longPos);
            ret.ChangeCountAndNotional(remainCount);
            return ret;
        }
Ejemplo n.º 7
0
        KtbSpotDonePosition GetDonePos(KtbSpotPosition longPos, KtbSpotPosition shortPos)
        {
            KtbSpotDonePosition done = new KtbSpotDonePosition();

            long count = Math.Min(longPos.Count, shortPos.Count);

            KtbSpotPosition doneLongPos = new KtbSpotPosition(longPos);
            doneLongPos.ChangeCountAndNotional(count);
            done.LongPosition = doneLongPos;

            KtbSpotPosition doneShortPos = new KtbSpotPosition(shortPos);
            doneShortPos.ChangeCountAndNotional(count);
            done.ShortPosition = doneShortPos;

            return done;
        }
Ejemplo n.º 8
0
        void WriteLongBody(KtbSpotPosition longPos, CsvFileWriter writer)
        {
            CsvRow row = new CsvRow();

            row.Add("" + 2);
            row.Add("" + longPos.Count / CommonConst._100_000_000);
            row.Add(longPos.Rate.ToString("n5"));
            row.Add("" + longPos.Price);
            row.Add("" + longPos.Notional);

            writer.WriteRow(row);
        }
Ejemplo n.º 9
0
        void LoadYesterdayLongRemains()
        {
            try
            {
                CsvFileReader reader = new CsvFileReader(_yesterdayLongRemainFileName_Input);

                Boolean header = true;
                while (true)
                {
                    CsvRow row = new CsvRow();
                    if (reader.ReadRow(row))
                    {
                        if (header)
                        {
                            header = false;
                            continue;
                        }

                        DateTime dt = DateTime.ParseExact(row[0], "yyyy-MM-dd", null);
                        long count = Convert.ToInt64(row[1]) * CommonConst._100_000_000;
                        double rate = Math.Round(Convert.ToDouble(row[2]), 5);
                        int price = Convert.ToInt32(row[3]);
                        long notional = Convert.ToInt64(row[4]);

                        KtbSpotPosition pos = new KtbSpotPosition();
                        pos.TradingDate = dt;
                        pos.Long_2_Short_1 = 2;
                        pos.Count = count;
                        pos.Rate = rate;
                        pos.Price = price;
                        pos.Notional = notional;

                        this.Longs.Add(pos);
                    }
                    else
                    {
                        break;
                    }
                }
                reader.Close();

                logger.Info("Yesterday Long Remain Position Load complete.");
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
            }
        }
Ejemplo n.º 10
0
        void LoadTodayShort()
        {
            try
            {
                CsvFileReader reader = new CsvFileReader(_todayShortFileName_Input);

                Boolean header = true;
                while (true)
                {
                    CsvRow row = new CsvRow();
                    if (reader.ReadRow(row))
                    {
                        if (header)
                        {
                            header = false;
                            continue;
                        }

                        DateTime dt = this.Today;

                        long count = Convert.ToInt64(row[1]) * CommonConst._100_000_000;
                        double rate = Math.Round(Convert.ToDouble(row[2]), 5);
                        int price = Convert.ToInt32(TextUtil.RemoveComma(row[3]));
                        long notional = Convert.ToInt64(TextUtil.RemoveComma(row[4]));

                        KtbSpotPosition pos = new KtbSpotPosition();
                        pos.TradingDate = dt;
                        pos.Long_2_Short_1 = 1;
                        pos.Count = count;
                        pos.Rate = rate;
                        pos.Price = price;
                        pos.Notional = notional;

                        this.Shorts.Add(pos);
                    }
                    else
                    {
                        break;
                    }
                }
                reader.Close();

                logger.Info("Today Short Position Load complete.");
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
            }
        }