/
xDealCommitment.cs
146 lines (125 loc) · 3.93 KB
/
xDealCommitment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/// <author>
/// Phil Koop, Alastair Wilkins
/// </author>
/// <owner>
/// Alastair Wilkins
/// </owner>
/// <summary>
/// Deal and valuation classes for commitment deals.
/// </summary>
using System;
using SunGard.Adaptiv.Analytics.Framework;
namespace SunGard.Adaptiv.Analytics.Models
{
/// <summary>
/// Commitment deal class.
/// </summary>
[Serializable]
[System.ComponentModel.DisplayName("Commitment")]
public class CommitmentDeal : IRDeal
{
public CommitmentDeal()
: base()
{
Amortisation = new Amortisation();
}
public double Amount
{
get; set;
}
public TDate Effective_Date
{
get; set;
}
public TDate Maturity_Date
{
get; set;
}
[NonMandatory]
public Amortisation Amortisation
{
get; set;
}
/// <summary>
/// Deal end date.
/// </summary>
public override double EndDate()
{
return Maturity_Date;
}
/// <summary>
/// Validate deal properties.
/// </summary>
public override void Validate(ICalendarData calendar, ErrorList errors)
{
base.Validate(calendar, errors);
CalcUtils.ValidateDates(errors, Effective_Date, Maturity_Date, false);
Amortisation.Validate(errors);
}
/// <summary>
/// Deal description constructed from main deal properties.
/// </summary>
public override string Summary()
{
return string.Format("{0} {1:N}", fCurrency, Amount);
}
}
/// <summary>
/// Valuation class for commitment deals.
/// </summary>
[Serializable]
[System.ComponentModel.DisplayName("Commitment Valuation")]
public class CommitmentValuation : IRValuation
{
/// <summary>
/// Type of deals that this class can value.
/// </summary>
public override Type DealType()
{
return typeof(CommitmentDeal);
}
/// <summary>
/// Prepare for valuation anything that will be shared between scenarios.
/// </summary>
public override void PreCloneInitialize(PriceFactorList factors, BaseTimeGrid baseTimes, RequiredResults requiredResults)
{
base.PreCloneInitialize(factors, baseTimes, requiredResults);
CommitmentDeal deal = (CommitmentDeal)Deal;
// Add to valuation time grid
fT.Add(deal.Effective_Date - 1.0);
fT.Add(deal.Effective_Date);
for (int i = 0; i < deal.Amortisation.Count; ++i)
{
fT.AddPayDate(deal.Amortisation[i].Date);
}
}
/// <summary>
/// Calculate valuation profiles.
/// </summary>
public override void Value(ValuationResults valuationResults, PriceFactorList factors, BaseTimeGrid baseTimes)
{
PreValue(factors);
TimeGridIterator tgi = new TimeGridIterator(fT);
PVProfiles result = valuationResults.Profile;
CommitmentDeal deal = (CommitmentDeal)Deal;
VectorEngine.For(tgi, () =>
{
if (tgi.Date < deal.Effective_Date)
{
result.AppendZeroVector(tgi.Date);
}
else
{
double amount = deal.Amortisation.GetPrincipal(deal.Amount, tgi.Date - 1.0);
result.AppendVector(tgi.Date, fFxRate.Get(tgi.T) * amount);
}
});
result.Complete(fT);
}
/// <inheritdoc />
protected override bool DoIsTracingVectorCompatible()
{
return true;
}
}
}