예제 #1
0
        public static List<MarketData> FillByPivotData(MarketData pivotData, List<MarketData> inputData)
        {
            // pivotData의 datetime에 맞추어서 나머지 데이터를 채운다.
            DateTime curDateTime = pivotData.StartDate;
            List<MarketData> outputData = new List<MarketData>();
            Dictionary<String, MarketDataTrace> trace = new Dictionary<string, MarketDataTrace>();

            // init variables
            foreach (MarketData md in inputData)
            {
                String ticker = md.Ticker;
                DOHLC firstData = md.GetByIndex(0);
                trace.Add(md.Ticker, new MarketDataTrace(ticker, firstData));
                outputData.Add(new MarketData(md));
            }

            while (curDateTime <= pivotData.EndDate)
            {
                if (pivotData.IsExistDate(curDateTime))
                {
                    // update trace
                    foreach (MarketData md in inputData)
                    {
                        String ticker = md.Ticker;
                        if (md.IsExistDate(curDateTime))
                        {
                            trace[ticker].CurData = md.GetData(curDateTime);
                        }
                    }

                    // set data
                    foreach (MarketData md in outputData)
                    {
                        String ticker = md.Ticker;
                        MarketDataTrace tr = trace[ticker];
                        // 기준 데이터보다 전 데이터이어야 한다.
                        Trace.Assert(tr.CurData.CurDate <= curDateTime, String.Format("{0}, {1}, {2}", tr.Ticker, tr.CurData.CurDate, curDateTime));
                        md.AddDatum(curDateTime, tr.CurData.OHLC);

                        if (tr.CurData.CurDate != curDateTime)
                        {
                            md.SetPrevDataUsedDate(curDateTime);
                        }
                    }
                }
                curDateTime = curDateTime.AddDays(1);
            }
            return outputData;
        }
예제 #2
0
 MarketData GetNewMarketData(DateTime startDate, DateTime endDate, MarketData md)
 {
     MarketData newMD = new MarketData(startDate, endDate, md.Ticker);
     DateTime curDate = startDate;
     while (curDate <= endDate)
     {
         if (md.IsExistDate(curDate))
         {
             DOHLC dohlc = md.GetData(curDate);
             newMD.AddDatum(dohlc);
         }
         curDate = curDate.AddDays(1);
     }
     return newMD;
 }
