public override void fixing_calulate(DateTime refDate) { clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); clstb.INDEX_CD = this.DAO_.FIXING_INDEX_CD; clstb.REF_DT = this.DAO_.FIXING_DT; DateTime fixing_date = ConvertingTool.ToDateTime(this.DAO_.FIXING_DT); if(fixing_date <= refDate) { int checkNum = clstb.SelectOwn(); if (checkNum == 0) //{ throw new Exception("Index doesn't exit : " + clstb.REF_DT + " , " + clstb.INDEX_CD); } { throw new Exception("Index doesn't exit : " + clstb.REF_DT + " , " + clstb.INDEX_CD); } //this.DAO_.LEG_ID this.DAO_.FIXED_FIXING = clstb.LAST; this.DAO_.FIXED_FIXING_CALCLATED = (int)clsMAST_CF_VANILLA_FLOATING_TB.FIXED_FIXING_CALCLATED_Type.FIXED; this.DAO_.FIXING_CALCLATION_TYP = (int)clsMAST_CF_VANILLA_FLOATING_TB.FIXED_CALCULATION_TYP.AUTOMATIC; this.DAO_.UpdateFixing(); } }
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) { // 돌릴거에 대한 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 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 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 ? }
public void irData(string name, SquareRootProcess process, double rand, DateTime preDate, DateTime nextDate) { DayCounter dc = new SimpleDayCounter(); clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); clstb.INDEX_CD = name; clstb.REF_DT = preDate.ToString("yyyyMMdd"); clstb.SelectOwn(); clstb.REF_DT = nextDate.ToString("yyyyMMdd"); double x0 = clstb.LAST; double t0 = 0.0; double dt = dc.yearFraction(preDate, nextDate); double v = Math.Round(process.evolve(t0, x0, dt, rand), 8); clstb.LAST = v; clstb.LOW = v; clstb.HIGH = v; clstb.Insert(); }