// 기존거 있으면 지움. 초기화임. public void build_position() { // 전일자 position date ? CalendarManager calendarM = new CalendarManager(this.ReferenceDate_, CalendarManager.CountryType.SOUTH_KOREA); DateTime preDate = calendarM.preBusinessDay(this.ReferenceDate_); clsHITM_FP_POSITION_TB clstb_position = new clsHITM_FP_POSITION_TB(); clstb_position.POSITION_DT = this.ReferenceDate_.ToString("yyyyMMdd"); clstb_position.DeleteDate(); this.build_cashMaster(); // ------------------------------------------------------------------------ clsMAST_FP_INSTRUMENT_TB clstb_mast = new clsMAST_FP_INSTRUMENT_TB(); DataTable dt = clstb_mast.Select(); List<Financial_instrument> fi_list = new List<Financial_instrument>(); // master 의 list 내에서 position을 만들음. // bookdate ? 감안해서 만듬? 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); } foreach (Financial_instrument fi in fi_list) { // trading 할때에 같은 날짜는 나중에 더해서 만들어짐 if (ConvertingTool.ToDateTime(fi.baseDAO_.BOOKED_DT).Date < this.ReferenceDate_.Date) { fi.build_position(preDate, this.ReferenceDate_); } } }
public void calculatePL() { CalendarManager cm = new CalendarManager(this.ReferenceDateTime_, CalendarManager.CountryType.SOUTH_KOREA); clsHITM_FP_GREEKRESULT_TB clstb_result = new clsHITM_FP_GREEKRESULT_TB(); clstb_result.CALC_DT = this.ReferenceDateTime_.ToString("yyyyMMdd"); clstb_result.INSTRUMENT_ID = this.DAO_.INSTRUMENT_ID; clstb_result.SEQ = 1; int checkNum = clstb_result.SelectOwn(); if (checkNum == 0) { throw new Exception("no exist"); } double calcPrice = clstb_result.CALC_PRICE; double quantity = this.DAO_.INSTRUMENT_QNT; clsMAST_FP_INSTRUMENT_TB clstb_master = new clsMAST_FP_INSTRUMENT_TB(); //this.DAO_.ETC_PL = clstb_result.CALC_PRICE; this.DAO_.EVAL_AMT = Math.Round( calcPrice ); this.DAO_.EVAL_PRICE = Math.Round( calcPrice / quantity ); this.DAO_.EVAL_ACCOUNT_PL = Math.Round( this.DAO_.EVAL_AMT - this.DAO_.ACCOUNT_AMT ); // - 평가금액 - 장부금액 //this.DAO_.TRADE_PROFIT = this.DAO_.TRADE_PROFIT + tradePosition.DAO_.TRADE_PROFIT; // 일별 매매수익 //this.DAO_.TRADE_LOSS = tradePosition.DAO_.TRADE_LOSS; //this.DAO_.TRADE_TOTAL = tradePosition.DAO_.TRADE_TOTAL; //this.DAO_.TRANSACTION_FEE = tradePosition.DAO_.TRANSACTION_FEE; this.DAO_.ETC_PL = 0; // 데일리 기타 손익임. this.DAO_.TOTAL_ACCOUNT_PL = Math.Round( this.DAO_.EVAL_ACCOUNT_PL + this.DAO_.TRADE_TOTAL + this.DAO_.TRANSACTION_FEE ); // 전일 포지션 DateTime preDate = cm.preBusinessDay(ConvertingTool.ToDateTime(this.ReferenceDateTime_.ToString("yyyyMMdd"))); clsHITM_FP_POSITION_TB clstb_position = new clsHITM_FP_POSITION_TB(); clstb_position.POSITION_DT = preDate.ToString("yyyyMMdd"); clstb_position.INSTRUMENT_ID = this.DAO_.INSTRUMENT_ID; clstb_position.SelectOwn(); // 전일자꺼가 여기 박혀서 옴..? 중간에 trade했을때 this.DAO_.DAILY_EVAL_PL = Math.Round(this.DAO_.EVAL_AMT - clstb_position.EVAL_AMT ); // 전일 평가 - 당일 평가 this.DAO_.DAILY_TOTAL_PL = Math.Round( this.DAO_.TRADE_TOTAL + this.DAO_.ETC_PL + this.DAO_.DAILY_EVAL_PL ); // 여기서 부터 작업 this.calculatePL_impl(); if (this.DAO_.UpdateCalculatedPosition() == 0) { throw new Exception("update fail :" + this.DAO_.INSTRUMENT_ID + " " + this.DAO_.POSITION_DT); } else if (this.DAO_.UpdateCalculatedPosition() > 1) { throw new Exception("too many updated :" + this.DAO_.INSTRUMENT_ID + " " + this.DAO_.POSITION_DT); } else { } }