Skip to content

Instantly share code, notes, and snippets.

@sam-thecoder
Created August 9, 2018 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam-thecoder/bccf2dcea2817ea81b8757169c59a0a2 to your computer and use it in GitHub Desktop.
Save sam-thecoder/bccf2dcea2817ea81b8757169c59a0a2 to your computer and use it in GitHub Desktop.
def player_1(start_date=None, 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_date=start_date)
#print(user_key)
prev_predict = day_info[-1]
miss_colors = ['g']
while game_active == False:
#print(day_info[-1])
if day_info[-1] == 2: #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)
elif invested < hold_max and amount > 100: #invest 20
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_min)
elif invested > hold_max: #withdraw 500
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max)
else:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_min*2)
elif day_info[-1] == 1 or day_info[-1] == 0: #50/50 good odds
#print('second option')
if invested > hold_max:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max)
elif invested > 500:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max/5)
elif invested > 200:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min)
elif invested > 100:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_min)
else:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_min)
elif day_info[-1] == -1: #bad odds but the market might pick up
#print('third option')
if invested > hold_max:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max)
elif invested > 500:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max/5)
elif invested > 200:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min*2)
elif invested > 100:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min*3)
elif invested > 50:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min)
else:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_min)
elif day_info[-1] == -2: #you should be alarmed, the bubble might be bursting
#print('fourth option')
if invested > hold_max:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max)
elif invested > 500:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_max/5)
elif invested > 200:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min*4)
elif invested > 100:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min*3)
elif invested > 50:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, withdraw_amount=withdraw_min*2)
else:
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(user_key=user_key, invest_amount=withdraw_min)
if output:
print('day: {0} profit: {1} loss: {2} amount: {3} invested: {4} predict: {5}'.format(day_info[0], profit, loss, amount, invested, day_info[-1]))
prev_predict = day_info[-1]
#loss day: 1/24/2018 profit: 3.4399999999999977 loss: 0 amount: 950.0 invested: 36.94 predict: 0
if miss_plot:
low_ball = day_info[-1] == -75 or day_info[-1] == -50
high_ball = day_info[-1] == 50 or day_info[-1] == 0
if low_ball and profit > 0 or high_ball and loss > 0:
miss_colors.append('r')
else:
miss_colors.append('g')
if miss_output:
low_ball = day_info[-1] == -75 or day_info[-1] == -50
high_ball = day_info[-1] == 50 or day_info[-1] == 0
if low_ball and profit > 0:
print('profit day: {0} profit: {1} loss: {2} amount: {3} invested: {4} predict: {5}'.format(day_info[0], profit, loss, amount, invested, day_info[-1]))
elif high_ball and loss > 0:
print('loss day: {0} profit: {1} loss: {2} amount: {3} invested: {4} predict: {5}'.format(day_info[0], profit, loss, amount, invested, day_info[-1]))
#so I can easily assess what's going on
if sleep:
time.sleep(sleep_time)
if not output: #only one output
print('day: {0} profit: {1} loss: {2} amount: {3} invested: {4}'.format(day_info[0], profit, loss, amount, invested))
if plot or miss_plot:
if start_date:
result = df[df['Date'] == start_date].index.tolist()
if result:
start_index = result[0]
else:
start_index = 0
else:
start_index = 0
df_copy = df[df.index >= start_index].copy()
df_copy['time'] = pd.to_datetime(df_copy['Date'], format='%m/%d/%Y')
player_record = game_record['player_{0}'.format(user_key)]
miss_colors.append('g')
if miss_plot:
#make plot bigger
plt.rcParams['figure.figsize'] = (40,20)
index = []
count = 0
for color in miss_colors:
if color == 'r':
index.append(count)
count+=1
#colors = ['r']*miss_colors.count('r')
#df_copy.plot(kind='scatter', x=df_copy.index.tolist(), y='amount', figsize=(20, 20), colormap=miss_colors)
#plt.plot(x=df_copy.index, y=df_copy['Value USD'])
plt.scatter(x=index, y=df_copy.iloc[index]['Value USD'], c='r', s=80)
plt.plot(df_copy.index, df_copy['Value USD'], 'g')
plt.show()
if plot:
try:
#the len seems to be off by 3
extended_invest = player_record['invest_history']
extended_invest.extend([extended_invest[-1]]*3)
extended_amount = player_record['amount_history']
extended_amount.extend([extended_amount[-1]]*2)
df_copy['investment'] = extended_invest
df_copy['amount'] = extended_amount
df_copy.plot(x='', y=['investment', 'amount', 'Value USD'], figsize=(20, 20))
except Exception as e:
print(str(e))
print('df copy shape', df_copy.shape)
print('investment len', len(extended_invest))
print('amount len', len(extended_amount))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment