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); }
private ConventionDate GetNextCouponDate(ConventionDate today) { int nextDay = maturity.Day; int nextMonth = GetNextMonth(today); int nextYear = GetNextYear(today, nextMonth); return(new ConventionDate(nextYear, nextMonth, nextDay)); }
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; }
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); }
private int GetNextYear(ConventionDate today, int nextMonth) { if (nextMonth < today.Month) { return(today.Year + 1); } else { return(today.Year); } }
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)); } }
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); }
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); }
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(); } }
public int NumberDays(ConventionDate endDate) { return(360 * (endDate.Year - this.Year) + 30 * (endDate.Month - this.Month) + (endDate.Day - this.Day)); }
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); }
private int YearsTillMaturity() { ConventionDate today = new ConventionDate(); return(maturity.Year - today.Year); }
public double GetPerf(ConventionDate currentDate, ConventionDate previousDate) { double perf = (spots[currentDate] - spots[previousDate]) / spots[previousDate]; return(perf > 0 ? perf : 0); }