Esempio n. 1
0
        public AdjRateDatum CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            MarketData md = data.GetData(MarketDataSetKey.KospiFuture);
            DOHLC dohlc = md.GetData(targetDate);
            double curValue = dohlc.OHLC.Close;

            AdjRateDatum ret = null;

            if (_prevValue > 0)
            {
                // 평균 변동성을 구한다.
                double increment = (curValue - _prevValue) / _prevValue;
                _ma.Add(increment);
                double avgIncrement = _ma.GetCurMA();

                int level = (int)(avgIncrement * 100);

                double kospiFactor = 1.3 - 0.1 * level;
                ret = new AdjRateDatum(kospiFactor * _weight, 1, 1);
            }
            else
            {
                ret = new AdjRateDatum(1, 1, 1);
            }
            _prevValue = curValue;

            return ret;
        }
Esempio n. 2
0
        public AdjRateDatum CalculateAssetWeight_Raw(DateTime targetDate, MarketDataSet data)
        {
            MarketData md = data.GetData(MarketDataSetKey.KospiFuture);
            DOHLC dohlc = md.GetData(targetDate);
            double curValue = dohlc.OHLC.Close;

            AdjRateDatum ret = null;

            if (_prevValue > 0)
            {
                // 평균 변동성을 구한다.
                double increment = (curValue - _prevValue) / _prevValue;
                _ma.Add(Math.Abs(increment));
                double avgIncrement = _ma.GetCurMA();

                int level = (int)(avgIncrement * 200);

                double kospiFactor = 1.3 - 0.1 * level;
                kospiFactor *= _weight;
                kospiFactor = MathUtil.CapAndFloor(kospiFactor);

                ret = new AdjRateDatum(kospiFactor, 1, 1);
            }
            else
            {
                ret = new AdjRateDatum(1, 1, 1);
            }
            _prevValue = curValue;

            return ret;
        }
Esempio n. 3
0
        public AdjRateDatum CalculateAssetWeight(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            OperationRow opData = opSet.GetData(_key);
            Boolean on = opData.On;
            AdjRateDatum others = _nextAdjustment.CalculateAssetWeight(opSet, targetDate, data);

            if (on)
            {
                AdjRateDatum mine = new AdjRateDatum(_kospiAdjustment, _bondAdjustment, _dollarAdjustment);
                Operation op = opData.Op;
                if (op == Operation.Multiply)
                {
                    AdjRateDatum ret = AdjUtil.Multiply(mine, others);
                    return ret;
                }
                else
                {
                    logger.Warn("Multiply 이외의 기능은 아직 제공하고 있지 않음");
                    return others;
                }
            }
            else
            {
                return others;
            }
        }
Esempio n. 4
0
        public AdjRateDatum CalculateAdjRateDatum(DateTime targetDate, MarketDataSet data)
        {
            if (_ismAdjDic == null || _ismAdjDic.Count == 0)
            {
                LoadISMEqAdjs();
                //TODO: ism 데이터를 월말이 아닌 매일 DB에 넣어준 후에 아래 함수를 사용.
                //LoadBSIEqAdjs(data);
            }

            // ISM 매달초 당월 말일날짜로 발표 -> 당월 중에는 전월 말일날짜 이용가능.
            DateTime dataAvailableDate = targetDate.AddDays( - 1 * targetDate.Day); //전월 말일

            double curAdj = 1;
            if (_ismAdjDic.ContainsKey(dataAvailableDate))
            {
                curAdj = _ismAdjDic[dataAvailableDate];
                _lastReturnedAdjRate = curAdj;
            }
            else
            {
                curAdj = _lastReturnedAdjRate;
            }

            AdjRateDatum ret = new AdjRateDatum(curAdj * _weight, 1, 1);

            return ret;
        }
Esempio n. 5
0
        public static AdjRateDatum Sum(AdjRateDatum a, AdjRateDatum b)
        {
            double kospiAdjustment = a.KospiRate + b.KospiRate;
            double bondAdjustment = a.KtbRate + b.KtbRate;
            double dollarAdjustment = a.DollarRate + b.DollarRate;

            AdjRateDatum aa = new AdjRateDatum(kospiAdjustment, bondAdjustment, dollarAdjustment);
            return aa;
        }
Esempio n. 6
0
        public AdjRateDatum CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            if (_adjs.ContainsKey(targetDate))
            {
                Tuple<double, double, double> t = _adjs[targetDate];
                AdjRateDatum aa = new AdjRateDatum(t);
                _prev = aa;

                return aa;
            }
            return _prev;
        }
