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 void IndexData(DateTime refDate) { string refDateStr = refDate.ToString("yyyyMMdd"); //string fileName = @"D:\data_etl\INDEX_" + refDateStr + ".TXT"; string fileName = @"C:\batch\INDEX_" + refDateStr + ".TXT"; /* Download a File */ this.FtpConnector_.download("/marketdata/index/INDEX_" + refDateStr + ".TXT", fileName); if (!File.Exists(fileName)) throw new FileNotFoundException(); DataSet ds = TextToDataSet.Convert(fileName, "testTB", "|"); // db 에 올림. clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); clstb.REF_DT = refDateStr; clstb.DeleteDate(); foreach (DataRow dr in ds.Tables[0].Select()) { if (dr[0].ToString() != "") { if ( dr[1].ToString().Trim().Substring(0,3) != "KRA") { clstb.REF_DT = dr[0].ToString().Trim(); clstb.INDEX_CD = dr[1].ToString().Trim(); if (dr[10].ToString().Trim() != "") { if (clstb.INDEX_CD == "KOSPI_029") { clstb.INDEX_CD = "KOSPI200"; } clstb.LAST = Convert.ToDouble(dr[6].ToString().Trim()) / 100.0; clstb.LOW = Convert.ToDouble(dr[7].ToString().Trim()) / 100.0; clstb.HIGH = Convert.ToDouble(dr[8].ToString().Trim()) / 100.0; } else { clstb.LAST = Convert.ToDouble(dr[6].ToString().Trim()); clstb.LOW = Convert.ToDouble(dr[7].ToString().Trim()); clstb.HIGH = Convert.ToDouble(dr[8].ToString().Trim()); } clstb.Insert(); } } } clstb.INDEX_CD = "CD91"; clstb.LAST = 0.0185; clstb.LOW = 0.0185; clstb.HIGH = 0.0185; clstb.Insert(); }
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 void buildTestData() { clsHDAT_MARKETDATA_TB clsTB = new clsHDAT_MARKETDATA_TB(); string[] dateString = { "20130701","20130702","20130703","20130704","20130705","20130708","20130709","20130710","20130711","20130712","20130715","20130716", #region data "20130717","20130718","20130719","20130722","20130723","20130724","20130725","20130726","20130729","20130730","20130731","20130801", "20130802","20130805","20130806","20130807","20130808","20130809","20130812","20130813","20130814","20130815","20130816","20130819", "20130820","20130821","20130822","20130823","20130826","20130827","20130828","20130829","20130830","20130902","20130903","20130904", "20130905","20130906","20130909","20130910","20130911","20130912","20130913","20130916","20130917","20130918","20130919","20130920", "20130923","20130924","20130925","20130926","20130927","20130930","20131001","20131002","20131003","20131004","20131007","20131008", "20131009","20131010","20131011","20131014","20131015","20131016","20131017","20131018","20131021","20131022","20131023","20131024", "20131025","20131028","20131029","20131030","20131031","20131101","20131104","20131105","20131106","20131107","20131108","20131111", "20131112","20131113","20131114","20131115","20131118","20131119","20131120","20131121","20131122","20131125","20131126","20131127", "20131128","20131129","20131202","20131203","20131204","20131205","20131206","20131209","20131210","20131211","20131212","20131213", "20131216","20131217","20131218","20131219","20131220","20131223","20131224","20131225","20131226","20131227","20131230","20131231", "20140101","20140102","20140103","20140106","20140107","20140108","20140109","20140110","20140113","20140114","20140115","20140116", "20140117","20140120","20140121","20140122","20140123","20140124","20140127","20140128","20140129","20140130","20140131","20140203", "20140204","20140205","20140206","20140207","20140210","20140211","20140212","20140213","20140214","20140217","20140218","20140219", "20140220","20140221","20140224","20140225","20140226","20140227","20140228","20140303","20140304","20140305","20140306","20140307", "20140310","20140311","20140312","20140313","20140314","20140317","20140318","20140319","20140320","20140321","20140324","20140325", "20140326","20140327","20140328","20140331","20140404","20140407","20140408","20140409","20140410","20140411","20140414","20140415", "20140416","20140417","20140418","20140421","20140422","20140423","20140424","20140425","20140428","20140429","20140430","20140501", "20140502","20140505","20140506","20140507","20140508","20140509","20140512","20140513","20140514","20140515","20140516","20140519", "20140520","20140521","20140522","20140523","20140526","20140527","20140528","20140529","20140530","20140602","20140603","20140604", "20140605","20140609","20140610","20140611","20140612","20140613","20140616","20140617","20140618","20140619","20140620","20140623", "20140624","20140625","20140626","20140627","20140630","20140701","20140702","20140703","20140704","20140707","20140708","20140709", "20140710","20140711","20140714","20140715","20140716","20140717","20140718","20140721","20140722","20140723","20140724","20140725", "20140728","20140729","20140730","20140731","20140801","20140804","20140805","20140806","20140807","20140808","20140811","20140812", "20140813","20140814","20140815","20140818","20140819","20140820","20140821","20140822","20140825","20140826","20140827","20140828", "20140829","20140901","20140902","20140903","20140904","20140905","20140908","20140909","20140910","20140911","20140912","20140915", "20140916","20140917","20140918","20140919","20140922","20140923","20140924","20140925","20140926","20140929","20140930","20141001", "20141002","20141003","20141006","20141007","20141008","20141009","20141010","20141013","20141014","20141015","20141016","20141017", "20141020","20141021","20141022","20141023","20141024","20141027","20141028","20141029","20141030","20141031","20141103","20141104", "20141105","20141106","20141107","20141110","20141111","20141112","20141113","20141114","20141117","20141118","20141119","20141120", "20141121","20141124","20141125","20141126","20141127","20141128","20141201","20141202","20141203","20141204","20141205","20141208", "20141209","20141210","20141211","20141212","20141215","20141216","20141217","20141218","20141219","20141222","20141223","20141224", "20141225","20141226","20141229","20141230","20141231","20150101","20150102","20150105","20150106","20150107","20150108","20150109", "20150112","20150113","20150114","20150115","20150116","20150119","20150120","20150121","20150122","20150123","20150126","20150127", "20150128","20150129","20150130","20150202","20150203","20150204","20150205","20150206","20150209","20150210","20150211","20150212", "20150213","20150216","20150217","20150218","20150219","20150220","20150223","20150224","20150225","20150226","20150227","20150302", "20150303","20150304","20150305","20150306","20150309","20150310","20150311","20150312","20150313","20150316","20150317","20150318", #endregion "20150319","20150320","20150323","20150324","20150325","20150326","20150327","20150330","20150604" }; double[] rateList = { 0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0269,0.0267,0.0267,0.0267,0.0267,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.026505,0.026503,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0266,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0265,0.0263,0.0262,0.0261,0.0246,0.0246,0.0243,0.0242,0.0242,0.0242,0.0241,0.0241,0.024,0.024,0.024,0.024,0.024,0.0236,0.0236,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0235,0.0231,0.023,0.023,0.0229,0.0228,0.0228,0.0218,0.0217,0.0217,0.0216,0.0215,0.0215,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0214,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0213,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.0212,0.021,0.021,0.021,0.021,0.021,0.021,0.021,0.021,0.021,0.021,0.021,0.021,0.0191,0.019,0.0189,0.0188,0.0187,0.0187,0.0186,0.0186,0.0186,0.0186,0.0186,0.0186,0.0185,0.0185 }; double[] indexkospi200List = { 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47, 255.47 }; int rateListLength = rateList.Length; int indexListLength = rateList.Length; int dateLength = dateString.Length; clsTB.INDEX_CD = "CD91"; for (int i = 0; i < dateLength; i++) { clsTB.REF_DT = dateString[i]; clsTB.LAST = rateList[i]; clsTB.LOW= rateList[i]; clsTB.HIGH= rateList[i]; clsTB.Insert(); } clsTB.INDEX_CD = "KOSPI200"; for (int i = 0; i < dateLength; i++) { clsTB.REF_DT = dateString[i]; clsTB.LAST = indexkospi200List[i]; clsTB.LOW = indexkospi200List[i]; clsTB.HIGH = indexkospi200List[i]; clsTB.Insert(); } }
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, 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 clsHDAT_MARKETDATA_TB Clone() { try { clsHDAT_MARKETDATA_TB cloneTB = new clsHDAT_MARKETDATA_TB(); cloneTB._REF_DT = this._REF_DT; cloneTB._INDEX_CD = this._INDEX_CD; cloneTB._LAST = this._LAST; cloneTB._LOW = this._LOW; cloneTB._HIGH = this._HIGH; return cloneTB; } catch(Exception ex) { throw new Exception(ex.Message); } }
//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 static clsHDAT_MARKETDATA_TB Create(DataRow dr) { try { clsHDAT_MARKETDATA_TB tb = new clsHDAT_MARKETDATA_TB(); tb._REF_DT = Convert.ToString(dr[0]); tb._INDEX_CD = Convert.ToString(dr[1]); tb._LAST = Convert.ToDouble(dr[2]); tb._LOW = Convert.ToDouble(dr[3]); tb._HIGH = Convert.ToDouble(dr[4]); return tb; } catch(Exception ex) { throw new Exception(ex.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.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 historyIndexData(GBMParameter para, DateTime startDate, DateTime endDate) //{ // DayCounter dc = new SimpleDayCounter(); // CalendarManager cm = new CalendarManager(DateTime.Now,CalendarManager.CountryType.SOUTH_KOREA); // double initialValue = para.Initial_; // double preValue = initialValue; // double drift = para.Drift_; // double vol = para.Vol_; // double t0 = 0.0; // double dt = 0.0; // double x0 = preValue; // double dw = 0.0; // DateTime roopDate = startDate; // GeometricBrownianMotionProcess gbm = new GeometricBrownianMotionProcess(initialValue, drift, vol); // PseudoRandom random = new PseudoRandom(); // //RandomSequenceGenerator<MersenneTwisterUniformRng> randGen = random.make_sequence_generator(1000, 1) as RandomSequenceGenerator<MersenneTwisterUniformRng>; // int genNum = Convert.ToInt32((endDate - startDate).TotalDays); // IRNG randGen = random.make_sequence_generator(genNum, Convert.ToUInt64( this.random_.Next())) as IRNG; // int i = 0; // Sample<List<double>> sample = randGen.nextSequence(); // //Sample<List<double>> sample = new Sample<List<double>>(); // clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); // clstb.INDEX_CD = para.Name_; // while (roopDate < endDate) // { // clstb.REF_DT = roopDate.ToString("yyyyMMdd"); // DateTime nextDate = cm.adjust(roopDate,"1D"); // t0 = dc.yearFraction(startDate, roopDate); // dt = dc.yearFraction(roopDate, nextDate); // dw = sample.value[i]; // double v = Math.Round(gbm.evolve(t0, x0, dt, dw),2); // clstb.LAST = v; // clstb.LOW = v; // clstb.HIGH = v; // clstb.Insert(); // roopDate = nextDate; // x0 = v; // i += 1; // } //} //public void historyIRData(VasicekParameter para, DateTime startDate, DateTime endDate) //{ // DayCounter dc = new SimpleDayCounter(); // CalendarManager cm = new CalendarManager(DateTime.Now, CalendarManager.CountryType.SOUTH_KOREA); // double initialValue = para.Initial_; // double preValue = initialValue; // double longTermRate = para.LongTermRate_; // double spreed = para.Speed_; // double vol = para.Vol_; // double t0 = 0.0; // double dt = 0.0; // double x0 = preValue; // double dw = 0.0; // DateTime roopDate = startDate; // SquareRootProcess vasicek = new SquareRootProcess(longTermRate, spreed, vol, initialValue); // PseudoRandom random = new PseudoRandom(); // int genNum = Convert.ToInt32((endDate - startDate).TotalDays); // 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(); // clstb.INDEX_CD = para.Name_; // while (roopDate < endDate) // { // clstb.REF_DT = roopDate.ToString("yyyyMMdd"); // DateTime nextDate = cm.adjust(roopDate, "1D"); // t0 = dc.yearFraction(startDate, roopDate); // dt = dc.yearFraction(roopDate, nextDate); // dw = sample.value[i]; // double v = Math.Round(vasicek.evolve(t0, x0, dt, dw)); // clstb.LAST = v; // clstb.LOW = v; // clstb.HIGH = v; // clstb.Insert(); // roopDate = nextDate; // x0 = v; // i += 1; // } //} public void getData(DateTime refDate) { // 전일자 구함. clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); clstb.REF_DT = refDate.ToString("yyyyMMdd"); clstb.DeleteDate(); DateTime preDate = clstb.SelectMaxDate(); // ㄱㄱ this.build_indexHistoryData(preDate,refDate,false); this.build_irHistoryData(preDate, refDate, false); this.build_curveHistoryData(preDate, refDate, false); }
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(); }
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; } } }