CLEAN
Valuation library for mortgage-backed securities
structs.h
1 // -*-C++-*- make sure Emacs is in C++ mode
13 #ifndef INCLUDED_ANDREW_KALOTAY_ASSOCIATES_CLEAN_STRUCTS_H
14 #define INCLUDED_ANDREW_KALOTAY_ASSOCIATES_CLEAN_STRUCTS_H
15 
16 #include "andrew_kalotay_associates/clean/dll_macros.h"
17 #include "andrew_kalotay_associates/common/enums.h"
18 #include "andrew_kalotay_associates/common/structs.h"
19 #include "andrew_kalotay_associates/common/array.h"
20 #include "andrew_kalotay_associates/common/optional.h"
21 
22 namespace AndrewKalotayAssociates
23 {
24  namespace Clean
25  {
35 
36  namespace Input
37  {
46 
68  struct CLEAN_API PrepaymentModelParameters
69  {
70  double laggard_spread_spacing;
71  double laggard_decay_factor;
72  double refinancing_cost; // As fraction of original principal
73 
74  Common::Array<double> turnover_speeds;
75  Common::Array<double> curtailment_speeds;
76  Common::Array<double> default_speeds;
77  Common::Array<double> default_recovery_rates;
78 
79  double homeowner_credit_spread;
80 
82  :laggard_spread_spacing(0.0027),
83  laggard_decay_factor(0.678),
84  refinancing_cost(0.01),
85  turnover_speeds(1, 0.06),
86  curtailment_speeds(1, 0.0),
87  default_speeds(standard_default_assumption(1.0)),
88  default_recovery_rates(1, 1.0),
89  homeowner_credit_spread(0.0)
90  {}
91 
92  PrepaymentModelParameters(double this_homeowner_credit_spread,
93  double sda_multiplier = 1.0,
94  double default_recovery_rate = 1.0,
95  double this_turnover_speed = 0.06,
96  double this_curtailment_speed = 0.0,
97  double this_refinancing_cost = 0.01,
98  double this_laggard_spread_spacing = 0.0027,
99  double this_laggard_decay_factor = 0.678)
100  :laggard_spread_spacing(this_laggard_spread_spacing),
101  laggard_decay_factor(this_laggard_decay_factor),
102  refinancing_cost(this_refinancing_cost),
103  turnover_speeds(1, this_turnover_speed),
104  curtailment_speeds(1, this_curtailment_speed),
105  default_speeds(standard_default_assumption(sda_multiplier)),
106  default_recovery_rates(1, default_recovery_rate),
107  homeowner_credit_spread(this_homeowner_credit_spread)
108  {}
109 
118  static
120  prepayment_speed_assumption(double multiplier = 1.0,
121  double peak_speed = 0.06,
122  double stable_speed = 0.06,
123  long periods_to_peak = 30,
124  long periods_at_peak = 1,
125  long periods_to_stable = 1);
126 
128  static
130  standard_default_assumption(double multiplier = 1.0,
131  double peak_default_speed = 0.006,
132  double stable_default_speed = 0.0004,
133  long periods_to_peak = 30,
134  long periods_at_peak = 30,
135  long periods_to_stable = 60);
136 
137  static
139  ramped_speeds(double multiplier,
140  double peak_speed,
141  double stable_speed,
142  long periods_to_peak,
143  long periods_at_peak,
144  long periods_to_stable);
145  };
146 
148  struct COMMON_API InterestRateModelParameters
149  {
153  {
154  very_dense_lattice = -2,
155  dense_lattice = -1,
156  default_lattice = 0,
157  sparse_lattice = 1,
158  very_sparse_lattice = 2,
159  extremely_sparse_lattice = 3,
160  extremely_extremely_sparse_lattice = 4
161  };
162 
163  enum model_type
164  {
165  lognormal_lattice_1d = 0,
166  normal_lattice_1d = 1,
167  shifted_lognormal_lattice_1d = 2
168  };
169 
172 
175 
177  model_type model;
178 
181 
183  bool vol_risk;
184 
187  double shift;
188 
191 
192  InterestRateModelParameters(long this_payment_lag_in_days = 0,
193  density_type this_density = default_lattice,
194  model_type this_model = lognormal_lattice_1d,
195  bool this_effective_risk = false,
196  bool this_vol_risk = false,
197  double this_shift = 0)
198  :payment_lag_in_days(this_payment_lag_in_days),
199  density(this_density),
200  model(this_model),
201  effective_risk(this_effective_risk),
202  vol_risk(this_vol_risk),
203  shift(0)
204  {}
205  };
206 
208  struct CLEAN_API Mbs
209  {
210  double mbs_coupon;
211  double mortgage_coupon;
212  double original_amortization_in_months;
213  double remaining_amortization_in_months;
214  double remaining_life_in_months;
215  double age_in_months;
216  double factor;
217 
220 
221  Mbs()
222  :mbs_coupon(0),
223  mortgage_coupon(0),
224  original_amortization_in_months(0),
225  remaining_amortization_in_months(0),
226  remaining_life_in_months(0),
227  age_in_months(0),
228  factor(0),
229  principal_multiplier(1.0)
230  {}
231 
232  };
233 
235 
236 
237  struct CLEAN_API ValuationSelection
238  {
239  bool effective_risk;
240  bool vol_risk;
241  bool oas_risk;
242  bool homeowner_credit_spread_risk;
243 
244  Common::Array<TimeDifference> partial_duration_maturities;
245  Common::Array<TimeDifference> prepayment_speed_periods;
246 
248  :effective_risk(false),
249  vol_risk(false),
250  oas_risk(false),
251  homeowner_credit_spread_risk(false)
252  {}
253  };
254 
256  }
257 
258 
259 
260  namespace Output
261  {
266 
269  struct CLEAN_API PrepaymentSpeed
270  {
271  TimeDifference period;
272  double speed;
273  };
274 
276  struct CLEAN_API Cashflow
277  {
278  int period;
279  double principal_remaining;
280  double amortization;
281  double liquidation;
282  double defaults;
283  double curtailment;
284  double interest;
285 
286  Cashflow()
287  :period(0),
288  principal_remaining(0),
289  amortization(0),
290  liquidation(0),
291  defaults(0),
292  curtailment(0),
293  interest(0)
294  {}
295  };
296 
297  struct CLEAN_API Cashflows
298  {
299  Common::Array<Cashflow> cashflows() const
300  {
301  return cashflows_;
302  }
303 
304  Output::Status status() const
305  {
306  return status_;
307  }
308 
310  void set(Common::Array<Cashflow> cashflows)
311  {
312  cashflows_ = cashflows;
313  }
314 
315  void set(Output::Status status)
316  {
317  status_ = status;
318  }
319  private:
320  Common::Array<Cashflow> cashflows_;
321  Output::Status status_;
322  };
323 
326  struct CLEAN_API Price
327  {
328  double clean_price;
329  double accrued_interest;
330  double dirty_price;
331  double oas;
332 
333  double refinancing_value;
334 
335  Status status() const
336  {
337  return status_;
338  }
339 
341  void set(Status status)
342  {
343  status_ = status;
344  }
345 
346  private:
347  Status status_;
348  };
349 
352  struct CLEAN_API ValuationReport
353  {
354  Status status() const
355  {
356  return price_.status();
357  }
358 
359  Price price() const
360  {
361  return price_;
362  }
363 
364  Common::Optional<Risk> effective_risk() const
365  {
366  return effective_risk_;
367  }
368 
369  Common::Optional<Risk> oas_risk() const
370  {
371  return oas_risk_;
372  }
373 
374  Common::Optional<Risk> homeowner_credit_spread_risk() const
375  {
376  return homeowner_credit_spread_risk_;
377  }
378 
379  Common::Optional<Risk> vol_risk() const
380  {
381  return vol_risk_;
382  }
383 
384  Common::Array<PartialDuration> partial_durations() const
385  {
386  return partial_durations_;
387  }
388 
389  Common::Array<PrepaymentSpeed> average_prepayment_speeds() const
390  {
391  return average_prepayment_speeds_;
392  }
393 
394  Common::Optional<double> expected_life() const
395  {
396  return expected_life_;
397  }
398 
400  void set(Status status)
401  {
402  price_.set(status);
403  }
404  void set(Price price)
405  {
406  price_ = price;
407  }
408  void set_effective_risk(Risk effective_risk)
409  {
410  effective_risk_ = effective_risk;
411  }
412  void set_oas_risk(Risk oas_risk)
413  {
414  oas_risk_ = oas_risk;
415  }
416  void set_homeowner_credit_spread_risk(Risk homeowner_credit_spread_risk)
417  {
418  homeowner_credit_spread_risk_ = homeowner_credit_spread_risk;
419  }
420  void set_vol_risk(Risk vol_risk)
421  {
422  vol_risk_ = vol_risk;
423  }
424  void set(Common::Array<PartialDuration> partial_durations)
425  {
426  partial_durations_ = partial_durations;
427  }
428  void set(Common::Array<PrepaymentSpeed> average_prepayment_speeds)
429  {
430  average_prepayment_speeds_ = average_prepayment_speeds;
431  }
432  void set_expected_life(double expected_life)
433  {
434  expected_life_ = expected_life;
435  }
436 
437  private:
438  Price price_;
439  Common::Optional<Risk> effective_risk_;
440  Common::Optional<Risk> oas_risk_;
441  Common::Optional<Risk> homeowner_credit_spread_risk_;
442  Common::Optional<Risk> vol_risk_;
443  Common::Array<PartialDuration> partial_durations_;
444  Common::Array<PrepaymentSpeed> average_prepayment_speeds_;
445  Common::Optional<double> expected_life_;
446  };
447 
450  struct CLEAN_API CashflowReport
451  {
453  Price price() const
454  {
455  return price_;
456  }
457 
458  Common::Array<BondCashflow> cashflows() const
459  {
460  return cashflows_;
461  }
462 
463  Status status() const
464  {
465  return status_;
466  }
467 
469  void set(Price price)
470  {
471  price_ = price;
472  }
473 
474  void set(Common::Array<BondCashflow> cashflows)
475  {
476  cashflows_ = cashflows;
477  }
478 
479  void set(Status status)
480  {
481  status_ = status;
482  }
483 
484  private:
485  Price price_;
486  Common::Array<BondCashflow> cashflows_;
487  Status status_;
488  };
489 
492  struct CLEAN_API YieldReport
493  {
494  double price;
495  double accrued_interest;
496  double yield;
497  Risk modified_risk;
498  double expected_life;
499 
500  Status status() const
501  {
502  return status_;
503  }
504 
506  void set(Status status)
507  {
508  status_ = status;
509  }
510 
511  private:
512  Status status_;
513  };
514 
517  struct CLEAN_API ScenarioAnalysisReport
518  {
519  double initial_value;
520  double principal_income;
521  double interest_income;
522  double reinvestment_income;
523  double final_value;
524  double annualized_rate_of_return;
525 
526  Status status() const
527  {
528  return status_;
529  }
530 
532  void set(Status status)
533  {
534  status_ = status;
535  }
536 
537  private:
538  Status status_;
539  };
540  }
541  }
542 }
543 
544 #endif
Parametesrs needed by InterestRateModel constructor.
Definition: structs.h:149
density_type density
Density of lattice.
Definition: structs.h:174
model_type model
Model type: lognormal, shifted lognormal, or normal.
Definition: structs.h:177
long payment_lag_in_days
Number of days from mortgage payment to MBS coupon payment.
Definition: structs.h:171
bool effective_risk
Set to true if effective duration and convexity will be calculated.
Definition: structs.h:180
bool vol_risk
Set to true if vol risk (vega) will be calcukated.
Definition: structs.h:183
Common::Array< TimeDifference > partial_duration_maturities
Maturities of partial durations to be calculated.
Definition: structs.h:190
Terms of a pass-through MBS.
Definition: structs.h:209
double principal_multiplier
Set to 1 if pass-through and to 0 if IO.
Definition: structs.h:219
static Common::Array< double > prepayment_speed_assumption(double multiplier=1.0, double peak_speed=0.06, double stable_speed=0.06, long periods_to_peak=30, long periods_at_peak=1, long periods_to_stable=1)
static Common::Array< double > standard_default_assumption(double multiplier=1.0, double peak_default_speed=0.006, double stable_default_speed=0.0004, long periods_to_peak=30, long periods_at_peak=30, long periods_to_stable=60)
Create default speed curve analogous to the SDA curve.
Cashflow broken down by cause.
Definition: structs.h:277
void set(Price price)
For internal use only.
Definition: structs.h:469
Price price() const
Accessors.
Definition: structs.h:453
void set(Common::Array< Cashflow > cashflows)
For internal use only.
Definition: structs.h:310
void set(Status status)
For internal use onky.
Definition: structs.h:341
void set(Status status)
For internal use only.
Definition: structs.h:532
void set(Status status)
For internal use only.
Definition: structs.h:400
void set(Status status)
For internal use only.
Definition: structs.h:506
Forward currency rate.
Definition: structs.h:298
Discount factor curve.
Definition: structs.h:289
Bond price quote.
Definition: structs.h:702
Used to specify a yield in a yield curve.
Definition: structs.h:163
Duration and convexity.
Definition: structs.h:843