private void ViewModelChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            this.viewModel_ = this.DataContext as Excel_vanillaReturnCalViewModel;

            //this.viewModel_.Excel_interfaceViewModel_.Excel_underlyingCalcInfoViewModel_.PropertyChanged +=
            //    this.viewModel_.Excel_parameterViewModel_.instrumentEventObserver;
        }
        private void ViewModelChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            this.viewModel_ = this.DataContext as Excel_vanillaReturnCalViewModel;

            //this.viewModel_.Excel_interfaceViewModel_.Excel_underlyingCalcInfoViewModel_.PropertyChanged +=
            //    this.viewModel_.Excel_parameterViewModel_.instrumentEventObserver;
        }
        public override void excel_kiEventCalculationBuild()
        {
            Excel_simpleKiEventCalcViewModel e_simpleKiEvent = new Excel_simpleKiEventCalcViewModel();

            e_simpleKiEvent.Excel_underlyingCalcInfoViewModel_ = this.Excel_underlyingCalcInfoViewModel_;

            e_simpleKiEvent.EventDate_ = this.KiObEndDate_;
            e_simpleKiEvent.PayoffDate_ = this.KiObEndDate_;

            #region EventCal
            {
                Excel_singleBarrierEventCalViewModel e_singleBarrierEvent = new Excel_singleBarrierEventCalViewModel();

                e_singleBarrierEvent.UpperTrigger_ = "1000";
                e_singleBarrierEvent.LowerTrigger_ = ( Convert.ToDouble(this.Ki_) /100.0 ).ToString();

                // 우선 max를 사용함

                Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = this.KiObEndDate_;

                e_mucidvm.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);

                e_singleBarrierEvent.Excel_underlyingCalcIDViewModel_ = e_mucidvm;

                e_singleBarrierEvent.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);

                e_singleBarrierEvent.ObservationStartDate_ = this.KiObStartDate_;
                e_singleBarrierEvent.ObservationEndDate_ = this.KiObEndDate_;

                e_simpleKiEvent.Excel_eventCalcInfoViewModel_ = e_singleBarrierEvent;
            }
            #endregion

            #region OccReturn
            {
                Excel_vanillaReturnCalViewModel e_vanillaReturn = new Excel_vanillaReturnCalViewModel();

                e_vanillaReturn.Excel_underlyingCalcInfoViewModel_ = this.Excel_underlyingCalcInfoViewModel_;

                //e_vanillaReturn.Gearing_ = "-1";
                //e_vanillaReturn.Spread_ = "-0.2";

                e_vanillaReturn.Gearing_ = "1.0";
                e_vanillaReturn.Spread_ = "0.0";

                Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = this.KiObEndDate_;
                e_mucidvm.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);

                e_vanillaReturn.ReturnUnderlyingCalcIDViewModel_ = e_mucidvm;

                e_simpleKiEvent.Excel_occReturnCalcInfoViewModel_ = new Excel_occReturnCalcInfoViewModel();
                e_simpleKiEvent.Excel_occReturnCalcInfoViewModel_.Excel_returnCalcInfoViewModel_ = e_vanillaReturn;
            }
            #endregion

            #region noOccReturn
            {
                Excel_constReturnCalViewModel e_constReturnCalc = new Excel_constReturnCalViewModel();
                int count = this.subScheduleDataList_.Count;

                //입력으로 받아도 대는데 지금은 마지막껄로함.
                e_constReturnCalc.ConstReturn_ = (1.0 + Convert.ToDouble(this.subScheduleDataList_[count - 1].Coupon_) / 100.0).ToString();

                e_constReturnCalc.Excel_underlyingCalcInfoViewModel_ = this.Excel_underlyingCalcInfoViewModel_;

                e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_ = new Excel_noOccReturnCalcInfoViewModel();
                e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_.Excel_returnCalcInfoViewModel_ = e_constReturnCalc;

                e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);
            }
            #endregion

            this.Excel_kiEventCalculationViewModel_ = e_simpleKiEvent;
        }
        public override void excel_kiEventCalculationBuild()
        {
            Excel_simpleKiEventCalcViewModel e_simpleKiEvent = new Excel_simpleKiEventCalcViewModel();

            e_simpleKiEvent.Excel_underlyingCalcInfoViewModel_ = this.Excel_underlyingCalcInfoViewModel_;

            e_simpleKiEvent.EventDate_  = this.KiObEndDate_;
            e_simpleKiEvent.PayoffDate_ = this.KiObEndDate_;

            #region EventCal
            {
                Excel_singleBarrierEventCalViewModel e_singleBarrierEvent = new Excel_singleBarrierEventCalViewModel();

                e_singleBarrierEvent.UpperTrigger_ = "1000";
                e_singleBarrierEvent.LowerTrigger_ = (Convert.ToDouble(this.Ki_) / 100.0).ToString();

                // 우선 max를 사용함

                Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = this.KiObEndDate_;

                e_mucidvm.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);

                e_singleBarrierEvent.Excel_underlyingCalcIDViewModel_ = e_mucidvm;

                e_singleBarrierEvent.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);

                e_singleBarrierEvent.ObservationStartDate_ = this.KiObStartDate_;
                e_singleBarrierEvent.ObservationEndDate_   = this.KiObEndDate_;

                e_simpleKiEvent.Excel_eventCalcInfoViewModel_ = e_singleBarrierEvent;
            }
            #endregion

            #region OccReturn
            {
                Excel_vanillaReturnCalViewModel e_vanillaReturn = new Excel_vanillaReturnCalViewModel();

                e_vanillaReturn.Excel_underlyingCalcInfoViewModel_ = this.Excel_underlyingCalcInfoViewModel_;

                //e_vanillaReturn.Gearing_ = "-1";
                //e_vanillaReturn.Spread_ = "-0.2";

                e_vanillaReturn.Gearing_ = "1.0";
                e_vanillaReturn.Spread_  = "0.0";

                Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = this.KiObEndDate_;
                e_mucidvm.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);

                e_vanillaReturn.ReturnUnderlyingCalcIDViewModel_ = e_mucidvm;

                e_simpleKiEvent.Excel_occReturnCalcInfoViewModel_ = new Excel_occReturnCalcInfoViewModel();
                e_simpleKiEvent.Excel_occReturnCalcInfoViewModel_.Excel_returnCalcInfoViewModel_ = e_vanillaReturn;
            }
            #endregion

            #region noOccReturn
            {
                Excel_constReturnCalViewModel e_constReturnCalc = new Excel_constReturnCalViewModel();
                int count = this.subScheduleDataList_.Count;

                //입력으로 받아도 대는데 지금은 마지막껄로함.
                e_constReturnCalc.ConstReturn_ = (1.0 + Convert.ToDouble(this.subScheduleDataList_[count - 1].Coupon_) / 100.0).ToString();

                e_constReturnCalc.Excel_underlyingCalcInfoViewModel_ = this.Excel_underlyingCalcInfoViewModel_;

                e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_ = new Excel_noOccReturnCalcInfoViewModel();
                e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_.Excel_returnCalcInfoViewModel_ = e_constReturnCalc;

                e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_.setUnderlying(this.Excel_underlyingCalcInfoViewModel_);
            }
            #endregion

            this.Excel_kiEventCalculationViewModel_ = e_simpleKiEvent;
        }
        // ki 계열
        public string set_constKI_sch(double lowerTrigger,
                                       double upperTrigger,
                                       //CalculationEnum kiCheckType,
                                       string kiCheckType,
                                       string underlyings,
                                       //LossType lossType,
                                       string lossType, // 이거 구분 아직 안함
                                       double noKICoupon,
                                       DateTime obStartDate,
                                       DateTime obEndDate)
        {
            try
            {
                #region CheckParameter

                if (underlyings == "")
                    throw new Exception("underlying input is empty");
                
                // check underlying 
                if ( !this.hasUnderlyings(underlyings))
                    throw new Exception(underlyings + " does not exist. add underlying first.");

                #endregion

                Excel_simpleKiEventCalcViewModel e_simpleKiEvent = new Excel_simpleKiEventCalcViewModel();

                //this.addUnderlying(underlyings);

                Excel_underlyingCalcInfoViewModel e_ucivm = this.InstVM_.Excel_interfaceViewModel_.Excel_underlyingCalcInfoViewModel_;

                e_simpleKiEvent.Excel_underlyingCalcInfoViewModel_ = e_ucivm;
                
                e_simpleKiEvent.EventDate_ = obEndDate;
                e_simpleKiEvent.PayoffDate_ = obEndDate;

                #region EventCal
                {
                    Excel_singleBarrierEventCalViewModel e_singleBarrierEvent = new Excel_singleBarrierEventCalViewModel();

                    e_singleBarrierEvent.UpperTrigger_ = upperTrigger.ToString();
                    e_singleBarrierEvent.LowerTrigger_ = lowerTrigger.ToString(); 

                    // 우선 max를 사용함

                    Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                    e_mucidvm.EventDate_ = obEndDate;

                    e_mucidvm.setUnderlying(e_ucivm);
                    e_mucidvm.selectUnderlyings(underlyings);

                    e_singleBarrierEvent.Excel_underlyingCalcIDViewModel_ = e_mucidvm;

                    //e_singleBarrierEvent.setUnderlying(e_ucivm);
                    
                    e_singleBarrierEvent.ObservationStartDate_ = obStartDate;
                    e_singleBarrierEvent.ObservationEndDate_ = obEndDate;

                    e_simpleKiEvent.Excel_eventCalcInfoViewModel_ = e_singleBarrierEvent;
                }
                #endregion

                #region OccReturn
                {
                    Excel_vanillaReturnCalViewModel e_vanillaReturn = new Excel_vanillaReturnCalViewModel();

                    e_vanillaReturn.Excel_underlyingCalcInfoViewModel_ = e_ucivm;

                    //e_vanillaReturn.Gearing_ = "-1";
                    //e_vanillaReturn.Spread_ = "-0.2";

                    e_vanillaReturn.Gearing_ = "1.0";
                    e_vanillaReturn.Spread_ = "-1.0";

                    Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                    e_mucidvm.EventDate_ = obEndDate;
                    e_mucidvm.setUnderlying(e_ucivm);
                    e_mucidvm.selectUnderlyings(underlyings);

                    e_vanillaReturn.ReturnUnderlyingCalcIDViewModel_ = e_mucidvm;

                    e_simpleKiEvent.Excel_occReturnCalcInfoViewModel_ = new Excel_occReturnCalcInfoViewModel();
                    e_simpleKiEvent.Excel_occReturnCalcInfoViewModel_.Excel_returnCalcInfoViewModel_ = e_vanillaReturn;
                }
                #endregion

                #region noOccReturn
                {
                    Excel_constReturnCalViewModel e_constReturnCalc = new Excel_constReturnCalViewModel();
                    
                    e_constReturnCalc.ConstReturn_ = noKICoupon.ToString();

                    e_constReturnCalc.Excel_underlyingCalcInfoViewModel_ = e_ucivm;

                    e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_ = new Excel_noOccReturnCalcInfoViewModel();
                    e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_.Excel_returnCalcInfoViewModel_ = e_constReturnCalc;

                    e_simpleKiEvent.Excel_noOccReturnCalcInfoViewModel_.setUnderlying(e_ucivm);
                }
                #endregion

                Excel_hifiveViewModel e_hvm = this.InstVM_.Excel_interfaceViewModel_ as Excel_hifiveViewModel;

                e_hvm.Excel_kiEventCalculationViewModel_ = e_simpleKiEvent;

                List<string> member = new List<string>() {"instType", "schtype","lowerTrigger", "upperTrigger", "kiCheckType", "underlyings", "lossType", "noKICoupon", "obStartDate", "obEndDate" };
                List<string> value = new List<string>() { "hifive" ,"constKI",lowerTrigger.ToString(), upperTrigger.ToString(), kiCheckType.ToString(), underlyings.ToString(), lossType.ToString(), noKICoupon.ToString(), StringConverter.xmlDateTimeToDateString(obStartDate), StringConverter.xmlDateTimeToDateString(obEndDate) };

                e_simpleKiEvent.VBA_description_ = this.vba_description(member, value);

                return "set complete";
            }
            catch (Exception e)
            {
                return "set fail : " + e.Message;
            }
        }