-
Notifications
You must be signed in to change notification settings - Fork 9
/
default_strategies.py
73 lines (62 loc) · 2.22 KB
/
default_strategies.py
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
__version__ = '3.0'
__author__ = 'Jason Ansel ([email protected])'
__copyright__ = '(C) 2012-2014. GNU GPL 3.'
from lendingclub import SellStrategy
import logging
try:
import marketmodel
except ImportError:
marketmodel = None
log = logging.getLogger(__name__)
class SellImperfect(SellStrategy):
def sale_price(self, note, markup=None):
if marketmodel is None or marketmodel.MarketModel.instance() is None:
return note.par_value() * markup
model = marketmodel.MarketModel.instance()
trading_row = note.to_trading_row_format()
price = model.predict_sale_price_trading_row(trading_row,
confidence=0.4,
min_markup=0.98,
max_markup=1.25)
try:
log.info('Sale: %.2f markup=%.2f %s neverlate=%s rate=%s, '
'credit_delta=%s sell_proba=%.2f',
price, price / note.par_value(), trading_row['Status'],
trading_row['NeverLate'], trading_row['Interest Rate'],
note.creditdeltamin(),
model.sell_proba_trading_row(trading_row, price=price))
except Exception:
log.exception('Eeek!')
return price
def initial_filter(self, note):
return note.can_sell()
def details_filter(self, note):
"""
Sell all notes with any sort of imperfection
"""
if not note.can_sell():
self.reasons['cant sell'] += 1
return False
if len(note.collection_log) > 0:
s = repr(note.collection_log).lower()
if 'failed' in s:
self.reasons['failed payment'] += 1
else:
self.reasons['collections log'] += 1
return True
late = note.get_late_payments()
if late:
if filter(lambda x: x.status not in ('Completed - in grace period',),
late):
self.reasons['late payment'] += 1
else:
self.reasons['payment in grace period'] += 1
return True
if note.credit_history:
if note.creditdeltamin() < -120:
self.reasons['credit score drop >120'] += 1
return True
elif note.creditdeltamin() < -80:
self.reasons['credit score drop >80'] += 1
return True
return False