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

            this.underlyingSelectListView_.ItemsSource = this.viewModel_.Excel_selectedUnderlyingViewModel_;

        }
        public override Excel_underlyingCalcIDViewModel Clone()
        {
            Excel_minimumUnderlyingCalcIDViewModel clone = new Excel_minimumUnderlyingCalcIDViewModel();

            foreach (var item in this.excel_selectedUnderlyingViewModel_)
            {
                clone.excel_selectedUnderlyingViewModel_ = new ObservableCollection <Excel_selectedUnderlyingViewModel>();
                clone.excel_selectedUnderlyingViewModel_.Add(item.Clone());
            }

            clone.EventDate_   = this.eventDate_;
            clone.AverageDays_ = this.averageDays_;

            return(clone);
        }
        public static Excel_underlyingCalcIDViewModel CreateExcel_underlyingCalcID(Excel_stepDownKI_subScheduleViewModel e_s_svm)
        {
            string typeStr = e_s_svm.UnderCalcType_;

            if (typeStr.ToUpper() == "MAXIMUM" || typeStr.ToUpper() == "MAX")
            {
                Excel_maximumUnderlyingCalcIDViewModel e_mucidvm = new Excel_maximumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_   = e_s_svm.EventDate_;
                e_mucidvm.AverageDays_ = e_s_svm.AverageDays_;

                return(e_mucidvm);
            }
            else if (typeStr.ToUpper() == "MINIMUM" || typeStr.ToUpper() == "MIN")
            {
                Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_   = e_s_svm.EventDate_;
                e_mucidvm.AverageDays_ = e_s_svm.AverageDays_;

                return(e_mucidvm);
            }
            else if (typeStr.ToUpper() == "AVERAGE" || typeStr.ToUpper() == "AVER")
            {
                Excel_averageUnderlyingCalcIDViewModel e_mucidvm = new Excel_averageUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = e_s_svm.EventDate_;
                //e_mucidvm.AverageDays_ = e_s_svm.AverageDays_;

                return(e_mucidvm);
            }
            //else if (typeStr == "excel_orderUnderlyingCalcID")
            //{
            //    return new Excel_orderUnderlyingCalcIDViewModel();
            //}
            else
            {
                throw new NotImplementedException();
            }
        }
        public override Excel_underlyingCalcIDViewModel Clone()
        {
            Excel_minimumUnderlyingCalcIDViewModel clone = new Excel_minimumUnderlyingCalcIDViewModel();

            foreach (var item in this.excel_selectedUnderlyingViewModel_)
            {
                clone.excel_selectedUnderlyingViewModel_ = new ObservableCollection<Excel_selectedUnderlyingViewModel>();
                clone.excel_selectedUnderlyingViewModel_.Add(item.Clone());
            }

            clone.EventDate_ = this.eventDate_;
            clone.AverageDays_ = this.averageDays_;

            return clone;

        }
        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;
            }
        }
        public static Excel_underlyingCalcIDViewModel CreateExcel_underlyingCalcID(Excel_stepDownKI_subScheduleViewModel e_s_svm)
        {
            string typeStr = e_s_svm.UnderCalcType_;

            if (typeStr.ToUpper() == "MAXIMUM" || typeStr.ToUpper() == "MAX")
            {
                Excel_maximumUnderlyingCalcIDViewModel e_mucidvm = new Excel_maximumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = e_s_svm.EventDate_;
                e_mucidvm.AverageDays_ = e_s_svm.AverageDays_;

                return e_mucidvm;
            }
            else if (typeStr.ToUpper() == "MINIMUM" || typeStr.ToUpper() == "MIN")
            {
                Excel_minimumUnderlyingCalcIDViewModel e_mucidvm = new Excel_minimumUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = e_s_svm.EventDate_;
                e_mucidvm.AverageDays_ = e_s_svm.AverageDays_;

                return e_mucidvm;

            }
            else if (typeStr.ToUpper() == "AVERAGE" || typeStr.ToUpper() == "AVER")
            {
                Excel_averageUnderlyingCalcIDViewModel e_mucidvm = new Excel_averageUnderlyingCalcIDViewModel();

                e_mucidvm.EventDate_ = e_s_svm.EventDate_;
                //e_mucidvm.AverageDays_ = e_s_svm.AverageDays_;

                return e_mucidvm;
            }
            //else if (typeStr == "excel_orderUnderlyingCalcID")
            //{
            //    return new Excel_orderUnderlyingCalcIDViewModel();
            //}
            else
            {
                throw new NotImplementedException();
            }
        }
        private void ViewModelChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            this.viewModel_ = this.DataContext as Excel_minimumUnderlyingCalcIDViewModel;

            this.underlyingSelectListView_.ItemsSource = this.viewModel_.Excel_selectedUnderlyingViewModel_;
        }