Beispiel #1
0
        private void SetParameters(object sender, RoutedEventArgs e)
        {
            // Create Bond from User's Input
            int frequency;

            if ((bool)monthly.IsChecked)
            {
                frequency = 12;
            }
            else if ((bool)quaterly.IsChecked)
            {
                frequency = 3;
            }
            else if ((bool)twiceYear.IsChecked)
            {
                frequency = 2;
            }
            else
            {
                frequency = 1;
            }
            double         marketRate = Double.Parse(MarketRate.Text, CultureInfo.InvariantCulture) / 100;
            double         annualRate = Double.Parse(AnnualRate.Text, CultureInfo.InvariantCulture) / 100;
            double         faceValue  = Double.Parse(FaceValue.Text, CultureInfo.InvariantCulture);
            ConventionDate maturity   = new ConventionDate(Maturity.Text);

            // Get Action if needed
            string yieldType = FormatString(YieldType.SelectedItem.ToString());

            if (yieldType == "Variable Yield")
            {
                action = new Action("ACCOR", 100, new ConventionDate(), maturity);
            }
            bond = new Bond(faceValue, annualRate, marketRate, frequency, maturity);
        }
Beispiel #2
0
        private ConventionDate GetNextCouponDate(ConventionDate today)
        {
            int nextDay   = maturity.Day;
            int nextMonth = GetNextMonth(today);
            int nextYear  = GetNextYear(today, nextMonth);

            return(new ConventionDate(nextYear, nextMonth, nextDay));
        }
Beispiel #3
0
 public Bond(double faceValue, double annualRate, double marketRate, int frequency,
             ConventionDate maturity)
 {
     this.faceValue  = faceValue;
     this.annualRate = annualRate;
     this.marketRate = marketRate;
     this.frequency  = frequency;
     this.maturity   = maturity;
 }
Beispiel #4
0
 public Action(string name, double initial, ConventionDate today, ConventionDate maturity)
 {
     this.name  = name;
     this.drift = 0.1;
     this.vol   = 0.2;
     this.spots = new Dictionary <ConventionDate, double>();
     this.spots.Add(today, initial);
     BuildTrajectory(today, maturity);
 }
Beispiel #5
0
 private int GetNextYear(ConventionDate today, int nextMonth)
 {
     if (nextMonth < today.Month)
     {
         return(today.Year + 1);
     }
     else
     {
         return(today.Year);
     }
 }
Beispiel #6
0
        private int GetNextMonth(ConventionDate today)
        {
            List <int> months = GetMonthsCoupon();

            if (today.Day < maturity.Day)
            {
                return(FindClosestBefore(months, today.Month));
            }
            else
            {
                return(FindClosestAfter(months, today.Month));
            }
        }
Beispiel #7
0
        public override bool Equals(object obj)
        {
            if ((obj == null) || !this.GetType().Equals(obj.GetType()))
            {
                return(false);
            }

            ConventionDate date = (ConventionDate)obj;

            if ((date.Day != this.Day) || (date.Month != this.Month) || (date.Year != this.Year))
            {
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        private void QuickSimulation(object sender, RoutedEventArgs e)
        {
            double         faceValue  = 100000;
            double         annualRate = 5.5 / 100;
            double         marketRate = 1.2 / 100;
            ConventionDate maturity   = new ConventionDate(2022, 11, 15);
            int            frequency  = 1;

            bond = new Bond(faceValue, annualRate, marketRate, frequency, maturity);

            double price         = 0;
            int    nbSimulations = 100;

            for (var simul = 0; simul < nbSimulations; simul++)
            {
                action = new Action("ACCOR", 100, new ConventionDate(), maturity);
                price += bond.GetPrice(action);
            }
            ShowPrice(price / nbSimulations);
        }
Beispiel #9
0
        private void BuildTrajectory(ConventionDate today, ConventionDate maturity)
        {
            double         dt = GetDt();
            double         spotValue;
            bool           afterMaturity = false;
            ConventionDate currentDate   = today.GetNextDate();
            ConventionDate previousDate  = today;

            while (!afterMaturity)
            {
                if (currentDate.Equals(maturity))
                {
                    afterMaturity = true;
                }
                spotValue = spots[previousDate] * Math.Exp((drift - Math.Pow(vol, 2) / 2) * dt + vol * Math.Sqrt(dt) * Normal.Sample(random, 0.0, 1.0));
                spots.Add(currentDate, spotValue);
                previousDate = currentDate;
                currentDate  = currentDate.GetNextDate();
            }
        }
Beispiel #10
0
 public int NumberDays(ConventionDate endDate)
 {
     return(360 * (endDate.Year - this.Year) + 30 * (endDate.Month - this.Month) + (endDate.Day - this.Day));
 }
Beispiel #11
0
        public double GetPrice(Action action)
        {
            double         perf;
            double         perfFactor   = 1;
            double         price        = 0;
            int            year         = 1;
            ConventionDate previousDate = new ConventionDate();
            ConventionDate currentDate  = GetNextCouponDate(previousDate);
            int            nbDays       = previousDate.NumberDays(currentDate);
            double         factor       = (double)nbDays / (double)previousDate.GetDaysPerYear();

            price += factor * faceValue * annualRate / Math.Pow((1 + marketRate), factor);
            while (!currentDate.Equals(maturity))
            {
                if (action != null)
                {
                    perf = action.GetPerf(currentDate, previousDate);
                    if (perf > 0.2)
                    {
                        perfFactor = 1;
                    }
                    else if (perf > 0.1)
                    {
                        perfFactor = 0.7;
                    }
                    else
                    {
                        perfFactor = 0.5;
                    }
                }
                price       += perfFactor * faceValue * annualRate / Math.Pow(1 + marketRate, factor + (year / frequency)) / (double)frequency;
                year        += 1;
                previousDate = currentDate;
                currentDate  = GetNextCouponDate(currentDate);
            }

            /*for (int year = 1; year < frequency * YearsTillMaturity(); year++)
             * {
             *  if (action != null)
             *  {
             *      perf = action.GetPerf(year);
             *  }
             *  price += perf * faceValue * annualRate / Math.Pow((1 + marketRate), factor + (year / frequency)) / (double)frequency;
             * }*/
            if (action != null)
            {
                perf = action.GetPerf(previousDate, maturity);
                if (perf > 0.2)
                {
                    perfFactor = 1;
                }
                else if (perf > 0.1)
                {
                    perfFactor = 0.7;
                }
                else
                {
                    perfFactor = 0.5;
                }
            }
            price += perfFactor * faceValue * (1 + annualRate) / Math.Pow((1 + marketRate), factor + YearsTillMaturity());
            return(price);
        }
Beispiel #12
0
        private int YearsTillMaturity()
        {
            ConventionDate today = new ConventionDate();

            return(maturity.Year - today.Year);
        }
Beispiel #13
0
        public double GetPerf(ConventionDate currentDate, ConventionDate previousDate)
        {
            double perf = (spots[currentDate] - spots[previousDate]) / spots[previousDate];

            return(perf > 0 ? perf : 0);
        }