예제 #3
0
        public MarketData ReadMarketData(
            String ticker, object src, DateTime startDate, DateTime endDate)
        {
            String text = src as String;
            List<DOHLC> dohlcData = new List<DOHLC>();

            try
            {
                StringReader sr = new StringReader(text);
                while (true)
                {
                    String line = sr.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    DOHLC data = ParseLine(line, ticker, startDate, endDate);

                    if (data != null)
                    {
                        dohlcData.Add(data);
                        UpdateStartEndDate(data.CurDate);
                    }
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
            }

            MarketData marketData = new MarketData(_readStartDate, _readEndDate, ticker);
            foreach (DOHLC dohlc in dohlcData)
            {
                marketData.AddDatum(dohlc);
            }

            return marketData;
        }
예제 #4
0
 public void Add(MarketDataSetKey key, MarketData data)
 {
     _data.Add(key, data);
     _tickers.Add(data.Ticker, data.Ticker);
     _marketDataKeys.Add(key);
     MarketDataSetKeyManager.Ins().AddKey(key, data.Ticker);
 }
예제 #5
0
        void UpdatePrevDataGridView_Raw(MarketData md)
        {
            DateTime curDate = md.StartDate;
            String ticker = md.Ticker;
            String desc = TickerNameMap.Ins().GetDesc(ticker);

            while (curDate <= md.EndDate)
            {
                if (md.IsExistDate(curDate))
                {
                    DOHLC datum = md.GetData(curDate);
                    double value = datum.OHLC.Close;
                    int index = dataGridView1.Rows.Add();

                    dataGridView1.Rows[index].Cells[0].Value = curDate.ToString("yyyy-MM-dd");
                    dataGridView1.Rows[index].Cells[1].Value = ticker;
                    dataGridView1.Rows[index].Cells[2].Value = desc;
                    dataGridView1.Rows[index].Cells[3].Value = value;
                }

                curDate = curDate.AddDays(1);
            }
        }
예제 #6
0
        public void ReadyData()
        {
            // Load data
            MarketData mdKospi = new MarketData(Input.StartDate, Input.EndDate, "KM1 R:00_0_R Index");
            MarketData mdBond = new MarketData(Input.StartDate, Input.EndDate, "KE1 R:00_0_R Comdty");
            MarketData mdDollar = new MarketData(Input.StartDate, Input.EndDate, "KU1 R:00_0_R Curncy");
            mdKospi.LoadDataFromDB();
            mdBond.LoadDataFromDB();
            mdDollar.LoadDataFromDB();

            // Ready data
            List<MarketData> l = new List<MarketData>();
            l.Add(mdKospi);
            l.Add(mdBond);
            l.Add(mdDollar);
            List<MarketData> alignedData = DataUtil.FillByPivotData(mdKospi, l);
            Boolean arranged = DataUtil.IsArrangedDateAndIndex(alignedData);
            Trace.Assert(arranged);

            //Set data
            this._readyData.Add(MarketDataSetKey.KospiFuture, alignedData[0]);
            this._readyData.Add(MarketDataSetKey.KtbFuture, alignedData[1]);
            this._readyData.Add(MarketDataSetKey.DollarFuture, alignedData[2]);
            this._readyData.RegisterPivotData(alignedData[0]);
        }
예제 #7
0
        void LoadCycleEqAdjs()
        {
            _mdPivot = DataUtil.GetKeyMarketData(MarketDataSetKey.CycleLeadingIndex, _startDate, _endDate);
            //string marketDataText = DataUtil.GetMarketDataStringFromTextFile(kFileName);
            //MarketData md =
            //    new MarketDataTextReader().ReadMarketData(_key, marketDataText, _startDate, _endDate);

            _cycleAdjDic = new Dictionary<DateTime, double>();
            long totalCount = _mdPivot.GetTotalCount();
            for (int i = 0; i < totalCount; i++)
            {
                DOHLC dohlc = _mdPivot.GetByIndex(i);
                DateTime curDate = dohlc.CurDate;
                double curValue = dohlc.OHLC.Close;
                double curAdj = CalculateCycleAdjValue(curValue, kMaxValue, kMinValue);
                curAdj = GetSwitchUpDownAdjValue(curAdj);
                _cycleAdjDic.Add(curDate, curAdj);
            }
        }
예제 #8
0
        Dictionary<DateTime, double> GetDeltaVolAdjRates(MarketDataSetKey key, MarketData md)
        {
            DeltaVolInput input = GetDefaultDeltaVolAdjInput(key);
            DeltaVolTradingSimulator simulator =
                new DeltaVolTradingSimulator(key, input.BaseInvest, input.PayoffType, input.DefaultStrikeDiff,
                     input.DefaultPeriod, input.IssueInterval, input.DefaultVol, input.bAmountBasis, md);

            if (input.bMATrendTest)
            {
                if (MarketDataSetKey.KospiFuture == key)
                {
                    simulator.AddMATrendFilter(10, 50);
                }
                else if (MarketDataSetKey.KtbFuture == key)
                {
                    simulator.AddMATrendFilter(15, 50);
                }
                else
                {
                    simulator.AddMATrendFilter(10, 50);
                }

                if (input.bMaSpreadSwitchTest)
                {
                    if (input.bMaSpreadSwitchTest)
                    {
                        if (MarketDataSetKey.KospiFuture == key)
                        {
                            simulator.UseMASpreadSwitch(0.2, -0.2);
                        }
                        else if (MarketDataSetKey.KtbFuture == key)
                        {
                            simulator.UseMASpreadSwitch(0.05, -0.05);
                        }
                        else
                        {
                            simulator.UseMASpreadSwitch(0.2, -0.2);
                        }
                    }
                }
            }
            if (input.bDeltaSwitchUpDown)
            {
                simulator.AddDeltaSwitchUpDownFilter(20);
            }
            if (input.bReturnModel)
            {
                simulator.ReplaceWithReturnModel(input.ReturnCap);
            }

            SinglePnLResult result = simulator.Simulate();
            Dictionary<DateTime, double> adjRates = GetTradingInvestAdjFromResult(result);

            return adjRates;
        }
예제 #9
0
 public static MarketData LoadDataAndAddToList(String ticker, DateTime startDate, DateTime endDate, List<MarketData> l)
 {
     MarketData md = new MarketData(startDate, endDate, ticker);
     md.LoadDataFromDB();
     l.Add(md);
     return md;
 }
예제 #10
0
        public static DateTime GetPivotTradingDate(int pivot, DateTime curDate, MarketData pivotData)
        {
            DateTime pivotDate = curDate;

            while (pivot > 0)
            {
                pivotDate = pivotDate.AddDays(1);
                if (pivotData.IsExistDate(pivotDate))
                {
                    pivot--;
                }
            }

            while (pivot < 0)
            {
                pivotDate = pivotDate.AddDays(-1);
                if (pivotData.IsExistDate(pivotDate))
                {
                    pivot++;
                }
            }

            return pivotDate;
        }
예제 #11
0
        /**
         * Target Date가 비거래일이면, 직전 거래일을 반환한다.
         * */
        public static DateTime GetLastTradingDay(MarketData mdPivot, DateTime targetDate)
        {
            if (mdPivot == null || mdPivot.GetByIndex(0).CurDate >= targetDate)
            {
                if (targetDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    return targetDate.AddDays(-2);
                }
                if (targetDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    return targetDate.AddDays(-1);
                }
                return targetDate;
            }

            DateTime tradingDate = targetDate;
            while (true)
            {
                if (mdPivot.IsExistDate(tradingDate))
                {
                    break;
                }
                tradingDate = tradingDate.AddDays(-1);
            }
            return tradingDate;
        }
예제 #12
0
 public static MarketData GetKeyMarketData(MarketDataSetKey key, DateTime startDate, DateTime endDate)
 {
     String ticker = GetTickerFromMarketDataKey(key);
     MarketData md = new MarketData(startDate, endDate, ticker);
     md.LoadDataFromDB();
     return md;
 }
예제 #13
0
 public MarketData(MarketData md)
 {
     this.StartDate = md.StartDate;
     this.EndDate = md.EndDate;
     this.Ticker = md.Ticker;
 }
예제 #14
0
 public void RegisterPivotData(MarketData md)
 {
     this.PivotData = md;
 }
예제 #15
0
 static Dictionary<String, MarketData> GetOutputIntersectionDict(List<MarketData> inputs)
 {
     Dictionary<String, MarketData> dict = new Dictionary<string, MarketData>();
     foreach (MarketData md in inputs)
     {
         MarketData newMarketData = new MarketData(md);
         dict.Add(md.Ticker, newMarketData);
     }
     return dict;
 }
예제 #16
0
 double GetUpDownRate(MarketData md, DateTime prevDate, DateTime curDate)
 {
     double curPrice = md.GetData(curDate).OHLC.Close;
     double prevPrice = md.GetData(prevDate).OHLC.Close;
     return (curPrice / prevPrice) - 1;
 }
예제 #17
0
 void AssignDollarWeight(MarketData dollarMargetData)
 {
     //_dollarFutreWeight = GetDeltaVolAdjRates(MarketDataSetKey.DollarFuture, dollarMargetData);
 }