Esempio n. 7
0
        public AdjRateDatum CalculateAdjRateDatum(DateTime targetDate, MarketDataSet data)
        {
            if (_RealIrAdjDic == null || _RealIrAdjDic.Count == 0)
            {
                LoadRealIrAdjs(data);
            }

            double curAdj = 1;
            if (_RealIrAdjDic.ContainsKey(targetDate))
            {
                curAdj = _RealIrAdjDic[targetDate];
            }

            AdjRateDatum ret = new AdjRateDatum(1, curAdj * _weight, 1);

            return ret;
        }
Esempio n. 8
0
        public AdjRateDatum CalculateAdjRateDatum(DateTime targetDate, MarketDataSet data)
        {
            AdjRateDatum adj = new AdjRateDatum(1, 1, 1);
            if (targetDate > new DateTime(2007, 6, 1))
            {
                DateTime twoTradingDaysAgo = DataUtil.GetPivotTradingDate(-2, targetDate, data.PivotData);
                MarketData mdCreditDepositRate = data.GetData(MarketDataSetKey.KrxCreditDepositRate);

                DOHLC dohlc = mdCreditDepositRate.GetData(twoTradingDaysAgo);
                double rate = dohlc.OHLC.Close;

                double kospiAdjustment = GetKospiAdjustment(rate);

                kospiAdjustment = MathUtil.CapAndFloor(kospiAdjustment);

                adj = new AdjRateDatum(kospiAdjustment, 1, 1);
            }
            return adj;
        }
Esempio n. 9
0
        public AdjRateDatum CalculateAdjRateDatum(DateTime targetDate, MarketDataSet data)
        {
            if (_kospiFutureWeight == null || _kospiFutureWeight.Count == 0)
            {
                LoadDeltaVolAdjRates(data);
                //LoadDeltaVolAdjRates();
            }

            double kospiWeight = 1;
            double ktbWeight = 1;
            double dollarWeight = 1;
            if (_kospiFutureWeight.ContainsKey(targetDate))
            {
                kospiWeight = _kospiFutureWeight[targetDate] * _weight;
                if (_ktbFutureWeight.ContainsKey(targetDate))
                {
                    ktbWeight = _ktbFutureWeight[targetDate] * _weight;
                }
                else
                {
                    ktbWeight = _prev.KtbRate;
                }

                if (_dollarFutreWeight != null && _dollarFutreWeight.ContainsKey(targetDate))
                {
                    dollarWeight = _dollarFutreWeight[targetDate] * _weight;
                }
                else
                {
                    dollarWeight = _prev.DollarRate;
                }

                Tuple<double, double, double> t =
                    new Tuple<double, double, double>(kospiWeight, ktbWeight, dollarWeight);
                AdjRateDatum adjRateDatum = new AdjRateDatum(t);
                _prev = adjRateDatum;
                return adjRateDatum;
            }

            return _prev;
        }
Esempio n. 10
0
        public AdjRateDatum CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            MarketData md = data.GetData(MarketDataSetKey.BokRate);
            DOHLC dohlc = md.GetData(targetDate);

            AdjRateDatum ret = null;

            if (_prevMarketData == null)
            {
                ret = new AdjRateDatum(1, 1, 1);
            }
            else
            {
                double prevValue = _prevMarketData.OHLC.Close;
                double curValue = dohlc.OHLC.Close;

                // changed more than 1 bp
                if (Math.Abs(prevValue - curValue) > 0.01)
                {
                    double increment = curValue / prevValue - 1;
                    // 금리 변동이 있다.
                    BokRateEvent ev = new BokRateEvent();
                    ev.TargetIncrement = increment;
                    ev.StartDate = targetDate;
                    ev.EndDate = targetDate.AddYears(kEventDuration);
                    ev.EventKey = _eventKeyGenerator++;
                    ev.UpDown = increment > 0 ? UpDown.Up : UpDown.Down;

                    _events.Add(ev);
                    _lastEvent = ev;
                }
                ret = GetIncrement(targetDate);
            }
            _prevMarketData = dohlc;

            return ret;
        }
