This repository was archived by the owner on Oct 14, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathformula.py
67 lines (49 loc) · 1.53 KB
/
formula.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
import math
from fastnumbers import fast_float
def calculate(new, old, net_worth):
new = fast_float(new)
old = fast_float(old)
net_worth = fast_float(net_worth)
# Treat anything below 0 upvotes as 0 upvotes
if old < 0:
old = 0
if new < 0:
new = 0
# Compute gain
delta = new - old
# Treat negative gain as no gain
if delta < 0:
delta = 0
# Compute the maximum of the sigmoid
sig_max = sigmoid_max(old)
# Compute the midpoint of the sigmoid
sig_mp = sigmoid_midpoint(old)
# Compute the steepness of the sigmoid
sig_stp = sigmoid_steepness(old)
# Calculate return
factor = sigmoid(delta, sig_max, sig_mp, sig_stp)
# Normalize between -1 and 1
factor = factor - 1
# Adjust based on net worth
factor = factor * net_worth_coefficient(net_worth)
# Return investment amount multiplier (change + 1)
return factor + 1
def sigmoid(x, maxvalue, midpoint, steepness):
arg = -(steepness * (x - midpoint))
y = fast_float(maxvalue) / ( 1 + math.exp(arg) )
return y
def sigmoid_max(old):
return 1.2 + 0.6 / ((old / 10) + 1)
def sigmoid_midpoint(old):
sig_mp_0 = 10
sig_mp_1 = 500
return linear_interpolate(old, 0, 25000, sig_mp_0, sig_mp_1)
def sigmoid_steepness(old):
return 0.06 / ((old / 100) + 1)
def linear_interpolate(x, x_0, x_1, y_0, y_1):
m = (y_1 - y_0) / fast_float(x_1 - x_0)
c = y_0
y = (m * x) + c
return y
def net_worth_coefficient(net_worth):
return net_worth ** -0.155 * 6