예제 #1
0
        public double CalculateAssetWeight_Raw(DateTime targetDate)
        {
            if (!_marketData.ContainsKey(targetDate))
            {
                //logger.Warn("Invalid {0}", targetDate);
                return double.MinValue;
            }

            double ret = double.MinValue;
            double curValue = _marketData[targetDate];

            if (_prevMarketData == double.MinValue)
            {
                ret = 1.0;
            }
            else
            {
                double prevValue = _prevMarketData;

                // changed more than 1 bp
                if (Math.Abs(prevValue - curValue) > 0.01)
                {
                    double increment = curValue / (prevValue + 0.000001) - 1;
                    // 금리 변동이 있다.
                    CbrEvent ev = new CbrEvent();
                    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 = curValue;
            return ret;
        }
예제 #2
0
        double GetIncrementEach(
            CbrEvent lastEvent,
            CbrEvent curEvent,
            DateTime curDate)
        {
            if (curEvent.EndDate < curDate)
            {
                // 기한이 지났다.
                return 0;
            }
            double doubleDownFactor = GetDoubleDownFactor(lastEvent, curEvent);
            double defaultIncrement = GetDefaultIncrement(curEvent, curDate);

            double ret = defaultIncrement * doubleDownFactor;
            return ret;
        }
예제 #3
0
        double GetDefaultIncrement(CbrEvent curEvent, DateTime curDate)
        {
            int remainDays = (curEvent.EndDate - curDate).Days;

            if (remainDays < 0)
            {
                return 0.0;
            }

            if (remainDays < 90)
            {
                double y = (double)remainDays / 90;
                double increment = y * curEvent.TargetIncrement * (-1);
                return increment;
            }
            else if (remainDays <= 670)
            {
                return curEvent.TargetIncrement * (-1);
            }
            else
            {
                double daysAfterStart = (365 * 2 + 1) - remainDays;
                if (daysAfterStart < 0)
                {
                    return 0.0;
                }
                double y = daysAfterStart / 60;
                double increment = y * curEvent.TargetIncrement * (-1);
                return increment;
            }
        }
예제 #4
0
        double GetDoubleDownFactor(CbrEvent lastEvent, CbrEvent curEvent)
        {
            double factor = 1;
            const double kFactor = 1.3;
            //const double kFactor = 1000;
            double devide = kFactor;
            if (lastEvent.UpDown != curEvent.UpDown)
            {
                devide = kFactor;
            }

            int diff = lastEvent.EventKey - curEvent.EventKey;
            for (int i = 0; i < diff; ++i)
            {
                factor /= devide;
            }
            return factor;
        }
예제 #5
0
        public double GetIncrement(
            CbrEvent lastEvent,
            List<CbrEvent> events,
            DateTime curDate,
            double weight)
        {
            List<double> increments = new List<double>();
            foreach (CbrEvent ev in events)
            {
                double curIncrement = GetIncrementEach(lastEvent, ev, curDate);
                increments.Add(curIncrement);
            }

            double totalIncrement = weight * (1.0 + increments.Sum());

            totalIncrement = MathUtil.CapAndFloor(totalIncrement, 5, 0);

            if (totalIncrement < 0.0)
            {
                logger.Warn("BokRate TotalIncrement < 0.0 ({0})", totalIncrement);
                //Trace.Assert(totalIncrement >= 0.0);
                totalIncrement = 0.0;
            }

            return totalIncrement;
        }