public void read_instrument(VanillaIRS_instrument inst)
        {
            this.masterTabItem_.DataContext = inst;
            this.payLegCashFlowDataGrid_.ItemsSource = inst.FP_PayCashFlowList_;
            this.receiveLegCashFlowDataGrid_.ItemsSource = inst.FP_RecCashFlowList_;


        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            VanillaIRS_instrument inst = new VanillaIRS_instrument();

            inst.loadFPMaster("KRS1A7002789");
            inst.loadDetail("KRS1A7002789");

            this.read_instrument(inst);


        }
Exemplo n.º 3
0
        public void loadInstrument()
        {
            this.Financial_instrumentList_.Clear();

            clsMAST_SWAP_TB swap_tb = new clsMAST_SWAP_TB();
            DataTable dt = swap_tb.Select();

            foreach (DataRow dr in dt.Select())
            {
                VanillaIRS_instrument v_irs_inst = new VanillaIRS_instrument();
                v_irs_inst.SwapDAO_ = clsMAST_SWAP_TB.Create(dr);
                v_irs_inst.loadCashflow();

                this.Financial_instrumentList_.Add(v_irs_inst);
            }
        }
Exemplo n.º 4
0
        // #CreateInstrument_ItemAdd
        public static Financial_instrument CreateInstrument(clsMAST_FP_INSTRUMENT_TB tb)
        {
            int type = tb.FP_MASTER_TYP;

            Financial_instrument fi = new Unknown_fi_instrument();

            if (type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.Kospi200_IndexFutures)
            {
                fi = new Kospi200Index_futures();
            }
            else if (type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.Kospi200_IndexOption_Call 
                || type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.Kospi200_IndexOption_Put)
            {
                fi = new Kospi200Index_option();
            }
            else if (type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.VanillaIRS)
            {
                fi = new VanillaIRS_instrument();
            }
            else if (type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.VanillaSwap)
            {
                fi = new Vanilla_Swap();
            }
            else if (type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.Ftp_DepositLoan)
            {
                fi = new Ftp_DepositLoan();
            }
            else if (type == (int)clsMAST_FP_INSTRUMENT_TB.FP_MASTER_TYP_Type.Money_Cash)
            {
                fi = new CurrencyCash();
            }

            else
            {
                //fi = new Unknown_instrument();
            }

            fi.baseDAO_ = tb;
            fi.loadDetail(tb.INSTRUMENT_ID);

            return fi;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }