public override void loadLegInfo(string inst_id) { // leg info this.LegDAO_.INSTRUMENT_ID = inst_id; if (this.LegDAO_.SelectOwn() == 0) { throw new Exception("data not exist"); } // cash flow this.FP_CashFlowList_.Clear(); clsMAST_CF_VANILLA_FLOATING_TB clstb_vanilla_cf = new clsMAST_CF_VANILLA_FLOATING_TB(); clstb_vanilla_cf.LEG_ID = inst_id; DataTable resultTb = clstb_vanilla_cf.Select(); foreach (DataRow dr in resultTb.Select()) { FP_FloatingRateCoupon fp_floating = new FP_FloatingRateCoupon(); fp_floating.DAO_ = clsMAST_CF_VANILLA_FLOATING_TB.Create(dr); fp_floating.Notional_ = fp_floating.DAO_.NOTIONAL; fp_floating.CalculationStartDate_ = ConvertingTool.ToDateTime(fp_floating.DAO_.CALC_START_DT); fp_floating.CalculationEndDate_ = ConvertingTool.ToDateTime(fp_floating.DAO_.CALC_END_DT); fp_floating.PaymentDate_ = ConvertingTool.ToDateTime(fp_floating.DAO_.PAYMENT_DT); this.FP_CashFlowList_.Add(fp_floating); } }
private void load_fp_vanillaFloating() { clsMAST_CF_VANILLA_FLOATING_TB clstb = new clsMAST_CF_VANILLA_FLOATING_TB(); DataTable dt = clstb.Select(); foreach (DataRow dr in dt.Select()) { FP_FloatingRateCoupon fp_fixed = new FP_FloatingRateCoupon() { DAO_ = clsMAST_CF_VANILLA_FLOATING_TB.Create(dr) }; this.FP_CashFlowList_.Add(fp_fixed); } }
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); } }
private void cashflow(string legID,int type,List<FP_CashFlow> fp_cfList) { CultureInfo us = new CultureInfo("en-US"); if (type == 0) { clsMAST_CF_FIXED_TB tb = new clsMAST_CF_FIXED_TB(); tb.LEG_ID = legID; DataTable resultTb = tb.Select(); foreach ( DataRow dr in resultTb.Select() ) { FP_FixedRateCoupon fp_fixed = new FP_FixedRateCoupon(); fp_fixed.DAO_ = clsMAST_CF_FIXED_TB.Create(dr); fp_fixed.Notional_ = fp_fixed.DAO_.NOTIONAL; fp_fixed.CalculationStartDate_ = DateTime.ParseExact(fp_fixed.DAO_.CALC_START_DT,"yyyyMMdd",us); fp_fixed.CalculationEndDate_ = DateTime.ParseExact(fp_fixed.DAO_.CALC_END_DT, "yyyyMMdd", us); fp_fixed.PaymentDate_ = DateTime.ParseExact(fp_fixed.DAO_.PAYMENT_DT, "yyyyMMdd", us); fp_cfList.Add(fp_fixed); } } else if (type == 1) { clsMAST_CF_VANILLA_FLOATING_TB tb = new clsMAST_CF_VANILLA_FLOATING_TB(); tb.LEG_ID = legID; DataTable resultTb = tb.Select(); foreach (DataRow dr in resultTb.Select()) { FP_FloatingRateCoupon fp_floating = new FP_FloatingRateCoupon(); fp_floating.DAO_ = clsMAST_CF_VANILLA_FLOATING_TB.Create(dr); fp_floating.Notional_ = fp_floating.DAO_.NOTIONAL; fp_floating.CalculationStartDate_ = DateTime.ParseExact(fp_floating.DAO_.CALC_START_DT, "yyyyMMdd", us); fp_floating.CalculationEndDate_ = DateTime.ParseExact(fp_floating.DAO_.CALC_END_DT, "yyyyMMdd", us); fp_floating.PaymentDate_ = DateTime.ParseExact(fp_floating.DAO_.PAYMENT_DT, "yyyyMMdd", us); fp_cfList.Add(fp_floating); } this.FixingIndexCD_ = ((FP_FloatingRateCoupon)fp_cfList[0]).DAO_.FIXING_INDEX_CD; } else { } }
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; }
//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; }