crypto: stabilitycheck v1

This commit is contained in:
JP
2018-02-14 21:24:06 +01:00
parent a2f6840079
commit 5bb68ef286
+18 -7
View File
@@ -5,6 +5,7 @@ from urllib import request
import json, requests
import time
import random
import statistics
class Cryptocoin(object):
"""Voor al uw crypto currency advies."""
@@ -31,6 +32,14 @@ class Cryptocoin(object):
a = (sum_of_products - (sum_x * sum_y) / length) / (sum_x_squared - ((sum_x ** 2) / length))
b = (sum_y - a * sum_x) / length
return a, b
#get the stability based on the standard deviation
#the closer to 1, the better. (can be < 0, by the way. sue me.)
def getCoinStability(self, history):
histMean = statistics.mean(history)
if(histMean == 0):
return 0
return 1 - (statistics.stdev(history) / histMean)
def getCoinPrice(self, coinId, currencyId="USD", time="now"):
@@ -74,7 +83,10 @@ class Cryptocoin(object):
growPercentageShortTerm = growFactorShortTerm / history[N_DATAPOINTS-1]
growPercentage = growPercentageLongTerm*0.3 + growPercentageShortTerm*0.7 #weighted average
return growPercentage, history
stability = self.getCoinStability(history)
return growPercentage, stability, history
#TODO:
# - iets met stabiliteit?
@@ -124,20 +136,19 @@ class Cryptocoin(object):
tempName = coinlist[randIndex]["Name"]
#analyse:
growPercentage, tempHistory = self.analyseCoin(tempId)
growPercentage, stability, tempHistory = self.analyseCoin(tempId)
#For the first few iterations we're picky
if (growPercentage > 0.1):
if (growPercentage > 0.1 and stability > 0.5):
return (tempName + " (" + tempId + ") gaat to the moon!")
if (growPercentage > 0.06):
if (growPercentage > 0.06 and stability > 0.25):
return ("Ik zou zeker een paar " + tempName + " (" + tempId + ") kopen.")
if (i > 2):
#Later, negative advices are also acceptable...
if (growPercentage < -0.2):
return ("Ik zou zeker " + tempName + " (" + tempId + ") afraden!")
if (growPercentage > 0.015):
if (growPercentage > 0.015 and stability > 0.15):
return ("Ken je " + tempName + " (" + tempId + ") al? Best leuk")
if(i > 4):
#After a while, we're happy to give less useful advice
@@ -204,7 +215,7 @@ class Cryptocoin(object):
coinId = coinId.upper()
growPercentage, dummy = self.analyseCoin(coinId)
growPercentage, stability, dummy = self.analyseCoin(coinId)
if (growPercentage < -0.1):
yield from ctx.channel.send("Sell! Sell! Sell! " + coinId + " gaat erg slecht.")