Example #1
0
        public override void buildFromLegInfo(DateTime referenceDate, int payRec)
        {
            //int maturityYear = ConvertingTool.TenorMuliplier(this.LegDAO_.);
            int legTenorMonth = ConvertingTool.TenorMuliplier(this.LegDAO_.LEG_TENOR);

            //int cashflowCount = maturityYear * (12 / legTenorMonth);

            this.FP_CashFlowList_.Clear();

            DateTime roopDate = ConvertingTool.ToDateTime(this.LegDAO_.EFFECTIVE_DT);
            DateTime matutiryDate = ConvertingTool.ToDateTime(this.LegDAO_.MATURITY_DT);
            DateTime nextDate = roopDate.AddMonths(legTenorMonth);

            CalendarManager cm = new CalendarManager(referenceDate, CalendarManager.CountryType.SOUTH_KOREA);

            while (nextDate <= matutiryDate)
            {
                FP_FloatingRateCoupon fp_cashFlow = new FP_FloatingRateCoupon();

                fp_cashFlow.DAO_ = new clsMAST_CF_VANILLA_FLOATING_TB();

                fp_cashFlow.DAO_.LEG_ID = this.LegDAO_.INSTRUMENT_ID;
                fp_cashFlow.DAO_.LEG_TYP = 0;
                fp_cashFlow.DAO_.NOTIONAL = this.LegDAO_.NOTIONAL;
                fp_cashFlow.DAO_.PAY_RECEIVE = payRec;
                fp_cashFlow.DAO_.CALC_START_DT = roopDate.ToString("yyyyMMdd");
                fp_cashFlow.DAO_.CALC_END_DT = nextDate.ToString("yyyyMMdd");
                fp_cashFlow.DAO_.PAYMENT_DT = cm.adjust(nextDate).ToString("yyyyMMdd");

                fp_cashFlow.DAO_.CASHFLOW_DT = nextDate.ToString("yyyyMMdd");

                fp_cashFlow.DAO_.FIXING_DT = cm.adjust(roopDate).ToString("yyyyMMdd");

                // 우선 DEFAULT로 박고, FIXING은 차후 데일리로 계산함.

                fp_cashFlow.DAO_.FIXING_INDEX_CD = this.LegDAO_.FIXING_INDEX_CD;
                fp_cashFlow.DAO_.GREARING = this.LegDAO_.GREARING;
                fp_cashFlow.DAO_.SPREAD = this.LegDAO_.SPREAD;
                fp_cashFlow.DAO_.FIXED_FIXING = 0.0;
                fp_cashFlow.DAO_.FIXED_FIXING_CALCLATED
                    = (int)clsMAST_CF_VANILLA_FLOATING_TB.FIXED_FIXING_CALCLATED_Type.NOT_FIXED;

                this.FP_CashFlowList_.Add(fp_cashFlow);

                roopDate = roopDate.AddMonths(legTenorMonth);
                nextDate = roopDate.AddMonths(legTenorMonth);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            //QuantLib.MonotonicCubic m = new QuantLib.MonotonicCubic();
            //string result = string.Empty;
            //for (int i = 0; i < 10000; i++)
            //{
            //    result = IDGenerator.getLetter(i, 4);
            //    Console.WriteLine(i + " : " + result + " : " + IDGenerator.getIndex(result) );
            //}

            CalendarManager cm = new CalendarManager(DateTime.Now, CalendarManager.CountryType.SOUTH_KOREA);

            for (int i = 2015; i < 2020; i++)
            {
                for (int j = 1; j < 13; j++)
                {
                    Console.WriteLine(CalendarManager.monthlyOptionMaturiry(i, j, DayOfWeek.Thursday, 2).ToString("yyyyMMdd"));
                    
                }
            }

            //HedgeTest ht = new HedgeTest();
            //ht.doTest2();

            
            // 로드 yield curve 
            // master 도 로드

            // market data 로드 ( ir curve : index curve , discount curve )


            
            
            // irs master info 로드 ( notional cashflow 등 )




            //QuantLib.Swap ql_swap = new Swap();


        }
Example #3
0
        public override void buildFromLegInfo(DateTime referenceDate,int payRec)
        {
            //int maturityYear = ConvertingTool.TenorMuliplier(this.LegDAO_.);
            int legTenorMonth = ConvertingTool.TenorMuliplier(this.LegDAO_.LEG_TENOR);

            //int cashflowCount = maturityYear * (12 / legTenorMonth);

            this.FP_CashFlowList_.Clear();

            DateTime roopDate = ConvertingTool.ToDateTime(this.LegDAO_.EFFECTIVE_DT);
            DateTime matutiryDate = ConvertingTool.ToDateTime(this.LegDAO_.MATURITY_DT);
            DateTime nextDate = roopDate.AddMonths(legTenorMonth);

            CalendarManager cm = new CalendarManager(referenceDate,CalendarManager.CountryType.SOUTH_KOREA);

            while (nextDate <= matutiryDate )
            {
                FP_FixedRateCoupon fp_cashFlow = new FP_FixedRateCoupon();

                fp_cashFlow.DAO_ = new clsMAST_CF_FIXED_TB();

                fp_cashFlow.DAO_.LEG_ID = this.LegDAO_.INSTRUMENT_ID;
                fp_cashFlow.DAO_.LEG_TYP = 0;
                fp_cashFlow.DAO_.PAY_RECEIVE = payRec;
                fp_cashFlow.DAO_.NOTIONAL = this.LegDAO_.NOTIONAL;
                fp_cashFlow.DAO_.CALC_START_DT = roopDate.ToString("yyyyMMdd"); ;
                fp_cashFlow.DAO_.CALC_END_DT = nextDate.ToString("yyyyMMdd");
                fp_cashFlow.DAO_.PAYMENT_DT = cm.adjust(nextDate).ToString("yyyyMMdd");

                fp_cashFlow.DAO_.CASHFLOW_DT = fp_cashFlow.DAO_.PAYMENT_DT;

                fp_cashFlow.DAO_.FIXED_RATE = this.LegDAO_.FIXED_RATE;

                this.FP_CashFlowList_.Add(fp_cashFlow);

                roopDate = roopDate.AddMonths(legTenorMonth);
                nextDate = roopDate.AddMonths(legTenorMonth);
            }

        }
Example #4
0
        // 기존거 있으면 지움. 초기화임.
        public void build_position()
        {
            // 전일자 position date ?
            CalendarManager calendarM = new CalendarManager(this.ReferenceDate_, CalendarManager.CountryType.SOUTH_KOREA);
            DateTime preDate = calendarM.preBusinessDay(this.ReferenceDate_);

            clsHITM_FP_POSITION_TB clstb_position = new clsHITM_FP_POSITION_TB();
            clstb_position.POSITION_DT = this.ReferenceDate_.ToString("yyyyMMdd");
            clstb_position.DeleteDate();

            this.build_cashMaster();
            // ------------------------------------------------------------------------

            clsMAST_FP_INSTRUMENT_TB clstb_mast = new clsMAST_FP_INSTRUMENT_TB();

            DataTable dt = clstb_mast.Select();

            List<Financial_instrument> fi_list = new List<Financial_instrument>();

            // master 의 list 내에서 position을 만들음. // bookdate ? 감안해서 만듬?
            foreach (DataRow dr in dt.Select())
            {
                clsMAST_FP_INSTRUMENT_TB tb = clsMAST_FP_INSTRUMENT_TB.Create(dr);
                Financial_instrument fi = Financial_instrument.CreateInstrument(tb);
                fi_list.Add(fi);
            }

            foreach (Financial_instrument fi in fi_list)
            {
                // trading 할때에 같은 날짜는 나중에 더해서 만들어짐
                if (ConvertingTool.ToDateTime(fi.baseDAO_.BOOKED_DT).Date < this.ReferenceDate_.Date)
                { 
                    fi.build_position(preDate, this.ReferenceDate_);
                }
                
            }


        }
Example #5
0
        private void _buildRefDatePosition()
        {
            // if 이미 set이 되면 안함

            clsHITM_FP_POSITION_TB clstb = new clsHITM_FP_POSITION_TB();

            clstb.POSITION_DT = this.refDate_.ToString("yyyyMMdd");

            if ( clstb.Select().Rows.Count == 0 )
            {
                CalendarManager cm = new CalendarManager(this.refDate_, CalendarManager.CountryType.SOUTH_KOREA);

                DateTime roopDate = this.refDate_.AddDays(-1.0);

                while (!cm.isHoliday(roopDate))
                {
                    roopDate = roopDate.AddDays(-1.0);
                }

                this.HedgeTradingViewModel_.FinanceBook_.makePositionFromPreDate(roopDate,this.refDate_);

            }

        }
Example #6
0
        public QLNet.YieldTermStructure yieldCurve(CurveShift curveShift = null)
        {
            if (curveShift == null)
                curveShift = new ParallelCurveShift(0.0);

            QLNet.DayCounter dc = new QLNet.Actual365Fixed();

            List<Handle<Quote>> quotes = new List<Handle<Quote>>();
            List<double> datas = new List<double>();
            List<Date> dates = new List<Date>();

            CalendarManager cm = new CalendarManager(this.ReferenceDate_, CalendarManager.CountryType.SOUTH_KOREA);

            foreach (clsHDAT_CURVEDATA_TB tb in this.ResultCuveData_)
	        {
                DateTime dt = cm.adjust(this.ReferenceDate_,tb.TENOR);
                double? rate = tb.RATE + curveShift.shift(dt);

                dates.Add(dt);
                SimpleQuote quote = new SimpleQuote(rate);
                Handle<Quote> handleQuote = new Handle<Quote>(quote);

                quotes.Add(handleQuote);
                datas.Add(rate.Value);

	        }

            InterpolatedZeroCurve<ConvexMonotone>
                        yiels_ts = new InterpolatedZeroCurve<ConvexMonotone>(
                                                this.ReferenceDate_,
                                                dates,
                                                datas,
                                                dc,
                                                new ConvexMonotone(),
                                                Compounding.Compounded,
                                                Frequency.Annual);

            return yiels_ts;

        }
Example #7
0
        // code parsing or 어쩌구.
        public static Kospi200Index_futures CreateKOSPI200F(DateTime tradeDate,
                                                            string krxCode,
                                                            int quantity,
                                                            double tradeIndex)
        {
            // 장내 이므로 불러옴.
            clsTRADABLE_KRX_INDEXFUTURES_TB clstb = new clsTRADABLE_KRX_INDEXFUTURES_TB();

            clstb.INST_KRX_CD = krxCode;
            clstb.SelectOwn();

            Kospi200Index_futures inst = new Kospi200Index_futures();

            string inst_ID = IDGenerator.getNewInstrumentID(inst.InstrumentType_, tradeDate, inst);

            inst.baseDAO_.INSTRUMENT_ID = inst_ID;
            inst.baseDAO_.INSTRUMENT_NM = clstb.INST_NM;

            //inst.baseDAO_.FP_MASTER_TYP = Convert.ToInt32(inst.InstrumentType_); // 아직 구분 못했음. 우선 그냥 instType으로 넣음.

            inst.baseDAO_.FP_MASTER_TYP = IDGenerator.KRXCodetoFP_MASTER_TYP(krxCode);
            inst.baseDAO_.NOTIONAL = Convert.ToDouble(clstb.INDEX_MULTIPLIER);
            inst.baseDAO_.PRICE = tradeIndex;
            inst.baseDAO_.QUANTITY = quantity;
            inst.baseDAO_.CURR = "KRW";
            inst.baseDAO_.FX_RATE = 1.0;
            //inst.baseDAO_.NOTIONAL = Math.Abs(quantity * tradeIndex * clstb.INDEX_MULTIPLIER);
            //inst.baseDAO_.CURR = "KRW";

            //inst.baseDAO_.BUY_SELL = (quantity > 0) ? (int)clsMAST_FP_INSTRUMENT_TB.BUY_SELL_Type.Buy : 
            //                                          (int)clsMAST_FP_INSTRUMENT_TB.BUY_SELL_Type.Sell ;

            //inst.baseDAO_.QUANTITY = Math.Abs(quantity);

            inst.baseDAO_.EFFECTIVE_DT = tradeDate.ToString("yyyyMMdd");
            inst.baseDAO_.MATURITY_DT = clstb.MATURITY_DT;
            inst.baseDAO_.BOOKED_DT = tradeDate.ToString("yyyyMMdd");
            inst.baseDAO_.CLOSED_DT = "20991231";

            inst.indexFuturesDAO_.INSTRUMENT_ID = inst_ID;
            inst.indexFuturesDAO_.INSTRUMENT_TYP = Convert.ToInt32(inst.InstrumentType_); // 내부 타입인데..

            inst.indexFuturesDAO_.NOTIONAL = Math.Abs(quantity * tradeIndex * clstb.INDEX_MULTIPLIER);
            inst.indexFuturesDAO_.QUANTITY = quantity;
            inst.indexFuturesDAO_.INDEX_MULTIPLIER = clstb.INDEX_MULTIPLIER;
            inst.indexFuturesDAO_.UNDERLYING_INDEX_CD = clstb.UNDERLYING_CD;

            inst.indexFuturesDAO_.CURR = "KRW";
            inst.indexFuturesDAO_.EFFECTIVE_DT = tradeDate.ToString("yyyyMMdd");
            inst.indexFuturesDAO_.MATURITY_DT = clstb.MATURITY_DT;

            CalendarManager cm = new CalendarManager(tradeDate, CalendarManager.CountryType.SOUTH_KOREA);


            // CF
            FP_SimpleCashFlow fp_simple = new FP_SimpleCashFlow();
            fp_simple.DAO_ = new clsMAST_CF_SIMPLE_TB();

            DateTime maturityDate = ConvertingTool.ToDateTime(clstb.MATURITY_DT);

            fp_simple.DAO_.LEG_ID = inst_ID;
            fp_simple.DAO_.LEG_TYP = (int)clsMAST_SWAP_TB.LEG_TYP_Type.SIMPLE;
            fp_simple.DAO_.NOTIONAL = inst.indexFuturesDAO_.NOTIONAL;
            fp_simple.DAO_.AMOUNT = 0.0;

            fp_simple.DAO_.CALC_START_DT = tradeDate.ToString("yyyyMMdd");
            fp_simple.DAO_.CALC_END_DT = maturityDate.ToString("yyyyMMdd"); 
            fp_simple.DAO_.CASHFLOW_DT = maturityDate.ToString("yyyyMMdd");
            fp_simple.DAO_.PAY_RECEIVE = 1;
            fp_simple.DAO_.PAYMENT_DT = fp_simple.DAO_.CASHFLOW_DT;

            inst.FP_CashFlowList_.Add(fp_simple);

            return inst;

        }
Example #8
0
        public void calculatePL()
        {
            CalendarManager cm = new CalendarManager(this.ReferenceDateTime_, CalendarManager.CountryType.SOUTH_KOREA);

            clsHITM_FP_GREEKRESULT_TB clstb_result = new clsHITM_FP_GREEKRESULT_TB();

            clstb_result.CALC_DT = this.ReferenceDateTime_.ToString("yyyyMMdd");
            clstb_result.INSTRUMENT_ID = this.DAO_.INSTRUMENT_ID;
            clstb_result.SEQ = 1;

            int checkNum = clstb_result.SelectOwn();

            if (checkNum == 0) { throw new Exception("no exist"); }

            double calcPrice = clstb_result.CALC_PRICE;
            double quantity = this.DAO_.INSTRUMENT_QNT;

            clsMAST_FP_INSTRUMENT_TB clstb_master = new clsMAST_FP_INSTRUMENT_TB();

            //this.DAO_.ETC_PL = clstb_result.CALC_PRICE;

            this.DAO_.EVAL_AMT = Math.Round( calcPrice );
            this.DAO_.EVAL_PRICE = Math.Round( calcPrice / quantity );
            this.DAO_.EVAL_ACCOUNT_PL = Math.Round( this.DAO_.EVAL_AMT - this.DAO_.ACCOUNT_AMT ); // - 평가금액 - 장부금액
            //this.DAO_.TRADE_PROFIT = this.DAO_.TRADE_PROFIT + tradePosition.DAO_.TRADE_PROFIT; // 일별 매매수익
            //this.DAO_.TRADE_LOSS = tradePosition.DAO_.TRADE_LOSS;
            //this.DAO_.TRADE_TOTAL = tradePosition.DAO_.TRADE_TOTAL;
            //this.DAO_.TRANSACTION_FEE = tradePosition.DAO_.TRANSACTION_FEE;
            this.DAO_.ETC_PL = 0; // 데일리 기타 손익임.
            this.DAO_.TOTAL_ACCOUNT_PL = Math.Round( this.DAO_.EVAL_ACCOUNT_PL + this.DAO_.TRADE_TOTAL + this.DAO_.TRANSACTION_FEE );

            // 전일 포지션 
            DateTime preDate = cm.preBusinessDay(ConvertingTool.ToDateTime(this.ReferenceDateTime_.ToString("yyyyMMdd")));

            clsHITM_FP_POSITION_TB clstb_position = new clsHITM_FP_POSITION_TB();

            clstb_position.POSITION_DT = preDate.ToString("yyyyMMdd");
            clstb_position.INSTRUMENT_ID = this.DAO_.INSTRUMENT_ID;

            clstb_position.SelectOwn();

            // 전일자꺼가 여기 박혀서 옴..? 중간에 trade했을때
            this.DAO_.DAILY_EVAL_PL = Math.Round(this.DAO_.EVAL_AMT - clstb_position.EVAL_AMT ); // 전일 평가 - 당일 평가
            this.DAO_.DAILY_TOTAL_PL = Math.Round( this.DAO_.TRADE_TOTAL + this.DAO_.ETC_PL + this.DAO_.DAILY_EVAL_PL );

            // 여기서 부터 작업

            this.calculatePL_impl();

            if (this.DAO_.UpdateCalculatedPosition() == 0)
            { throw new Exception("update fail :" + this.DAO_.INSTRUMENT_ID + " " + this.DAO_.POSITION_DT); }
            else if (this.DAO_.UpdateCalculatedPosition() > 1)
            { throw new Exception("too many updated :" + this.DAO_.INSTRUMENT_ID + " " + this.DAO_.POSITION_DT); }
            else { }
        }
Example #9
0
        public static VanillaIRS_instrument CreateTradableCode(string availableTradeCD,
                                                               bool fixedPayFlag,
                                                               double notional,                                                   
                                                               int quantity,
                                                               DateTime effective,
                                                               double fixedRate,
                                                               double spread)
        {
            clsTRADABLE_OTC_VANILLA_IRS_TB clstb = new clsTRADABLE_OTC_VANILLA_IRS_TB();

            clstb.INST_CD = availableTradeCD;
            int checkNum = clstb.SelectOwn();

            if (checkNum == 0) { throw new Exception( availableTradeCD +  " : is not tradable."); }

            int maturityYear = ConvertingTool.TenorMuliplier(clstb.MATURITY_TENOR);
            int legTenorMonth = ConvertingTool.TenorMuliplier(clstb.LEG_TENOR);

            VanillaIRS_instrument inst = new VanillaIRS_instrument();

            int cashflowCount = maturityYear * (12 / legTenorMonth);

            // Master
            string inst_ID = IDGenerator.getNewInstrumentID(inst.InstrumentType_, effective,inst);

            inst.baseDAO_.INSTRUMENT_ID = inst_ID;
            inst.baseDAO_.INSTRUMENT_NM = (fixedPayFlag) ? fixedRate + " Pay " + clstb.MATURITY_TENOR : fixedRate + " Receive " + clstb.MATURITY_TENOR;
            inst.baseDAO_.FP_MASTER_TYP = (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.VanillaIRS;
            inst.baseDAO_.NOTIONAL = Math.Abs(notional);
            inst.baseDAO_.PRICE = fixedRate;
            inst.baseDAO_.QUANTITY = Math.Abs(quantity);
            inst.baseDAO_.CURR = "KRW";
            inst.baseDAO_.FX_RATE = 1.0;

            //inst.baseDAO_.BUY_SELL = (quantity > 0) ? (int)clsMAST_FP_INSTRUMENT_TB.BUY_SELL_Type.Buy :
            //                                          (int)clsMAST_FP_INSTRUMENT_TB.BUY_SELL_Type.Sell;

            inst.baseDAO_.EFFECTIVE_DT = effective.ToString("yyyyMMdd");
            inst.baseDAO_.MATURITY_DT = effective.AddYears(maturityYear).ToString("yyyyMMdd");
            inst.baseDAO_.BOOKED_DT = "";
            inst.baseDAO_.CLOSED_DT = "20991231";

            inst.SwapDAO_.INSTRUMENT_ID = inst_ID;
            inst.SwapDAO_.INSTRUMENT_TYP = Convert.ToInt32(inst.InstrumentType_);
            inst.SwapDAO_.NOTIONAL_PAY = Math.Abs(notional);
            inst.SwapDAO_.PAY_CURR = "KRW";
            inst.SwapDAO_.NOTIONAL_REC = Math.Abs(notional);
            inst.SwapDAO_.REC_CURR = "KRW";
            inst.SwapDAO_.EFFECTIVE_DT = effective.ToString("yyyyMMdd");
            inst.SwapDAO_.MATURITY_DT = effective.AddYears(maturityYear).ToString("yyyyMMdd");

            inst.SwapDAO_.PAY_LEG_TYP = 0;
            inst.SwapDAO_.PAY_LEG_TENOR = "3M";
            inst.SwapDAO_.PAY_LEG_BDC = 0;
            inst.SwapDAO_.PAY_LEG_DC = 0;

            inst.SwapDAO_.REC_LEG_TYP = 1;
            inst.SwapDAO_.REC_LEG_TENOR = "3M";
            inst.SwapDAO_.REC_LEG_BDC = 1;
            inst.SwapDAO_.REC_LEG_DC = 1;

            CalendarManager cm = new CalendarManager(effective, CalendarManager.CountryType.SOUTH_KOREA);

            // CF_FixedDAO_

            for (int i = 0; i < cashflowCount; i++)
            {
                FP_FixedRateCoupon fp_cashFlow = new FP_FixedRateCoupon();

                fp_cashFlow.DAO_ = new clsMAST_CF_FIXED_TB();

                fp_cashFlow.DAO_.CASHFLOW_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_cashFlow.DAO_.LEG_ID = inst_ID;
                fp_cashFlow.DAO_.LEG_TYP = 0;
                fp_cashFlow.DAO_.NOTIONAL = Math.Abs(notional); 
                fp_cashFlow.DAO_.CALC_START_DT = effective.AddMonths(3 * i).ToString("yyyyMMdd"); ;
                fp_cashFlow.DAO_.CALC_END_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_cashFlow.DAO_.PAYMENT_DT = cm.adjust(effective.AddMonths(3 * (i + 1))).ToString("yyyyMMdd");
                fp_cashFlow.DAO_.FIXED_RATE = fixedRate;

                if (fixedPayFlag) { inst.FP_PayCashFlowList_.Add(fp_cashFlow); }
                else { inst.FP_RecCashFlowList_.Add(fp_cashFlow); }
            }

            for (int i = 0; i < cashflowCount; i++)
            {
                FP_FloatingRateCoupon fp_floating_cashFlow = new FP_FloatingRateCoupon();

                fp_floating_cashFlow.DAO_ = new clsMAST_CF_VANILLA_FLOATING_TB();

                fp_floating_cashFlow.DAO_.CASHFLOW_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_floating_cashFlow.DAO_.LEG_ID = inst_ID;
                fp_floating_cashFlow.DAO_.LEG_TYP = 0;
                fp_floating_cashFlow.DAO_.NOTIONAL = Math.Abs(notional); 
                fp_floating_cashFlow.DAO_.CALC_START_DT = effective.AddMonths(3 * i).ToString("yyyyMMdd");
                fp_floating_cashFlow.DAO_.CALC_END_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_floating_cashFlow.DAO_.PAYMENT_DT = cm.adjust(effective.AddMonths(3 * (i + 1))).ToString("yyyyMMdd");

                fp_floating_cashFlow.DAO_.FIXING_DT = cm.adjust(effective.AddMonths(3 * i)).ToString("yyyyMMdd");

                // 우선 DEFAULT로 박고, FIXING은 차후 데일리로 계산함.

                fp_floating_cashFlow.DAO_.FIXING_INDEX_CD = clstb.FLOATING_INDEX_CD;
                fp_floating_cashFlow.DAO_.GREARING = 1.0;
                fp_floating_cashFlow.DAO_.SPREAD = spread;
                fp_floating_cashFlow.DAO_.FIXED_FIXING = 0.0;
                fp_floating_cashFlow.DAO_.FIXED_FIXING_CALCLATED 
                    = (int)clsMAST_CF_VANILLA_FLOATING_TB.FIXED_FIXING_CALCLATED_Type.NOT_FIXED;

                if (fixedPayFlag) { inst.FP_RecCashFlowList_.Add(fp_floating_cashFlow); }
                else { inst.FP_PayCashFlowList_.Add(fp_floating_cashFlow); }

            }

            return inst;
        }
Example #10
0
        //private void ql_FixedlegSet(List<FP_CashFlow> cashFlow, Leg leg, double notioal, DayCounter dc)
        //{
        //    double fixedRate = 0.0;

        //    for (int i = 0; i < cashFlow.Count; i++)
        //    {
        //        fixedRate = ((FP_FixedRateCoupon)cashFlow[i]).DAO_.FIXED_RATE;

        //        Date accrualStartDate = new Date(cashFlow[i].CalculationStartDate_.ToString("yyyyMMdd"), "yyyyMMdd");
        //        Date accrualEndDate = new Date(cashFlow[i].CalculationEndDate_.ToString("yyyyMMdd"), "yyyyMMdd");
        //        Date paymentDate = new Date(cashFlow[i].PaymentDate_.ToString("yyyyMMdd"), "yyyyMMdd"); 

        //        FixedRateCoupon fixedRateCoupon =
        //                new FixedRateCoupon(paymentDate,
        //                                    notioal,
        //                                    fixedRate,
        //                                    dc,
        //                                    accrualStartDate,
        //                                    accrualEndDate);

        //        leg.Add(fixedRateCoupon);
        //    }
        //}

        //private void ql_FloatinglegSet(List<FP_CashFlow> cashFlow, Leg leg, double notioal, YieldTermStructure indexCurve, DayCounter dc,QuantLib.Calendar calendar)
        //{
        //    Compounding forwardCompounding = Compounding.Compounded;

        //    Date evalDate = Settings.instance().getEvaluationDate();

        //    Console.WriteLine("year : " + evalDate.year());
        //    Console.WriteLine("month : " + evalDate.month());
        //    Console.WriteLine("day : " + evalDate.dayOfMonth());

        //    for (int i = 0; i < cashFlow.Count; i++)
        //    {
        //        // hard coding 함. 미친 코딩할 시간을 안줘. 호떡같은.. 
        //        //string periodStr = "3M"; // CD91 
                
        //        FP_FloatingRateCoupon fp_frc_i = (FP_FloatingRateCoupon)cashFlow[i] as FP_FloatingRateCoupon;

        //        Date accrualStartDate = new Date(cashFlow[i].CalculationStartDate_.ToString("yyyyMMdd"), "yyyyMMdd");
        //        Date accrualEndDate = new Date(cashFlow[i].CalculationEndDate_.ToString("yyyyMMdd"), "yyyyMMdd");
        //        Date paymentDate = new Date(cashFlow[i].PaymentDate_.ToString("yyyyMMdd"), "yyyyMMdd");

        //        double forwardRate = 0.0;
        //        int calculated = fp_frc_i.DAO_.FIXED_FIXING_CALCLATED;
        //        Date fixingDate = new Date(fp_frc_i.DAO_.FIXING_DT,"yyyyMMdd");

        //        if (fixingDate < evalDate || fixingDate == evalDate)
        //        {
        //            if (calculated == 1)
        //            {
        //                forwardRate = fp_frc_i.DAO_.FIXED_FIXING;
        //            }
        //            else
        //            {
        //                // 계산함
        //                clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB();

        //                clstb.INDEX_CD = fp_frc_i.DAO_.FIXING_INDEX_CD;
        //                clstb.REF_DT = fp_frc_i.DAO_.FIXING_DT;

        //                DataTable tb = clstb.Select();

        //                double fixed_fixing = 0.0;
        //                int uniqueSelectCheck = 0;

        //                foreach (DataRow dr in tb.Select())
        //                {
        //                    clsHDAT_MARKETDATA_TB resulttb = clsHDAT_MARKETDATA_TB.Create(dr);
        //                    fixed_fixing = resulttb.LAST;
        //                    uniqueSelectCheck += 1;

        //                }

        //                if (uniqueSelectCheck > 1)
        //                {
        //                    throw new Exception("market data is multiple: " + clstb.REF_DT + " " + clstb.INDEX_CD);
        //                }
        //                else if (uniqueSelectCheck == 0)
        //                {
        //                    throw new Exception("market data does not exist : " + clstb.REF_DT + " " + clstb.INDEX_CD);
        //                }

        //                // ID 랑 CASHFLOW는 SETTING이 이미 되어 있음. 

        //                fp_frc_i.DAO_.FIXED_FIXING_CALCLATED = 1;
        //                fp_frc_i.DAO_.FIXED_FIXING = fixed_fixing;

        //                fp_frc_i.DAO_.UpdateFixing();

        //                forwardRate = fixed_fixing;

        //                //((FP_FloatingRateCoupon)cashFlow[i]).DAO_.FIXED_FIXING = 

        //            }
        //        }
        //        else
        //        {
        //            forwardRate = indexCurve.forwardRate(fixingDate, 
        //                                                calendar.advance(fixingDate,3,TimeUnit.Months), 
        //                                                dc, 
        //                                                forwardCompounding).rate();
        //        }

        //        FixedRateCoupon floatingRateCoupon =
        //                new FixedRateCoupon(paymentDate,
        //                                    notioal,
        //                                    forwardRate,
        //                                    dc,
        //                                    accrualStartDate,
        //                                    accrualEndDate);

        //        leg.Add(floatingRateCoupon);
        //    }
        //}

        //  Vanilla maker 

        public static VanillaIRS_instrument CreateFixedFloating(bool fixedPayFlag,double notional,
            DateTime effective, int maturityYear, double fixedRate, bool fixedPaySide)
        {
            VanillaIRS_instrument inst = new VanillaIRS_instrument();

            int cashflowCount = maturityYear * (12 / 3);
            // Master
            string inst_ID = IDGenerator.getNewInstrumentID(inst.InstrumentType_, effective,inst);

            inst.baseDAO_.INSTRUMENT_ID = inst_ID;

            inst.baseDAO_.FP_MASTER_TYP = (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.VanillaIRS;
            inst.baseDAO_.NOTIONAL = notional;
            inst.baseDAO_.PRICE = fixedRate;
            inst.baseDAO_.QUANTITY = 1.0;
            inst.baseDAO_.CURR = "KRW";
            inst.baseDAO_.FX_RATE = 1.0;
            
            inst.baseDAO_.EFFECTIVE_DT = effective.ToString("yyyyMMdd");
            inst.baseDAO_.MATURITY_DT = effective.AddYears(maturityYear).ToString("yyyyMMdd");
            inst.baseDAO_.BOOKED_DT = "";
            inst.baseDAO_.CLOSED_DT = "20991231";

            inst.SwapDAO_.INSTRUMENT_ID = inst_ID;
            inst.SwapDAO_.INSTRUMENT_TYP = Convert.ToInt32(inst.InstrumentType_);
            inst.SwapDAO_.NOTIONAL_PAY = Math.Abs(notional);
		    inst.SwapDAO_.PAY_CURR = "KRW";
            inst.SwapDAO_.NOTIONAL_REC = Math.Abs(notional);
		    inst.SwapDAO_.REC_CURR = "KRW";
            inst.SwapDAO_.EFFECTIVE_DT = effective.ToString("yyyyMMdd");
            inst.SwapDAO_.MATURITY_DT = effective.AddYears(maturityYear).ToString("yyyyMMdd");

		    inst.SwapDAO_.PAY_LEG_TYP = 0;
		    inst.SwapDAO_.PAY_LEG_TENOR = "3M";
		    inst.SwapDAO_.PAY_LEG_BDC = 0;
		    inst.SwapDAO_.PAY_LEG_DC = 0;

		    inst.SwapDAO_.REC_LEG_TYP = 1;
		    inst.SwapDAO_.REC_LEG_TENOR = "3M";
		    inst.SwapDAO_.REC_LEG_BDC = 1;
		    inst.SwapDAO_.REC_LEG_DC = 1;

            CalendarManager cm = new CalendarManager(effective, CalendarManager.CountryType.SOUTH_KOREA);

            // CF_FixedDAO_

            for (int i = 0; i < cashflowCount; i++)
            {
                FP_FixedRateCoupon fp_cashFlow = new FP_FixedRateCoupon();

                fp_cashFlow.DAO_ = new clsMAST_CF_FIXED_TB();

                fp_cashFlow.DAO_.CASHFLOW_DT = effective.AddMonths(3*(i+1)).ToString("yyyyMMdd");
                fp_cashFlow.DAO_.LEG_ID = inst_ID;
                fp_cashFlow.DAO_.LEG_TYP = 2800;
                fp_cashFlow.DAO_.CALC_START_DT = effective.AddMonths(3 * i).ToString("yyyyMMdd"); ;
                fp_cashFlow.DAO_.CALC_END_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_cashFlow.DAO_.PAYMENT_DT = cm.adjust(effective.AddMonths(3 * (i + 1))).ToString("yyyyMMdd");
                fp_cashFlow.DAO_.FIXED_RATE = fixedRate;

                if (fixedPayFlag) {inst.FP_PayCashFlowList_.Add(fp_cashFlow); }
                else { inst.FP_RecCashFlowList_.Add(fp_cashFlow); }
            }

            for (int i = 0; i < cashflowCount; i++)
            {
                FP_FloatingRateCoupon fp_floating_cashFlow = new FP_FloatingRateCoupon();

                fp_floating_cashFlow.DAO_ = new clsMAST_CF_VANILLA_FLOATING_TB();

                fp_floating_cashFlow.DAO_.CASHFLOW_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_floating_cashFlow.DAO_.LEG_ID = inst_ID;
                fp_floating_cashFlow.DAO_.LEG_TYP = 0;
                fp_floating_cashFlow.DAO_.CALC_START_DT = effective.AddMonths(3 * i).ToString("yyyyMMdd");
                fp_floating_cashFlow.DAO_.CALC_END_DT = effective.AddMonths(3 * (i + 1)).ToString("yyyyMMdd");
                fp_floating_cashFlow.DAO_.PAYMENT_DT = cm.adjust(effective.AddMonths(3 * (i + 1))).ToString("yyyyMMdd");
                
                fp_floating_cashFlow.DAO_.FIXING_DT = cm.adjust(effective.AddMonths(3 * i)).ToString("yyyyMMdd");

                fp_floating_cashFlow.DAO_.FIXING_INDEX_CD = "CD91";
                fp_floating_cashFlow.DAO_.GREARING = 1.0;
                fp_floating_cashFlow.DAO_.SPREAD = 0.0;
                fp_floating_cashFlow.DAO_.FIXED_FIXING = 0.0;
                fp_floating_cashFlow.DAO_.FIXED_FIXING_CALCLATED = 0;

                if (fixedPayFlag) { inst.FP_RecCashFlowList_.Add(fp_floating_cashFlow); }
                else { inst.FP_PayCashFlowList_.Add(fp_floating_cashFlow); }

            }

            return inst;
        }
Example #11
0
        public void build_curveHistoryData(DateTime startDate, DateTime endDate,bool withClear)
        {
            CalendarManager cm = new CalendarManager(DateTime.Now, CalendarManager.CountryType.SOUTH_KOREA);

            clsHDAT_CURVEDATA_TB clstb = new clsHDAT_CURVEDATA_TB();

            CurveShift curveShift = new CurveShift();

            foreach (CurveDefInfo cdi in this.sampleCurve_)
            {
                clstb.CURVE_CD = cdi.Name_;

                if (withClear) 
                { 
                    clstb.DeleteIndex(); 

                    clstb.REF_DT = startDate.ToString("yyyyMMdd");

                    for (int i = 0; i < cdi.Tenor_.Count; i++)
                    {
                        clstb.TENOR = cdi.Tenor_[i];
                        clstb.TENOR_SEQ = i+1;
                        clstb.RATE_TYP = (int)clsHDAT_CURVEDATA_TB.RATE_TYP_Type.SWAP;
                        clstb.RATE = cdi.InitialCurve_[i];
                    }

                }

                clstb.Insert();

                DateTime roopDate = startDate;
                DateTime nextDate = cm.adjust(roopDate, "1D");

                while (nextDate < endDate)
                {
                    clstb.REF_DT = roopDate.ToString("yyyyMMdd");
                    nextDate = cm.adjust(roopDate, "1D");

                    this.curveData(cdi, curveShift, roopDate, nextDate);

                    roopDate = nextDate;
                }
            }        
        }
Example #12
0
        public void build_irHistoryData(DateTime startDate, DateTime endDate, bool withClear)
        {
            CalendarManager cm = new CalendarManager(DateTime.Now, CalendarManager.CountryType.SOUTH_KOREA);

            PseudoRandom random = new PseudoRandom();
            //RandomSequenceGenerator<MersenneTwisterUniformRng> randGen = random.make_sequence_generator(1000, 1) as RandomSequenceGenerator<MersenneTwisterUniformRng>;
            int genNum = Convert.ToInt32((endDate - startDate).TotalDays) * this.sampleIR_.Count;

            IRNG randGen = random.make_sequence_generator(genNum, Convert.ToUInt64(this.random_.Next())) as IRNG;

            int i = 0;
            Sample<List<double>> sample = randGen.nextSequence();

            clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB();

            foreach (VasicekParameter para in this.sampleIR_)
            {
                SquareRootProcess vasicek = new SquareRootProcess(para.LongTermRate_, para.Speed_, para.Vol_ , para.Initial_);

                clstb.INDEX_CD = para.Name_;

                if (withClear) 
                { 
                    clstb.DeleteIndex(); 

                    clstb.REF_DT = startDate.ToString("yyyyMMdd");

                    clstb.LAST = para.Initial_;
                    clstb.LOW = para.Initial_;
                    clstb.HIGH = para.Initial_;

                    clstb.Insert();
                }

                DateTime roopDate = startDate;
                DateTime nextDate = cm.adjust(roopDate, "1D");

                while (nextDate < endDate)
                {
                    clstb.REF_DT = roopDate.ToString("yyyyMMdd");
                    
                    nextDate = cm.adjust(roopDate, "1D");

                    this.irData(para.Name_, vasicek, sample.value[i], roopDate, nextDate);
                    
                    roopDate = nextDate;

                    i += 1;
                }

            }

        }
Example #13
0
        private void _pl_closingEnable_Initialize()
        {
            CalendarManager cm = new CalendarManager(this.refDate_, CalendarManager.CountryType.SOUTH_KOREA);
            DateTime nextDate = cm.adjust(this.refDate_);

            this.monthEndClosingBtn.Enabled = false;
            this.yearEndClosingBtn.Enabled = false;

            if ((nextDate.Month - this.refDate_.Month) == 1)
            {
                this.monthEndClosingBtn.Enabled = true;
            }

            if ((nextDate.Year - this.refDate_.Year) == 1)
            {
                this.monthEndClosingBtn.Enabled = true;
                this.yearEndClosingBtn.Enabled = true;
            }
        }