-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoan.cs
More file actions
85 lines (70 loc) · 2.67 KB
/
Loan.cs
File metadata and controls
85 lines (70 loc) · 2.67 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loan_Projection
{
enum LoanStatus { Active, Delinquent, Sold };
class Loan
{
public long Id;
public Account Owner;
public DateTime AsOfDate;
public double UnpaidBalance;
public double PaymentAmount;
public LoanStatus Status;
public DateTime delinquencyExpiration;
private static Random rand = new Random();
public static Loan Build(string[] info)
{
Loan output = new Loan();
output.Id = long.Parse(info[0]);
output.AsOfDate = DateTime.Parse(info[2]);
output.UnpaidBalance = double.Parse(info[3]);
output.PaymentAmount = double.Parse(info[4]);
output.Status = (LoanStatus)Enum.Parse(typeof(LoanStatus), info[5]);
if (output.Status == LoanStatus.Delinquent)
output.delinquencyExpiration = output.AsOfDate.AddYears(2);
return output;
}
public LoanIterationResult Iterate(DateTime currentDate)
{
if (Status == LoanStatus.Delinquent)
{
if(currentDate > delinquencyExpiration) // time to sell off the loan
{
Status = LoanStatus.Sold;
return new LoanIterationResult(LoanStatus.Sold, UnpaidBalance / 2);
}
else
return new LoanIterationResult(LoanStatus.Delinquent, PaymentAmount);
}
if (Status == LoanStatus.Sold)
return new LoanIterationResult(LoanStatus.Sold, 0);
// currently active
// sell off loan
if(rand.NextDouble() < 0.01)
{
LoanIterationResult output = new LoanIterationResult(LoanStatus.Active, UnpaidBalance); // leave as Active in result b/c payment
Status = LoanStatus.Sold;
UnpaidBalance = 0;
return output;
}
// goes delinquent
else if(rand.NextDouble() < 0.02)
{
Status = LoanStatus.Delinquent;
delinquencyExpiration = currentDate.AddYears(2);
return new LoanIterationResult(LoanStatus.Delinquent, PaymentAmount);
}
// make payment
else
{
double thisPayment = UnpaidBalance > 0.8 * PaymentAmount ? 0.8 * PaymentAmount : UnpaidBalance;
UnpaidBalance -= thisPayment;
return new LoanIterationResult(LoanStatus.Active, thisPayment);
}
}
}
}