def get_profit(datadata, datalimits): [ data, data_length, body_sizes, shadow_sizes, body_shadow_ratios, reversals, increase_data, run_function_data ] = datadata [ body_lim, shadow_lim, ratio_lim, prev_run_lim, prev_diff_lim, next_run_lim, next_diff_lim ] = datalimits # 0 for sell, 1 for buy last_trade = 0 trade_array = [0] * data_length for i in range(datadata[1]): if (last_trade == 0): if ((reversals[i] == 1) and (increase_data[i] == 1) and (body_sizes[i] <= body_lim) and (shadow_sizes[i] <= shadow_lim) and (body_shadow_ratios[i] <= ratio_lim) and (run_function_data[i][1] >= prev_run_lim) and (run_function_data[i][2] >= prev_diff_lim) and (run_function_data[i][3] >= next_run_lim) and (run_function_data[i][4] >= next_diff_lim)): trade_array[i] += 1 last_trade = 1 elif (last_trade == 1): if (reversals[i] == 1): trade_array[i] += 2 last_trade = 0 [profit, profit_array] = tradesim.sim_trade(data, trade_array) return (profit)
def get_profit(datadata, datalimits, combined_trade_array): [ jdata, data_length, body_sizes, shadow_sizes, body_shadow_ratios, reversals, increase_data, run_function_data ] = datadata [body_lim, shadow_lim, ratio_lim, prev_run_lim, prev_diff_lim] = datalimits # 0 for sell, 1 for buy last_trade = 0 trade_array = [0] * data_length for i in range(datadata[1]): if (last_trade == 0): if ((reversals[i] == 1) and (increase_data[i] == 1) and (body_sizes[i] <= body_lim[1]) and (body_sizes[i] >= body_lim[0]) and (shadow_sizes[i] <= shadow_lim[1]) and (shadow_sizes[i] >= shadow_lim[0]) and (body_shadow_ratios[i] <= ratio_lim[1]) and (body_shadow_ratios[i] >= ratio_lim[0]) and (run_function_data[i][1] <= prev_run_lim[1]) and (run_function_data[i][1] >= prev_run_lim[0]) and (run_function_data[i][2] <= prev_diff_lim[1]) and (run_function_data[i][2] >= prev_diff_lim[0])): trade_array[i] += 1 last_trade = 1 elif (last_trade == 1): if (reversals[i] == 1): trade_array[i] += 2 last_trade = 0 [profit, profit_array] = tradesim.sim_trade(jdata, trade_array) if profit > 1: temp_combined_trade_array = [None] * data_length for i in range(data_length): if trade_array[i] > 0: temp_combined_trade_array[i] = trade_array[i] [com_profit, com_profit_array] = tradesim.sim_trade(jdata, combined_trade_array) [temp_profit, temp_profit_array] = tradesim.sim_trade(jdata, temp_combined_trade_array) if temp_profit > com_profit: combined_trade_array = temp_combined_trade_array return ([profit, combined_trade_array])
import tradesim import csv trade_filepath = '../../data/tradedata/Heikenashispintopsbuyorsell.csv' with open(trade_filepath, 'rb') as trade_file: trade_array = [] trade_file_data = csv.reader(trade_file, delimiter=',') for row in trade_file_data: trade_array.append(int(row[0])) data_filepath = '../../data/hacandles.csv' data = getanalysis.import_j_candles(data_filepath) [profit, profit_array] = tradesim.sim_trade(data, trade_array) percent_profit = (profit - 1) * 100 print('Heikin Ashi spinning tops') print('Profit: ' + str(percent_profit) + '%') print('Max profit: ' + str((max(profit_array)-1)*100) + '%\n') trade_filepath = '../../data/tradedata/ha-candles-bear-and-bull-dojis.csv' with open(trade_filepath, 'rb') as trade_file: trade_array = [] trade_file_data = csv.reader(trade_file, delimiter=',') for row in trade_file_data: trade_array.append(int(row[0])) [profit, profit_array] = tradesim.sim_trade(data, trade_array) percent_profit = (profit - 1) * 100 print('Heikin Ashi dojis') print('Profit: ' + str(percent_profit) + '%')
for prev_diff_i2 in range(n_iter - prev_diff_i): prev_diff_lim[1] = prev_diff_array[( prev_diff_i + prev_diff_i2)] datalimits = [ body_lim, shadow_lim, ratio_lim, prev_run_lim, prev_diff_lim ] [this_profit, combined_trade_array] = get_profit( datadata, datalimits, combined_trade_array) profit_array.append(this_profit) profit_stuff_array.append([ body_i, shadow_i, ratio_i, prev_run_i, prev_diff_i ]) j += 1 [combined_profit, combined_profit_array] = tradesim.sim_trade(data, combined_trade_array) print('100%') endtime = time.time() timetaken = endtime - starttime print(str(timetaken) + 's') print(max(profit_array)) print(combined_profit)
for i in range(n): this_set[i] = tradesim_n.sim_trade(jdata, trade_data[jiter], i + 1) profit_data[jiter] = this_set this_max_profit_data = max(this_set) this_max_sell_after = this_set.index(max(this_set)) + 1 max_profit_data[jiter] = this_max_profit_data max_sell_after[jiter] = this_max_sell_after combined_trade_array = [0] * data_length this_profit = 1.0 for i in range(len(trade_data)): if max_profit_data[i] > 1.0: # Try adding trade data together to get more profit trial_combined_trade_array = combine_profits(combined_trade_array, trade_data[i], max_sell_after[i]) trial_profit = tradesim.sim_trade(jdata, trial_combined_trade_array) if trial_profit > this_profit: all_cents[i].append(trial_profit - this_profit) all_cents[i].append(trial_profit) all_cents[i].append(jcoefficient_data[i][0]) all_profitable_cents.append(all_cents[i]) this_profit = trial_profit combined_trade_array = trial_combined_trade_array percent_profit = (this_profit - 1) * 100 print('Japanese candles: ' + str(percent_profit) + '%') # Save combined_trade_array to csv file combined_filepath = '../data/jprofits.csv' with open(combined_filepath, 'wb') as jprofit_file: j_writer = csv.writer(jprofit_file, delimiter=',') for profit_row in all_profitable_cents: j_writer.writerow(profit_row)