This repository has been archived by the owner on Aug 7, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
algorithm.py
84 lines (56 loc) · 1.5 KB
/
algorithm.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
73
74
75
76
77
78
79
80
81
82
83
84
import math
def calculate(new, old, net_worth):
new = float(new)
old = float(old)
net_worth = 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 = 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) / 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
def break_even(upvotes):
y = upvotes
x = y
newFactor = calculate(x, y, 100)
while newFactor < 1:
x += 1
newFactor = calculate(x, y, 100)
return x