Esempio n. 11
0
        public AssetRateDataLog Execute(long caseNumber)
        {
            IAlloc allocBase = this._allocBases[(int)caseNumber];
            DateTime curDate = this.Input.StartDate;
            AssetRateDataLog log = new AssetRateDataLog();

            _curKey = String.Format("SAO({0})", allocBase.GetKey());

            while (curDate <= this.Input.EndDate)
            {
                if (this._readyData.IsExistDate(curDate))
                {
                    AssetRateDatum aw = allocBase.CalculateAndGetAssetRateDatum(curDate, this._readyData);
                    AdjRateDatum aa = new AdjRateDatum(1, 1, 1);
                    aw.Multiply(aa);
                    aw.SetScale();
                    log.Add(curDate, aw);
                }

                curDate = curDate.AddDays(1);
            }

            return log;
        }
Esempio n. 12
0
        public static AdjRateDatum Calculate(
            int key, 
            AdjRateDatum mine, 
            IAdjustment next, 
            OperationSet opSet, 
            DateTime targetDate, 
            MarketDataSet data)
        {
            if (next == null)
            {
                return mine;
            }

            OperationRow opData = opSet.GetData(key);
            Boolean on = opData.On;
            AdjRateDatum others = next.CalculateAssetWeight(opSet, targetDate, data);

            if (on)
            {
                Operation op = opData.Op;
                if (op == Operation.Multiply)
                {
                    AdjRateDatum ret = AdjUtil.Multiply(mine, others);
                    return ret;
                }
                else
                {
                    Trace.Assert(false);
                    return others;
                }
            }
            else
            {
                return others;
            }
        }
Esempio n. 13
0
        public AdjRateDatum CalculateAdjRateDatum(DateTime targetDate, MarketDataSet data)
        {
            if (_cycleAdjDic == null || _cycleAdjDic.Count == 0)
            {
                LoadCycleEqAdjs();
                //TODO: cycle 데이터를 월말이 아닌 매일 DB에 넣어준 후에 아래 함수를 사용.
                //LoadCycleEqAdjs(data);
            }

            // 경기선행지수 매달 말일 발표 -> 당월에는 전전월 말일자 데이터를 이용할 수 있다.
            DateTime dataAvailableDate = targetDate.AddDays(1 - 1 * targetDate.Day).AddMonths(-1); //전월 1일
            dataAvailableDate = dataAvailableDate.AddDays(-1); //전전월 말일

             // 당월 말일에는 전월 말일자
            if (targetDate == DataUtil.GetMonthEndWeekDay(targetDate))
            {
                dataAvailableDate = DataUtil.GetMonthEndDate(dataAvailableDate.AddDays(1));
            }

            dataAvailableDate = DataUtil.GetLastTradingDay(_mdPivot, dataAvailableDate); // 월말이 주말인 경우 마지막 금요일로 변환

            double curAdj = 1;
            if (_cycleAdjDic.ContainsKey(dataAvailableDate))
            {
                curAdj = _cycleAdjDic[dataAvailableDate];
                _lastReturnedAdjRate = curAdj;
            }
            else
            {
                curAdj = _lastReturnedAdjRate;
            }

            AdjRateDatum ret = new AdjRateDatum(curAdj * _weight, 1, 1);

            return ret;
        }
Esempio n. 14
0
 public void Multiply(AdjRateDatum adjRate)
 {
     this.KospiRate *= adjRate.KospiRate;
     this.KtbRate *= adjRate.KtbRate;
     this.DollarRate *= adjRate.DollarRate;
 }
Esempio n. 15
0
 AdjRateDatum SetBaseAdjRateDatum()
 {
     AdjRateDatum ret = null;
     if (this.Rule == MixupRule.Multiply)
     {
         ret = new AdjRateDatum(new Tuple<double,double,double>(1, 1, 1));
     }
     else if (this.Rule == MixupRule.Sum)
     {
         ret = new AdjRateDatum(new Tuple<double, double, double>(0, 0, 0));
     }
     else
     {
         Trace.Assert(false);
     }
     return ret;
 }
Esempio n. 16
0
 AdjRateDatum GetOperatedAdjRateDatum(AdjRateDatum datum1, AdjRateDatum datum2)
 {
     if (this.Rule == MixupRule.Multiply)
     {
         return AdjUtil.Multiply(datum1, datum2);
     }
     else if (this.Rule == MixupRule.Sum)
     {
         return AdjUtil.Sum(datum1, datum2);
     }
     Trace.Assert(false);
     return null;
 }
Esempio n. 17
0
 public void Sum(AdjRateDatum adjRate)
 {
     this.KospiRate += adjRate.KospiRate;
     this.KtbRate += adjRate.KtbRate;
     this.DollarRate += adjRate.DollarRate;
 }