Beispiel #1
0
        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 ?
        }
Beispiel #2
0
        public void build_position(DateTime preDate, DateTime nextDate)
        {
            // 
            clsHITM_FP_POSITION_TB clstb = new clsHITM_FP_POSITION_TB();

            clstb.POSITION_DT = preDate.ToString("yyyyMMdd");
            clstb.INSTRUMENT_ID = this.baseDAO_.INSTRUMENT_ID;

            //if (clstb.SelectOwn() == 0)
            //{
                //throw new Exception("no exist position : " + this.baseDAO_.INSTRUMENT_ID);
                
            //}
            
            // 없는게 말이 안됨... Trade 할때 Position이 박히거든...

            // Direct로 Master에 밀어 넣는건 안됨.

            // 없으면 없는 건데.. trade된거는 다음 Process 임. 엎어 치던 더하던, 이건 기존꺼만 함.

            if ( clstb.SelectOwn() != 0)
            { 
                Position ifp = Position.CreatePosition(clstb);
                ifp.DAO_ = clstb;
                Position next_date_ifp = ifp.nextDateClone(nextDate);

                next_date_ifp.DAO_.Insert();
            }

            //return next_date_ifp;
        }
Beispiel #3
0
        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 ?

        }
Beispiel #4
0
        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 { }
        }