public AssetAdjustment CalculateAssetWeight(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            OperationRow opData = opSet.GetData(_key);
            Boolean on = opData.On;
            AssetAdjustment others = _nextAdjustment.CalculateAssetWeight(opSet, targetDate, data);

            if (on)
            {
                AssetAdjustment mine = new AssetAdjustment(_kospiAdjustment, _bondAdjustment, _dollarAdjustment);
                Operation op = opData.Op;
                if (op == Operation.Multiply)
                {
                    AssetAdjustment ret = AdjustmentUtil.Multiply(mine, others);
                    return ret;
                }
                else
                {
                    logger.Warn("Multiply 이외의 기능은 아직 제공하고 있지 않음");
                    return others;
                }
            }
            else
            {
                return others;
            }
        }
Exemple #2
0
        public AssetAdjustment CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            MarketData md = data.GetData(MarketDataSetKey.KospiFuture);
            DOHLC dohlc = md.GetData(targetDate);
            double curValue = dohlc.OHLC.Close;

            AssetAdjustment 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 AssetAdjustment(kospiFactor * _weight, 1, 1);
            }
            else
            {
                ret = new AssetAdjustment(1, 1, 1);
            }
            _prevValue = curValue;

            return ret;
        }
Exemple #3
0
        public static MarketDataSet GetBaseMarketData(StrategyBaseInput input)
        {
            List<MarketData> l = new List<MarketData>();
            MarketData mdKospiFuture = LoadDataAndAddToList("KM1 R:00_0_R Index", input.StartDate, input.EndDate, l);

            MarketData mdBond = LoadDataAndAddToList("KE1 R:00_0_R Comdty", input.ReadStartDate, input.EndDate, l);
            MarketData mdDollar = LoadDataAndAddToList("KU1 R:00_0_R Curncy", input.ReadStartDate, input.EndDate, l);
            MarketData mdKrxCreditDepositRate = LoadDataAndAddToList("KrxCreditDepositRate", input.ReadStartDate, input.EndDate, l);
            MarketData mdUsdKrwCurncy = LoadDataAndAddToList("USDKRW Curncy", input.ReadStartDate, input.EndDate, l);
            MarketData mdBokRate = LoadDataAndAddToList("KORP7D Index", input.ReadStartDate, input.EndDate, l);

            MarketData mdKospiIndex = LoadDataAndAddToList("KOSPI Index", input.ReadStartDate, input.EndDate, l);
            MarketData mdKtbSpotRate = LoadDataAndAddToList("KWNDF3 CMPN CURNCY", input.ReadStartDate, input.EndDate, l);

            List<MarketData> alignedData = DataUtil.FillByPivotData(mdKospiFuture, l);
            Boolean arranged = DataUtil.IsArrangedDateAndIndex(alignedData);
            Trace.Assert(arranged);

            //Set data
            MarketDataSet data = new MarketDataSet();
            data.Add(MarketDataSetKey.KospiFuture, alignedData[0]);
            data.Add(MarketDataSetKey.KtbFuture, alignedData[1]);
            data.Add(MarketDataSetKey.DollarFuture, alignedData[2]);
            data.Add(MarketDataSetKey.KrxCreditDepositRate, alignedData[3]);
            data.Add(MarketDataSetKey.DollarSpot, alignedData[4]);
            data.Add(MarketDataSetKey.BokRate, alignedData[5]);
            data.Add(MarketDataSetKey.KospiSpot, alignedData[6]);
            data.Add(MarketDataSetKey.KtbSpot, alignedData[7]);

            data.RegisterPivotData(alignedData[0]);

            return data;
        }
        public AssetAdjustment CalculateAssetWeight(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            LogRow row = new LogRow();
            row.CurDate = targetDate;
            row.PrevAreaNumber = _prevAreaNumber;
            row.PrevUpDown = _prevUpDown;

            MarketData md = data.GetData(MarketDataSetKey.KrxCreditDepositRate);
            DOHLC dohlc = md.GetData(targetDate);

            _ma.Add(dohlc.OHLC.Close);
            double ma = _ma.GetCurMA();
            int areaNumber = GetAreaNumber(ma);

            double kospiWeight = GetKospiWeight(areaNumber, row);

            _logs.Add(row);

            if (targetDate > new DateTime(2007, 6, 1))
            {
                return new AssetAdjustment(kospiWeight, 1, 1);
            }
            else
            {
                _prevUpDown = UpDown.Unknown;
            }
            return new AssetAdjustment(1, 1, 1);
        }
Exemple #5
0
        public AssetAdjustment CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            if (_adjs.ContainsKey(targetDate))
            {
                Tuple<double, double, double> t = _adjs[targetDate];
                AssetAdjustment aa = new AssetAdjustment(t);
                _prev = aa;

                return aa;
            }
            return _prev;
        }
        AssetAdjustment CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            MarketData md = data.GetData(MarketDataSetKey.DollarSpot);
            DOHLC dohlc = md.GetData(targetDate);
            double cur = dohlc.OHLC.Close;

            const double kMax = 1800;
            const double kMin = 900;

            double rate = (kMax - cur) / (kMax - kMin);
            rate = Math.Max(0, rate);
            rate = Math.Min(1, rate);

            rate = 0.5 + rate;

            return new AssetAdjustment(1, 1, rate * _weight);
        }
        public AssetAdjustment CalculateAssetWeight(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            AssetAdjustment adj = new AssetAdjustment(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);

                adj = new AssetAdjustment(kospiAdjustment, 1, 1);
            }
            return adj;
        }
Exemple #8
0
        public AssetAdjustment CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            RowInfo curRow = GetCurRowWithBasicInfo(targetDate, data);
            //포지션 정보를 설정한다.
            SetPositionInfo(targetDate, data, curRow);

            // 전일대비 변동율을 구한다.
            SetFutureIncrement(curRow, _prevRow);

            this._cumData.Add(curRow);

            // 코스피 선물 평균 변동성을 구한다.
            curRow.KospiVol = this._cumData.GetKospiAvgVol();

            // 비중을 구한다.
            AssetAdjustment adj = GetAdj(curRow);
            curRow.AssetAdj = adj;

            this._prevRow = curRow;

            return adj;
        }
Exemple #9
0
        public AssetAdjustment CalculateAssetWeight_Raw(OperationSet opSet, DateTime targetDate, MarketDataSet data)
        {
            MarketData md = data.GetData(MarketDataSetKey.BokRate);
            DOHLC dohlc = md.GetData(targetDate);

            AssetAdjustment ret = null;

            if (_prevMarketData == null)
            {
                ret = new AssetAdjustment(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;
        }
Exemple #10
0
        public static AssetAdjustment Calculate(
            int key, 
            AssetAdjustment mine, 
            IAdjustment next, 
            OperationSet opSet, 
            DateTime targetDate, 
            MarketDataSet data)
        {
            if (next == null)
            {
                return mine;
            }

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

            if (on)
            {
                Operation op = opData.Op;
                if (op == Operation.Multiply)
                {
                    AssetAdjustment ret = AdjustmentUtil.Multiply(mine, others);
                    return ret;
                }
                else
                {
                    Trace.Assert(false);
                    return others;
                }
            }
            else
            {
                return others;
            }
        }
 public void ReadyData()
 {
     this._readyData = DataUtil.GetBaseMarketData(this.Input);
 }
        Tuple<double, double, double, double> GetDailyPnL(
            AssetWeight aw, DateTime prevDate, DateTime curDate, long notional, MarketDataSet marketDataSet)
        {
            MarketData mdKospi = marketDataSet.GetData(MarketDataSetKey.KospiFuture);
            MarketData mdBond = marketDataSet.GetData(MarketDataSetKey.KtbFuture);
            MarketData mdDollar = marketDataSet.GetData(MarketDataSetKey.DollarFuture);

            double kospiUpDoweRate = GetUpDownRate(mdKospi, prevDate, curDate);
            double bondUpDoweRate = GetUpDownRate(mdBond, prevDate, curDate);
            double dollarUpDoweRate = GetUpDownRate(mdDollar, prevDate, curDate);

            double kospiPnL = aw.KospiWeight * notional * kospiUpDoweRate;
            double bondPnL = aw.BondWeight * notional * bondUpDoweRate;
            double dollarPnL = aw.DollarWeight * notional * dollarUpDoweRate;
            double sum = kospiPnL + bondPnL + dollarPnL;

            return new Tuple<double, double, double, double>(sum, kospiPnL, bondPnL, dollarPnL);
        }
        public void CalculatePnL(AssetWeightLog log, MarketDataSet marketDataSet)
        {
            DateTime prevDate = log.StartDate;
            DateTime curDate = log.StartDate.AddDays(1);

            _cumPnL.Add(prevDate, 0);

            while (curDate <= log.EndDate)
            {
                if (log.IsExistDate(curDate))
                {
                    AssetWeight awPrev = log.GetData(prevDate);
                    Tuple<double, double, double, double> dailyPnL = GetDailyPnL(
                        awPrev, prevDate, curDate, InitInvestAmount, marketDataSet);
                    AddDailyPnL(curDate, dailyPnL);
                    AddCumPnL(prevDate, curDate, dailyPnL.Item1);

                    ChangeCurDateAndPrevDate(ref prevDate, ref curDate);
                    continue;
                }
                curDate = curDate.AddDays(1);
            }
            double total = TotalPnL;
        }
Exemple #14
0
 public AssetAdjustment CalculateAssetWeight(OperationSet opSet, DateTime targetDate, MarketDataSet data)
 {
     AssetAdjustment adj = CalculateAssetWeight_Raw(opSet, targetDate, data);
     return AdjustmentUtil.Calculate(_key, adj, _nextAdjustment, opSet, targetDate, data);
 }
 public AssetAdjustment CalculateAssetWeight(OperationSet opSet, DateTime targetDate, MarketDataSet data)
 {
     return new AssetAdjustment(1, 1, 1);
 }
Exemple #16
0
 public AssetWeight CalculateAssetWeight(DateTime targetDate, MarketDataSet data)
 {
     //공평하게 0.33씩 나누어서 투자한다.
     AssetWeight aw = new AssetWeight(this.KospiWeight, this.BondWeight, this.DollarWeight);
     return aw;
 }
Exemple #17
0
        RowInfo GetCurRowWithBasicInfo(DateTime curDate, MarketDataSet data)
        {
            MarketData mdKospiFuture = data.GetData(MarketDataSetKey.KospiFuture);
            MarketData mdKtbFuture = data.GetData(MarketDataSetKey.KtbFuture);
            MarketData mdDollarFuture = data.GetData(MarketDataSetKey.DollarFuture);

            MarketData mdKospiSpot = data.GetData(MarketDataSetKey.KospiSpot);
            MarketData mdKtbSpot = data.GetData(MarketDataSetKey.KtbSpot);
            MarketData mdDollarSpot = data.GetData(MarketDataSetKey.DollarSpot);

            DOHLC kospiFuture = mdKospiFuture.GetData(curDate);
            DOHLC ktbFuture = mdKtbFuture.GetData(curDate);
            DOHLC dollarFuture = mdDollarFuture.GetData(curDate);

            DOHLC kospiSpot = mdKospiSpot.GetData(curDate);
            DOHLC ktbSpot = mdKtbSpot.GetData(curDate);
            DOHLC dollarSpot = mdDollarSpot.GetData(curDate);

            RowInfo row = new RowInfo();

            row.CurDate = curDate;

            row.KospiFuturePrice = kospiFuture.OHLC.Close;
            row.KtbFuturePrice = ktbFuture.OHLC.Close;
            row.DollarFuturePrice = dollarFuture.OHLC.Close;

            row.KospiSpotPrice = kospiSpot.OHLC.Close;
            row.KtbSpotPrice = ktbSpot.OHLC.Close;
            row.DollarSpotPrice = dollarSpot.OHLC.Close;

            return row;
        }
Exemple #18
0
        void SetPositionInfo(DateTime curDate, MarketDataSet data, RowInfo row)
        {
            MarketData mdKospiSpot = data.GetData(MarketDataSetKey.KospiSpot);
            MarketData mdKtbSpot = data.GetData(MarketDataSetKey.KtbSpot);
            MarketData mdDollarSpot = data.GetData(MarketDataSetKey.DollarSpot);

            DOHLC kospiSpot = mdKospiSpot.GetData(curDate);
            DOHLC ktbSpot = mdKtbSpot.GetData(curDate);
            DOHLC dollarSpot = mdDollarSpot.GetData(curDate);

            double kospiSpotPos = (kospiSpot.OHLC.Close - MagicNumber.KOSPI_SPOT_MIN_RANGE) /
                (MagicNumber.KOSPI_SPOT_MAX_RANGE - MagicNumber.KOSPI_SPOT_MIN_RANGE);

            double ktbSpotPos = (MagicNumber.KTB_SPOT_MAX_RANGE - ktbSpot.OHLC.Close) /
                (MagicNumber.KTB_SPOT_MAX_RANGE - MagicNumber.KTB_SPOT_MIN_RANGE);

            double dollarSpotPos = (dollarSpot.OHLC.Close - MagicNumber.DOLLAR_SPOT_MIN_RANGE) /
                (MagicNumber.DOLLAR_SPOT_MAX_RANGE - MagicNumber.DOLLAR_SPOT_MIN_RANGE);

            row.KospiSpotPosition = kospiSpotPos;
            row.KtbSpotPosition = ktbSpotPos;
            row.DollarSpotPosition = dollarSpotPos;
        }