crypto: more nuance. RSI v1

This commit is contained in:
JP
2018-02-14 22:19:38 +01:00
parent 5bb68ef286
commit bd22485982
+70 -15
View File
@@ -33,6 +33,22 @@ class Cryptocoin(object):
b = (sum_y - a * sum_x) / length b = (sum_y - a * sum_x) / length
return a, b return a, b
#Relative Strength Index (RSI)
def rsi(self, datapoints):
totalGain = 0.0001
totalLoss = 0.0001
n_deltas = len(datapoints)-1
for x in range(0, n_deltas):
delta = datapoints[x+1] - datapoints[x]
if delta > 0:
totalGain += delta
else:
totalLoss -= delta #losses should also be positive
RS = (totalGain / n_deltas) / (totalLoss / n_deltas)
return 100 - ( 100 / (1 + RS) )
#get the stability based on the standard deviation #get the stability based on the standard deviation
#the closer to 1, the better. (can be < 0, by the way. sue me.) #the closer to 1, the better. (can be < 0, by the way. sue me.)
def getCoinStability(self, history): def getCoinStability(self, history):
@@ -206,6 +222,8 @@ class Cryptocoin(object):
Of vraag gewoon advies in het algemeen: Of vraag gewoon advies in het algemeen:
!coinadvice !coinadvice
(Over deze laatste optie moet soms even nagedacht worden) (Over deze laatste optie moet soms even nagedacht worden)
Stroopwafel en zijn development team nemen geen verantwoordelijkheid voor
eventuele financiele schade en verwoeste levens.
""" """
#Geen specieke coin? Doe random. #Geen specieke coin? Doe random.
@@ -215,23 +233,60 @@ class Cryptocoin(object):
coinId = coinId.upper() coinId = coinId.upper()
growPercentage, stability, dummy = self.analyseCoin(coinId) growPercentage, coinStability, coinHistory = self.analyseCoin(coinId)
coinRsi = self.rsi(coinHistory)
#TODO, get more recent data to feed the RSI
if (growPercentage < -0.1): message = ""
yield from ctx.channel.send("Sell! Sell! Sell! " + coinId + " gaat erg slecht.")
elif (growPercentage < -0.03): if (growPercentage < -0.04):
yield from ctx.channel.send("Als je " + coinId + " hebt, verkopen die handel.") if (coinRsi > 70):
message = "Sell! Sell! Sell! Aan " + coinId + " heb je niks meer."
elif (coinStability < 0.3):
message = coinId + " takelt op lange termijn af en is instabiel. Net als je moeder."
elif (coinRsi < 30):
message = "Op de lange termijn is " + coinId + " waardeloos, maar wacht nog even met verkopen."
else:
message = "Als je " + coinId + " hebt, verkopen die handel. Daar heb je op de lange termijn niks aan."
elif (growPercentage < 0): elif (growPercentage < 0):
yield from ctx.channel.send("Het gaat niet zo goed met " + coinId + ".") message = coinId + " gaat geen winnaar worden. "
elif (growPercentage < 0.015): if (coinRsi > 70):
yield from ctx.channel.send(coinId + " lijkt redelijk stabiel.") message += "Ditchen."
elif (growPercentage < 0.035): elif (coinRsi < 30):
yield from ctx.channel.send("Tijd om " + coinId + " te kopen.") message += "Maar hou hem nog even vast."
elif (growPercentage < 0.06): elif (growPercentage < 0.025):
yield from ctx.channel.send(coinId + " groeit snel") if (coinStability > 0.6):
elif (growPercentage < 0.1): message = coinId + " lijkt redelijk stabiel. "
yield from ctx.channel.send("Het gaat heel goed met " + coinId + "!") if (coinRsi < 30):
message += "Bovendien een goed moment om te kopen."
elif (coinRsi > 70):
message = "Ik zou " + coinId + " verkopen."
else:
message = "Niks bijzonders, die " + coinId
elif (growPercentage < 0.08):
if (coinStability > 0.45):
message = coinId + " is een stabiele groeier. "
if (coinRsi < 30):
message += "Nu kopen!"
elif (coinStability < 0.2):
message = coinId + " groeit lekker, maar is instabiel."
else:
message = coinId + " is aan het groeien... "
if (coinRsi > 70):
message += "Hij lijkt overbought, dus je kan nu verkopen."
else: else:
yield from ctx.channel.send("To the moon! " + coinId + " is niet meer te stoppen!") if (coinRsi < 30 and coinStability > 0.4):
message = "TO THE MOON! Nu " + coinId + " kopen!!"
elif (coinStability > 0.7):
message = coinId + " is op de lange termijn erg sterk en stabiel!"
elif (coinRsi < 30):
message = "Ik raad sterk aan om " + coinId + " te kopen."
elif (coinRsi < 70):
message = coinId + " groeit wel erg hard. Wellicht overbought?"
else:
message = coinId + " gaat toenemen in waarde... "
if (coinStability < 0.3):
message += "Denk ik?"
yield from ctx.channel.send(message)