Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
.5f %.5f' % (macd[0][-1], macd[1][-1], macd[2][-1]))

# Temporarily MODIFY THE GENOME at the current locus
storage.genome[storage.locus] = allele
# use genome definition to return ideal position
sim_position = genome(
macd[0][-1], macd[1][-1], macd[2][-1], all_bull, all_bear)
# Undo MODIFY THE GENOME
storage.genome[storage.locus] = original_state

# check what each simulation is holding
sim_state = np.argmax(portfolio, axis=1)

# if the the simulator wants to change position
if sim_position != sim_state[allele]:
#if (cut == depth): log('allele %s simulator trade signal: to' % allele)

#update simulated portfolio via the last price
#last[0] 'ltcbtc close'
#last[1] 'ltcusd close'
#last[2] 'btcusd close'
if sim_position == 0:
#if (cut == depth): log('move to usd')
if sim_state[allele] == 1:
#if (cut == depth): log('via btcusd')
portfolio[allele][0] = portfolio[allele][1] * last[2]
portfolio[allele][1] = 0
if sim_state[allele] == 2:
#if (cut == depth): log('via ltcusd')
portfolio[allele][0] = portfolio[allele][2] * last[1]
portfolio[allele][2] = 0

if sim_position == 1:
#if (cut == depth): log('move to btc')
if sim_state[allele] == 0:
#if (cut == depth): log('via btcusd')
portfolio[allele][1] = portfolio[allele][0] / last[2]
portfolio[allele][0] = 0
if sim_state[allele] == 2:
#if (cut == depth): log('via ltcbtc')
portfolio[allele][1] = portfolio[allele][2] * last[0]
portfolio[allele][2] = 0

if sim_position == 2:
#if (cut == depth): log('move to ltc')
if sim_state[allele] == 0:
#if (cut == depth): log('via ltcusd')
portfolio[allele][2] = portfolio[allele][0] / last[1]
portfolio[allele][0] = 0
if sim_state[allele] == 1:
#if (cut == depth): log('via ltcbtc')
portfolio[allele][2] = portfolio[allele][1] / last[0]
portfolio[allele][1] = 0
#if (cut == depth):
# log('sim_position %s' % sim_position)
# log('sim_state %s' % sim_state)
# log(portfolio)

# move postion back to usd at the end of the simulated backtest
sim_state = np.argmax(portfolio, axis=1)
if sim_state[allele] != 0:
if sim_state[allele] == 1:
#if (cut == depth): log('via btcusd')
portfolio[allele][0] = portfolio[allele][1] * last[2]
portfolio[allele][1] = 0
if sim_state[allele] == 2:
#if (cut == depth): log('via ltcusd')
portfolio[allele][0] = portfolio[allele][2] * last[1]
portfolio[allele][2] = 0

log(portfolio)

# determine which allele has highest USD ROI
winner = -1
if portfolio[0][0] > max([portfolio[1][0], portfolio[2][0]]): winner = 0
if portfolio[1][0] > max([portfolio[0][0], portfolio[2][0]]): winner = 1
if portfolio[2][0] > max([portfolio[0][0], portfolio[1][0]]): winner = 2


# if mutation improves ROI
if (winner != original_state) and (winner > -1):
# evolve genome at this locus to winning allele
storag