Created
November 30, 2020 15:58
-
-
Save szmeku/3efca6b68c8227ccd547d1710785ddb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import product | |
from timeit import timeit | |
import pandas as pd | |
# data from https://www.cryptodatadownload.com/data/coinbase/ | |
def profit(n, hPeriod, data): | |
return (data[n + hPeriod] - data[n]) / data[n] | |
def isSameSign(a, b): | |
return a * b > 0 | |
def bothGrow(a, b): | |
return a > 0 and b > 0 | |
def bothLoss(a, b): | |
return a < 0 and b < 0 | |
def cryptoPrices(filePath): | |
d = pd.read_csv(filePath, sep=',', skiprows=[0]) | |
return d["Close"] | |
def sameGrowth(p1GrowthPeriod, p2GrowthPeriod, growthsDistance, measurePeriod, p1, p2): | |
lastHour = len(p1) - (p1GrowthPeriod + p2GrowthPeriod + growthsDistance) | |
sameGrowthCounter = 0 | |
measuresCounter = 0 | |
# sameGrowth.counter +=1 | |
for i in range(lastHour - 16000, lastHour, measurePeriod): | |
measuresCounter += 1 | |
if isSameSign(profit(i, p1GrowthPeriod, p1), profit(i + p1GrowthPeriod + growthsDistance, p2GrowthPeriod, p2)): | |
# if bothLoss(profit(i, p1GrowthPeriod, p1), profit(i + p1GrowthPeriod + growthsDistance, p2GrowthPeriod, p2)): | |
# if bothLoss(profit(i, p1GrowthPeriod, p1), profit(i + p1GrowthPeriod + growthsDistance, p2GrowthPeriod, p2)): | |
# if bothLoss(profit(i, p1GrowthPeriod, p1), profit(i + p1GrowthPeriod + growthsDistance, p2GrowthPeriod, p2)): | |
sameGrowthCounter += 1 | |
result = sameGrowthCounter / measuresCounter | |
# print(sameGrowth.counter, result) | |
return result | |
sameGrowth.counter = 0 | |
btcPeriods = range(2, 40, 5) | |
ethPeriods = range(2, 40, 5) | |
growthDistances = range(35, 80, 2) | |
measurePeriods = range(16, 80, 2) | |
testedParameters = list(product(btcPeriods, ethPeriods, growthDistances, measurePeriods)) | |
print(len(testedParameters)) | |
btc = cryptoPrices('./data/Coinbase_BTCUSD_1h.csv') | |
eth = cryptoPrices('./data/Coinbase_ETHUSD_1h.csv') | |
results = list(map(lambda p: (sameGrowth(*p, btc, eth), p), testedParameters)) | |
sortedResults = list(reversed(sorted(results, key=lambda el: el[0]))) | |
for x in sortedResults[0:20]: | |
print(x) | |
for x in sortedResults[-20:]: | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment