Skip to content

Instantly share code, notes, and snippets.

View sam-thecoder's full-sized avatar

Samuel M. sam-thecoder

View GitHub Profile
def count_drop(numbers):
return len([x for x in numbers if x < 0])
def count_up(numbers):
return len([x for x in numbers if x > 0])
df.rename(columns={'Value': 'Value USD'}, inplace=True)
df['Value 2'] = df['Value USD'].shift(-1)
df['Max 7'] = df['Value USD'].rolling(7).max()
df['Min 7'] = df['Value USD'].rolling(7).min()
main_key = 0
game_record = {}
predictions = {
2: {'loss': 0, 'profit': 0, 'draw': 0},
1: {'loss': 0, 'profit': 0, 'draw': 0},
0: {'loss': 0, 'profit': 0, 'draw': 0},
-1: {'loss': 0, 'profit': 0, 'draw': 0},
-2: {'loss': 0, 'profit': 0, 'draw': 0}
}
##Add Reward Cycle last
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
df = pd.read_csv('data/BCHAIN.csv')
df_copy = df.copy()
#Not needed for prediction
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import linear_model
df = pd.read_csv('data/BCHAIN.csv')
df_copy = df.copy()
#Not needed for prediction
def player_2(start_index=0, sleep=False, sleep_time=1, plot=False, output=True, miss_output=False, miss_plot=False, show_exception=True):
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(start_index=start_index)
peak_price = day_info[1]
min_price = day_info[4]
max_price = day_info[5]
mean_price = day_info[6]
invest = None
max_profit = invested
def lazy_investor(start_index=0, output=False, plot=True, amount=1000):
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(start_index=start_index)
while game_active == False:
if amount > 100:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=amount-100)
#print(bitcoin_game(user_key=user_key, invest_amount=amount-100))
else:
try:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key)
except Exception as e:
def player_1(start_index=0, miss_output=False, miss_plot=False, sleep=False, sleep_time=1, plot=False, output=True, hold_max=1000, withdraw_max=500, withdraw_min=10):
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(start_index=start_index)
prev_predict = day_info[-1]
miss_colors = ['g']
while game_active == False:
#print(day_info[-1])
if day_info[-1] == 0: #equilavent of 100 i.e. good odds
#print('first option')
if invested < 100: #invest 100
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_max/5)
main_key = 0
game_record = {}
##Add Reward Cycle last
def bitcoin_game(user_key=None, amount=1000, start_index=0, invest_amount=None, withdraw_amount=None):
global main_key, game_record
#print(user_key)
if user_key == None:
player_name = 'player_{0}'.format(main_key)
def count_drop(numbers):
return len([x for x in numbers if x < 0])
def count_up(numbers):
return len([x for x in numbers if x > 0])
df['Change'] = df['Value USD'] - df['Value 2']
df.drop('Value 2', axis=1, inplace=True)
#Change for the past 7 days
df['Mean Change 7'] = df['Change'].rolling(7).mean()
def decider(row):
if row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] > 0 and row['Change'] > 0:
return 0 #invest/hold or put in 100 investment if none
#Withdraw 50%
elif row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] > 0 and row['Change'] < 0:
return -50
#Withdraw 75%
elif row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] < 0 or row['Change'] < 0:
return -75
#invest 50% more