-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunderwriting.rb
More file actions
78 lines (70 loc) · 2.37 KB
/
underwriting.rb
File metadata and controls
78 lines (70 loc) · 2.37 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
require_relative 'models'
class Underwriting
def initialize(test_mode: false)
@test_mode = test_mode
end
def preapprove(application)
raise 'expected an Application' unless application.is_a?(Application)
raise 'expected a valid Application' unless application.valid?
if @test_mode
case application.owners[0].first_name
when 'approved'
offers = (0..Random.rand(3)).map do
Offer.new(
loan_approval_amount: [10_000, 20_000, 50_000].sample,
term: [12, 24, 36].sample,
interest_rate: [15.0, 18.0, 21.0].sample,
repayment: ['Daily', 'Weekly', 'Bi-Weekly', 'Monthly'].sample,
origination_fee: [1.0, 2.0].sample,
miscellaneous_fee: [100, 200, 300].sample
)
end
return Decision.new(decision: 'preapproved', offers: offers)
when 'pending'
return Decision.new(decision: 'pending')
when 'declined'
return Decision.new(decision: 'declined', rejection_reason: 'testing')
when 'crash'
raise 'oops, something went wrong'
end
end
if %w(NV VT PR DC).include?(application.company.state)
return Decision.new(decision: 'declined', rejection_reason: "can't lend to businesses in #{application.company.state}")
end
loan_amounts_and_terms =
if application.company.annual_revenue > 500_000
[
[40_000, 12],
[70_000, 24],
[100_000, 36]
]
elsif application.company.annual_revenue > 200_000
[[20_000, 12]]
end
unless loan_amounts_and_terms
return Decision.new(decision: 'declined', rejection_reason: 'annual revenue is too low')
end
interest_rate =
case application.owners[0].credit_score
when 'Excellent (700+)', 'Excellent (660-699)'
15.0
when 'Good (640-659)', 'Good (620-639)'
18.0
when 'Fair (580-619)'
21.0
end
unless interest_rate
return Decision.new(decision: 'declined', rejection_reason: 'owner credit is too low')
end
offers = loan_amounts_and_terms.map do |loan_amount, term|
Offer.new(
loan_approval_amount: loan_amount,
term: term,
interest_rate: interest_rate,
repayment: term > 12 ? 'Monthly' : 'Daily',
origination_fee: 1.0
)
end
Decision.new(decision: 'preapproved', offers: offers)
end
end