public override QLNet.CashFlow build_ql_cf(FP_Parameter fp_parameter) { double amount = this.DAO_.AMOUNT; QLNet.Date paymentDate = this.PaymentDate_; QLNet.CashFlow ql_cf = new QLNet.SimpleCashFlow(amount,paymentDate); return ql_cf; }
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // market data load //clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); //clstb.REF_DT = calcDateStr; //clstb.INDEX_CD = this.DAO_.INDEX_CD; //int checkNum = clstb.SelectOwn(); //if (checkNum == 0) { throw new Exception("market data does not exist : " + calcDateStr + " " + clstb.INDEX_CD); } //double indexData = clstb.LAST; // calculate // position clsHITM_FP_POSITION_TB position_tb = new clsHITM_FP_POSITION_TB(); position_tb.INSTRUMENT_ID = this.baseDAO_.INSTRUMENT_ID; position_tb.POSITION_DT = calcDateStr; if (position_tb.SelectOwn() == 0) { throw new Exception("position load fail : " + calcDateStr + " " + position_tb.INSTRUMENT_ID); } double accountIndex = position_tb.ACCOUNT_INDEX; clsHITM_FP_GREEKRESULT_TB result_tb = new clsHITM_FP_GREEKRESULT_TB(); result_tb.CALC_DT = calcDateStr; // price result_tb.INSTRUMENT_ID = this.baseDAO_.INSTRUMENT_ID; result_tb.UNDERLYING_ID = "FTP"; result_tb.UNDERLYING_VALUE = this.DAO_.INDEX_RATE; // DateTime maturity = ConvertingTool.ToDateTime("21991231"); double t = (maturity - calcDate).TotalDays / 365; result_tb.DELTA = 0.0; result_tb.CALC_PRICE = this.DAO_.NOTIONAL; result_tb.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; result_tb.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); ; result_tb.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; result_tb.UpdateDateResult(); // delta // gamma and others : no exist ? }
public void batch_calculate() { // if empty result가 없으면 만듬. //this.build_calculation(); // load 함 ------------------------------------------------------------------ clsMAST_FP_INSTRUMENT_TB clstb_mast = new clsMAST_FP_INSTRUMENT_TB(); DataTable dt = clstb_mast.SelectAliveInstruments(this.ReferenceDate_); List<Financial_instrument> fi_list = new List<Financial_instrument>(); 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); } // 파라메터 아직 디폴트 --------------------------------------------- FP_Parameter fp_parameter = new FP_Parameter(); fp_parameter.CalcDate_ = this.ReferenceDate_; fp_parameter.defaultLoad(); // ------------------------------------------------------------------ foreach (Financial_instrument roop_fi in fi_list) { // 내부에서 cash_flow까지 같이 돌음. roop_fi.delete_result(this.ReferenceDate_,roop_fi.baseDAO_.INSTRUMENT_ID); roop_fi.calculate(this.ReferenceDate_, fp_parameter); } //try //{ //} //catch (Exception e) //{ // this.LogManager_.addLog(e.Message); //} // ------------------------------------------------------------------ //clstb.END_TIME = DateTime.Now.ToString("HHmmdd"); //clstb.STATUS = (int)clsHDAT_BATCHJOB_RESULT_TB.STATUS_Type.CALCULATED; //clstb.Update(); }
public override QLNet.CashFlow build_ql_cf(FP_Parameter fp_parameter) { double notional = this.DAO_.NOTIONAL; QLNet.Date paymentDate = this.PaymentDate_; string index_cd = this.DAO_.FIXING_INDEX_CD; QLNet.DayCounter dayCounter = new QLNet.Actual365Fixed(); QLNet.YieldTermStructure ql_yield_ts = fp_parameter.getEvaluationCurve(index_cd); QLNet.Date accrualStartDate = this.CalculationStartDate_; QLNet.Date accrualEndDate = this.CalculationEndDate_; double forwardRate = 0.0; DateTime fixingDate = ConvertingTool.ToDateTime(this.DAO_.FIXING_DT); if (fp_parameter.CalcDate_ >= fixingDate) { if (this.DAO_.FIXED_FIXING_CALCLATED == (int)clsMAST_CF_VANILLA_FLOATING_TB.FIXED_FIXING_CALCLATED_Type.NOT_FIXED) { this.fixing_calulate(fp_parameter.CalcDate_); } // 계산함. forwardRate = this.DAO_.FIXED_FIXING; } else { forwardRate = ql_yield_ts.forwardRate(accrualStartDate, accrualEndDate, dayCounter, QLNet.Compounding.Compounded).rate(); } QLNet.CashFlow ql_cf = new QLNet.FixedRateCoupon( notional, paymentDate, forwardRate, dayCounter, accrualStartDate, accrualEndDate); return ql_cf; }
// ql_net calculation interface public override QLNet.CashFlow build_ql_cf(FP_Parameter fp_parameter) { double notional = this.DAO_.NOTIONAL; QLNet.Date paymentDate = this.PaymentDate_; double rate = this.DAO_.FIXED_RATE; QLNet.DayCounter dayCounter = new QLNet.Actual365Fixed(); QLNet.Date accrualStartDate = this.CalculationStartDate_; QLNet.Date accrualEndDate = this.CalculationEndDate_; QLNet.CashFlow ql_cf = new QLNet.FixedRateCoupon( notional, paymentDate, rate, dayCounter, accrualStartDate, accrualEndDate); return ql_cf; }
public abstract void calculate(DateTime calcDate,FP_Parameter fp_parameter);
// single calculation -- 이거는 그냥 엎어치는 용 -- 전체 batch result를 update하지 않음. public void calculation(Financial_instrument fi) { try { // 파라메터 아직 디폴트 --------------------------------------------- FP_Parameter fp_parameter = new FP_Parameter(); fp_parameter.CalcDate_ = this.ReferenceDate_; fp_parameter.defaultLoad(); // ------------------------------------------------------------------ //fi.loadDetail(); fi.calculate(this.ReferenceDate_, fp_parameter); //fi.calculate(this.ReferenceDate_); } catch (Exception e) { //sb.AppendLine(e.Message); LogManager_.addLog(e.Message); } }
public override void calculate(DateTime calcDate,FP_Parameter fp_parameter) { // market data load clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); clstb.REF_DT = calcDateStr; clstb.INDEX_CD = this.indexFuturesDAO_.UNDERLYING_INDEX_CD; int checkNum = clstb.SelectOwn(); if (checkNum == 0) { throw new Exception("market data does not exist : " + calcDateStr + " " + clstb.INDEX_CD); } double indexData = clstb.LAST; // calculate // position clsHITM_FP_POSITION_TB position_tb = new clsHITM_FP_POSITION_TB(); position_tb.INSTRUMENT_ID = this.baseDAO_.INSTRUMENT_ID; position_tb.POSITION_DT = calcDateStr; if (position_tb.SelectOwn() == 0) { throw new Exception("position load fail : " + calcDateStr + " " + position_tb.INSTRUMENT_ID); } double accountIndex = position_tb.ACCOUNT_INDEX; clsHITM_FP_GREEKRESULT_TB result_tb = new clsHITM_FP_GREEKRESULT_TB(); result_tb.CALC_DT = calcDateStr; // price result_tb.INSTRUMENT_ID = this.baseDAO_.INSTRUMENT_ID; result_tb.UNDERLYING_ID = this.indexFuturesDAO_.UNDERLYING_INDEX_CD; result_tb.UNDERLYING_VALUE = indexData; // DateTime maturity = ConvertingTool.ToDateTime(this.indexFuturesDAO_.MATURITY_DT); double t = (maturity - calcDate).TotalDays / 365; result_tb.DELTA = Math.Round(this.indexFuturesDAO_.QUANTITY * indexData * this.indexFuturesDAO_.INDEX_MULTIPLIER * Math.Exp(0.03 * t)); result_tb.CALC_PRICE = Math.Round( this.indexFuturesDAO_.QUANTITY * ( indexData - accountIndex ) * this.indexFuturesDAO_.INDEX_MULTIPLIER ); result_tb.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; result_tb.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); ; result_tb.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; //result_tb.UpdateDateResult(); result_tb.Insert(); // delta // gamma and others : no exist ? }
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { throw new NotImplementedException(); }
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // 돌릴거에 대한 List를 가져옴. List<ScenarioInfo> scenarioInfoList = new List<ScenarioInfo>(); List<double> scenarioCalcList = new List<double>(); clsSET_SCENARIO_TB clstb_scenario = new clsSET_SCENARIO_TB(); // 이걸로 할건지 아니면 세부 swap 으로 할건지 clstb_scenario.FP_MASTER_TYP = this.baseDAO_.FP_MASTER_TYP; DataTable dt = clstb_scenario.Select(); foreach ( DataRow dr in dt.Select() ) { scenarioInfoList.Add(new ScenarioInfo() { DAO_ = clsSET_SCENARIO_TB.Create(dr) }); } foreach (ScenarioInfo sc_info in scenarioInfoList) { fp_parameter.ScenarioInfo_ = sc_info; //fp_parameter.CurveShift_ = new ParallelCurveShift(0.0); double v = this.calculateImpl(calcDate, fp_parameter); sc_info.CalcPrice_ = v; scenarioCalcList.Add(v); } fp_parameter.ScenarioInfo_ = ScenarioInfo.BaseParallelShift(); double value_up = this.calculateImpl(calcDate, fp_parameter); fp_parameter.ScenarioInfo_ = ScenarioInfo.NullScenario(); double value = this.calculateImpl(calcDate, fp_parameter); clsHITM_FP_GREEKRESULT_TB clstb_greekresult = new clsHITM_FP_GREEKRESULT_TB(); clsHDAT_MARKETDATA_TB clstb_market = new clsHDAT_MARKETDATA_TB(); clstb_market.REF_DT = calcDate.ToString("yyyyMMdd"); clstb_market.INDEX_CD = "CD91"; if (clstb_market.SelectOwn() == 0) { throw new Exception("market data does not exist : " + clstb_market.REF_DT + " " + clstb_market.INDEX_CD); } clstb_greekresult.CALC_DT = calcDate.ToString("yyyyMMdd"); clstb_greekresult.INSTRUMENT_ID = this.SwapDAO_.INSTRUMENT_ID; //clstb_greekresult.FP_GREEKRESULT_ID = ""; //clstb_greekresult.INSTRUMENT_TYP = 0; clstb_greekresult.UNDERLYING_ID = clstb_market.INDEX_CD; clstb_greekresult.UNDERLYING_VALUE = clstb_market.LAST; //clstb_greekresult.SEQ = 1; clstb_greekresult.DELTA = value_up - value; clstb_greekresult.GAMMA = 0.0; clstb_greekresult.VEGA = 0.0; clstb_greekresult.CALC_PRICE = value; clstb_greekresult.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; clstb_greekresult.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); clstb_greekresult.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; // 패러럴 쉬푸투 or 그냥 구한거 머 등등.. clstb_greekresult.UpdateDateResult(); foreach (ScenarioInfo sc_info in scenarioInfoList) { //clstb_greekresult.FP_GREEKRESULT_ID = ""; //clstb_greekresult.INSTRUMENT_TYP = 0; //clstb_greekresult.UNDERLYING_ID = clstb_market.INDEX_CD; clstb_greekresult.UNDERLYING_ID = sc_info.ScenarioCode_; clstb_greekresult.UNDERLYING_VALUE = clstb_market.LAST; //clstb_greekresult.SEQ = 1; clstb_greekresult.DELTA = sc_info.CalcPrice_ - value; clstb_greekresult.GAMMA = 0.0; clstb_greekresult.VEGA = 0.0; // 시나리오의 경우 시나리오 value를 넣음. clstb_greekresult.CALC_PRICE = sc_info.CalcPrice_; clstb_greekresult.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; clstb_greekresult.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); clstb_greekresult.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; // 패러럴 쉬푸투 or 그냥 구한거 머 등등.. //clstb_greekresult.Insert(); clstb_greekresult.UpdateDateResult(); } #region CashFlow // db 지우는 거? int fixedPayRec = this.SwapDAO_.PAY_REC; int floatingPayRec = fixedPayRec * (-1); for (int i = 0; i < this.FixedLegInfo_.FP_CashFlowList_.Count; i++) { this.FixedLegInfo_.FP_CashFlowList_[i].cf_insert(calcDate, i + 1, this.SwapDAO_.INSTRUMENT_ID, this.SwapDAO_.INSTRUMENT_TYP, fixedPayRec); } for (int j = 0; j < this.FloatingLegInfo_.FP_CashFlowList_.Count; j++) { this.FloatingLegInfo_.FP_CashFlowList_[j].cf_insert(calcDate, j + 1, this.SwapDAO_.INSTRUMENT_ID, this.SwapDAO_.INSTRUMENT_TYP, floatingPayRec); } #endregion }
public double calculateImpl(DateTime calcDate, FP_Parameter fp_parameter) { List<QLNet.CashFlow> ql_fixedCFList = new List<QLNet.CashFlow>(); List<QLNet.CashFlow> ql_floatingCFList = new List<QLNet.CashFlow>(); foreach (FP_CashFlow fixed_cf in this.FixedLegInfo_.FP_CashFlowList_) { ql_fixedCFList.Add(fixed_cf.build_ql_cf(fp_parameter)); } foreach (FP_CashFlow floating_cf in this.FloatingLegInfo_.FP_CashFlowList_) { ql_floatingCFList.Add(floating_cf.build_ql_cf(fp_parameter)); } Swap ql_swap = new Swap(ql_fixedCFList, ql_floatingCFList); //QLNet.DiscountingBasisSwapEngine Handle<YieldTermStructure> ql_discount_ts //= new QLNet.Handle<YieldTermStructure>(fp_parameter.DiscountCurveMap_["KRW"]); = new QLNet.Handle<YieldTermStructure>(fp_parameter.getDiscountCurve("KRW")); QLNet.DiscountingSwapEngine engine = new DiscountingSwapEngine(ql_discount_ts); ql_swap.setPricingEngine(engine); #region Result Price/Greek //clsHITM_FP_GREEKRESULT_TB clstb_greekresult = new clsHITM_FP_GREEKRESULT_TB(); //clsHDAT_MARKETDATA_TB clstb_market = new clsHDAT_MARKETDATA_TB(); //clstb_market.REF_DT = calcDate.ToString("yyyyMMdd"); double swap_price = ql_swap.NPV(); #region Comment //foreach (var item in index_cdList) //{ // clstb_market.INDEX_CD = item; // clstb_market.SelectOwn(); // clstb_greekresult.FP_GREEKRESULT_ID = ""; // clstb_greekresult.CALC_DT = calcDate.ToString("yyyyMMdd"); // clstb_greekresult.INSTRUMENT_ID = this.SwapDAO_.INSTRUMENT_ID; // clstb_greekresult.INSTRUMENT_TYP = 0; // clstb_greekresult.UNDERLYING_ID = item; // clstb_greekresult.UNDERLYING_VALUE = clstb_market.LAST; // clstb_greekresult.SEQ = count; // clstb_greekresult.DELTA = 0.0; // clstb_greekresult.GAMMA = 0.0; // clstb_greekresult.VEGA = 0.0; // if (count == 1) { clstb_greekresult.CALC_PRICE = swap_price; } // else { clstb_greekresult.CALC_PRICE = 0.0; } // clstb_greekresult.CALCULATED_FLAG = 1; // clstb_greekresult.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); // clstb_greekresult.CALCULATE_TYP = 1; // 패러럴 쉬푸투 or 그냥 구한거 머 등등.. // clstb_greekresult.Insert(); // count += 1; //} #endregion #endregion for (int i = 0; i < this.FixedLegInfo_.FP_CashFlowList_.Count; i++) { this.FixedLegInfo_.FP_CashFlowList_[i].CashFlowAmount_ = ql_fixedCFList[i].amount(); this.FixedLegInfo_.FP_CashFlowList_[i].DiscountFactor_ = ql_discount_ts.currentLink().discount(this.FixedLegInfo_.FP_CashFlowList_[i].PaymentDate_); } for (int j = 0; j < this.FloatingLegInfo_.FP_CashFlowList_.Count; j++) { this.FloatingLegInfo_.FP_CashFlowList_[j].CashFlowAmount_ = ql_floatingCFList[j].amount(); this.FloatingLegInfo_.FP_CashFlowList_[j].DiscountFactor_ = ql_discount_ts.currentLink().discount(this.FloatingLegInfo_.FP_CashFlowList_[j].PaymentDate_); } return swap_price; //#endregion }
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // master data load this.indexOptionDAO_.SelectOwn(); // market data load // index data clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); QLNet.Settings.setEvaluationDate(calcDate); clstb.REF_DT = calcDateStr; clstb.INDEX_CD = this.indexOptionDAO_.UNDERLYING_INDEX_CD; int checkNum = clstb.SelectOwn(); if (checkNum == 0) { throw new Exception("market data does not exist : " + calcDateStr + " " + clstb.INDEX_CD); } double indexData = clstb.LAST; // curveData -------------------------------------------------- string curve_cd = "IRSKRW"; YieldCurve curveManager = new YieldCurve(); curveManager.loadCurveData(calcDate,curve_cd,clsHDAT_CURVEDATA_TB.RATE_TYP_Type.YTM); QLNet.YieldTermStructure yield_ts = curveManager.yieldCurve(); // calculate string maturityDateStr = this.indexOptionDAO_.MATURITY_DT; System.Globalization.CultureInfo us = new System.Globalization.CultureInfo("en-US"); DateTime maturityDate = DateTime.ParseExact(maturityDateStr, "yyyyMMdd", us); DayCounter dc = new Actual365Fixed(); Calendar cal = new NullCalendar(); double vol = 0.3; double strike = this.indexOptionDAO_.STRIKE; PlainVanillaPayoff strikePayoff = new PlainVanillaPayoff(Option.Type. Call, strike); Exercise exercise = new EuropeanExercise(maturityDate); VanillaOption q_option = new VanillaOption(strikePayoff,exercise); Handle<Quote> x0 = new Handle<Quote>(new SimpleQuote(indexData)); FlatForward flatForward = new FlatForward(calcDate,0.01,dc); Handle<YieldTermStructure> dividendTS = new Handle<YieldTermStructure>(flatForward); Handle<YieldTermStructure> riskFreeTS = new Handle<YieldTermStructure>(yield_ts); BlackConstantVol blackConstVol = new BlackConstantVol(calcDate,cal,vol,dc); Handle<BlackVolTermStructure> blackVolTS = new Handle<BlackVolTermStructure>(blackConstVol); GeneralizedBlackScholesProcess process =new GeneralizedBlackScholesProcess(x0 ,dividendTS,riskFreeTS,blackVolTS); AnalyticEuropeanEngine europeanEngine = new AnalyticEuropeanEngine(process); q_option.setPricingEngine(europeanEngine); double value = q_option.NPV(); double indexMultiplier = this.indexOptionDAO_.INDEX_MULTIPLIER; int quantity = this.indexOptionDAO_.QUANTITY; clsHITM_FP_GREEKRESULT_TB result_tb = new clsHITM_FP_GREEKRESULT_TB(); result_tb.FP_GREEKRESULT_ID = IDGenerator.getNewGreekResultID(this.indexOptionDAO_.INSTRUMENT_ID,calcDateStr); result_tb.CALC_DT = calcDateStr; result_tb.INSTRUMENT_ID = this.indexOptionDAO_.INSTRUMENT_ID; result_tb.INSTRUMENT_TYP = this.indexOptionDAO_.INSTRUMENT_TYP; result_tb.UNDERLYING_ID = "KOSPI200"; result_tb.UNDERLYING_VALUE = indexData; //result_tb.SEQ = 1; result_tb.DELTA = (q_option.delta() * indexData / 100) * indexMultiplier * quantity; // 1% Delta result_tb.GAMMA = 0.5 * (q_option.gamma() * indexData / 100) * indexMultiplier * quantity; // 1% Gamma result_tb.VEGA = q_option.vega() / 100 * indexMultiplier * quantity; // 1% point Vega result_tb.CALC_PRICE = value * indexMultiplier * quantity; result_tb.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; result_tb.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); ; result_tb.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; // price if (result_tb.UpdateDateResult() == 0) { throw new Exception("update result fail. no exist , calcDate : " + calcDate.ToString("yyyyMMdd") + " , inst_id : " + result_tb.INSTRUMENT_ID); } // delta // gamma and others : no exist ? }
//public override void calculate(DateTime calcDate) //{ // //try // //{ // // this.marketDataCheck(calcDate); // //} // //catch (Exception e) // //{ // // Console.WriteLine(e.Message); // // return; // //} // //double pay_notional = this.SwapDAO_.NOTIONAL_PAY; // //double rec_notional = this.SwapDAO_.NOTIONAL_REC; // //Date ql_calcDate = new Date(calcDate.ToString("yyyyMMdd"), "yyyyMMdd"); // //QuantLib.Settings.instance(). setEvaluationDate(ql_calcDate); // ////Date evalDate = Settings.instance().getEvaluationDate(); // ////Console.WriteLine("year : " + evalDate.year()); // ////Console.WriteLine("month : " + evalDate.month()); // ////Console.WriteLine("day : " + evalDate.dayOfMonth()); // //Date effectiveDate = new Date(this.SwapDAO_.EFFECTIVE_DT, "yyyyMMdd"); // //Date maturityDate = new Date(this.SwapDAO_.MATURITY_DT, "yyyyMMdd"); // //DayCounter dc = new Actual365Fixed(); // //CurveManager cm = new CurveManager(); // //QuantLib.Calendar calendar = new QuantLib.SouthKorea(); // //// --------------------------------------- // //List<int> regTypeIDs = new List<int>() { this.SwapDAO_.PAY_LEG_TYP, this.SwapDAO_.REC_LEG_TYP }; // //List<Leg> legs = new List<Leg>(); // //for (int i = 0; i < 2; i++) // //{ // // int legID = regTypeIDs[i]; // // Leg ql_leg = new Leg(); // // if (legID == 0) // // { // // this.ql_FixedlegSet(this.FP_PayCashFlowList_, ql_leg, pay_notional, dc); // // } // // else // // { // // string curveID = cm.indexCurveMapping(this.FixingIndexCD_); // // cm.loadCurveData(calcDate, curveID); // // YieldTermStructure indexCurve = cm.yieldCurve(); // // this.ql_FloatinglegSet(this.FP_RecCashFlowList_, ql_leg, rec_notional, indexCurve, dc, calendar); // // //indexCurve.Dispose(); // // } // // legs.Add(ql_leg); // //} // //Swap swap = new Swap(legs[0], legs[1]); // //cm.loadDiscountCurveData(calcDate, SwapDAO_.PAY_CURR); // //YieldTermStructure discountCurve = cm.yieldCurve(); // //YieldTermStructureHandle ysh = new YieldTermStructureHandle(discountCurve); // //DiscountingSwapEngine dse = new DiscountingSwapEngine(ysh); // //swap.setPricingEngine(dse); // //double npv = swap.NPV(); // //Console.WriteLine("NPV : " + npv ); // ////discountCurve.Dispose(); // ////ysh.Dispose(); // //// 평가함. // //// db 에 박음. // //// price // //clsHITM_FP_GREEKRESULT_TB clstb = new clsHITM_FP_GREEKRESULT_TB(); // //clstb.CALC_DT = calcDate.ToString("yyyyMMdd"); // //clstb.INSTRUMENT_ID = this.SwapDAO_.INSTRUMENT_ID; // //clstb.INSTRUMENT_TYP = this.SwapDAO_.INSTRUMENT_TYP; // //clstb.UNDERLYING_ID = ""; // //clstb.SEQ = 1; // //clstb.DELTA = 0.0; // //clstb.GAMMA = 0.0; // //clstb.VEGA = 0.0; // //clstb.CALC_PRICE = npv; // //clstb.Insert(); //} public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // 돌릴거에 대한 List를 가져옴. //List<ScenarioData> scenarioDataList = new List<ScenarioData>(); fp_parameter.ScenarioInfo_ = ScenarioInfo.BaseParallelShift(); double value_up = this.calculateImpl(calcDate, fp_parameter); fp_parameter.ScenarioInfo_ = ScenarioInfo.NullScenario(); double value = this.calculateImpl(calcDate,fp_parameter); clsHITM_FP_GREEKRESULT_TB clstb_greekresult = new clsHITM_FP_GREEKRESULT_TB(); clsHDAT_MARKETDATA_TB clstb_market = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); clstb_market.REF_DT = calcDateStr; clstb_market.INDEX_CD = "CD91"; if (clstb_market.SelectOwn() == 0) { throw new Exception("market data does not exist : " + clstb_market.REF_DT + " " + clstb_market.INDEX_CD); } clstb_greekresult.FP_GREEKRESULT_ID = IDGenerator.getNewGreekResultID(this.baseDAO_.INSTRUMENT_ID, calcDateStr); clstb_greekresult.CALC_DT = calcDate.ToString("yyyyMMdd"); clstb_greekresult.INSTRUMENT_ID = this.SwapDAO_.INSTRUMENT_ID; clstb_greekresult.INSTRUMENT_TYP = this.baseDAO_.FP_MASTER_TYP; clstb_greekresult.UNDERLYING_ID = clstb_market.INDEX_CD; clstb_greekresult.UNDERLYING_VALUE = clstb_market.LAST; clstb_greekresult.SEQ = 1; clstb_greekresult.DELTA = value_up - value; clstb_greekresult.GAMMA = 0.0; clstb_greekresult.VEGA = 0.0; clstb_greekresult.CALC_PRICE = value; clstb_greekresult.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; clstb_greekresult.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); clstb_greekresult.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; // 패러럴 쉬푸투 or 그냥 구한거 머 등등.. //clstb_greekresult.UpdateDateResult(); clstb_greekresult.Insert(); #region CashFlow // db 지우는 거? for (int i = 0; i < this.FP_PayCashFlowList_.Count; i++) { if ( !this.FP_PayCashFlowList_[i].hasOccurred(calcDate) ) { this.FP_PayCashFlowList_[i].cf_insert(calcDate, i + 1, this.SwapDAO_.INSTRUMENT_ID, this.SwapDAO_.INSTRUMENT_TYP, (int)clsHITM_FP_CASHFLOWRESULT_TB.PAY_REC_Type.Pay); } } for (int j = 0; j < this.FP_RecCashFlowList_.Count; j++) { if (!this.FP_RecCashFlowList_[j].hasOccurred(calcDate)) { this.FP_RecCashFlowList_[j].cf_insert(calcDate, j + 1, this.SwapDAO_.INSTRUMENT_ID, this.SwapDAO_.INSTRUMENT_TYP, (int)clsHITM_FP_CASHFLOWRESULT_TB.PAY_REC_Type.Rec); } } #endregion }
public abstract QLNet.CashFlow build_ql_cf(FP_Parameter fp_parameter);
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // market data load clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); clstb.REF_DT = calcDateStr; clstb.INDEX_CD = this.Currency_; double currencyRate = 1.0; if ( this.Currency_ != "KRW") { int checkNum = clstb.SelectOwn(); if (checkNum == 0) { throw new Exception("market data does not exist : " + calcDateStr + " " + clstb.INDEX_CD); } currencyRate = clstb.LAST; } // cash amount load clsHITM_CASH_INSTOCK_TB clstb_cash = new clsHITM_CASH_INSTOCK_TB(); clstb_cash.BOOK_CD = this.baseDAO_.BOOK_CD; clstb_cash.CURR = this.Currency_; double total_cash_amount = 0.0; DataTable tb = clstb_cash.Select(); foreach (DataRow dr in tb.Select() ) { total_cash_amount += clsHITM_CASH_INSTOCK_TB.Create(dr).CASHFLOW; } // calculate // position clsHITM_FP_GREEKRESULT_TB result_tb = new clsHITM_FP_GREEKRESULT_TB(); result_tb.FP_GREEKRESULT_ID = IDGenerator.getNewGreekResultID(this.baseDAO_.INSTRUMENT_ID, calcDateStr); result_tb.CALC_DT = calcDateStr; result_tb.SEQ = 1; // price result_tb.INSTRUMENT_ID = this.baseDAO_.INSTRUMENT_ID; result_tb.INSTRUMENT_TYP = this.baseDAO_.FP_MASTER_TYP; result_tb.UNDERLYING_ID = this.Currency_; result_tb.UNDERLYING_VALUE = currencyRate; result_tb.DELTA = 0.0; result_tb.CALC_PRICE = total_cash_amount; result_tb.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; result_tb.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); ; result_tb.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; //if (result_tb.UpdateDateResult() == 0) // { throw new Exception("update fail : " + this.baseDAO_.INSTRUMENT_ID + " " + calcDate.ToString("yyyyMMdd")); }; result_tb.Insert(); // delta // gamma and others : no exist ? }