Skip to content

Instantly share code, notes, and snippets.

@sam-thecoder
Created August 7, 2018 08:20
Show Gist options
  • Save sam-thecoder/5ef170f07f8e8e4c6553c0929cfa930f to your computer and use it in GitHub Desktop.
Save sam-thecoder/5ef170f07f8e8e4c6553c0929cfa930f to your computer and use it in GitHub Desktop.
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:
print('Error', str(e))
print('results of program', bitcoin_game(user_key=user_key))
if output:
print('day: {0} profit: {1} loss: {2} amount: {3} invested: {4}'.format(day_info[0], profit, loss, amount, invested))
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:
try:
df_copy = df[df.index >= start_index].copy()
player_record = game_record['player_{0}'.format(user_key)]
#the len seems to be off by 3
extended_invest = player_record['invest_history']
extended_invest.extend([extended_invest[-1]]*3)
df_copy['time'] = pd.to_datetime(df_copy['Date'], format='%m/%d/%Y')
df_copy['investment'] = extended_invest
df_copy.plot(x='time', y=['investment', '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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment