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 json, requests
import time import time
import random import random
import statistics
class Cryptocoin(object): class Cryptocoin(object):
"""Voor al uw crypto currency advies.""" """Voor al uw crypto currency advies."""
@@ -32,6 +33,14 @@ class Cryptocoin(object):
b = (sum_y - a * sum_x) / length b = (sum_y - a * sum_x) / length
return a, b 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"): def getCoinPrice(self, coinId, currencyId="USD", time="now"):
if (time == "now"): #for the most current price, don't use the history API if (time == "now"): #for the most current price, don't use the history API
@@ -74,7 +83,10 @@ class Cryptocoin(object):
growPercentageShortTerm = growFactorShortTerm / history[N_DATAPOINTS-1] growPercentageShortTerm = growFactorShortTerm / history[N_DATAPOINTS-1]
growPercentage = growPercentageLongTerm*0.3 + growPercentageShortTerm*0.7 #weighted average growPercentage = growPercentageLongTerm*0.3 + growPercentageShortTerm*0.7 #weighted average
return growPercentage, history
stability = self.getCoinStability(history)
return growPercentage, stability, history
#TODO: #TODO:
# - iets met stabiliteit? # - iets met stabiliteit?
@@ -124,20 +136,19 @@ class Cryptocoin(object):
tempName = coinlist[randIndex]["Name"] tempName = coinlist[randIndex]["Name"]
#analyse: #analyse:
growPercentage, tempHistory = self.analyseCoin(tempId) growPercentage, stability, tempHistory = self.analyseCoin(tempId)
#For the first few iterations we're picky #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!") 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.") return ("Ik zou zeker een paar " + tempName + " (" + tempId + ") kopen.")
if (i > 2): if (i > 2):
#Later, negative advices are also acceptable... #Later, negative advices are also acceptable...
if (growPercentage < -0.2): if (growPercentage < -0.2):
return ("Ik zou zeker " + tempName + " (" + tempId + ") afraden!") 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") return ("Ken je " + tempName + " (" + tempId + ") al? Best leuk")
if(i > 4): if(i > 4):
#After a while, we're happy to give less useful advice #After a while, we're happy to give less useful advice
@@ -204,7 +215,7 @@ class Cryptocoin(object):
coinId = coinId.upper() coinId = coinId.upper()
growPercentage, dummy = self.analyseCoin(coinId) growPercentage, stability, dummy = self.analyseCoin(coinId)
if (growPercentage < -0.1): if (growPercentage < -0.1):
yield from ctx.channel.send("Sell! Sell! Sell! " + coinId + " gaat erg slecht.") yield from ctx.channel.send("Sell! Sell! Sell! " + coinId + " gaat erg slecht.")