(ticker, hidden_layers=15, NUM_MINUTES_BACK=1000, NUM_EPOCHS=1000, granularity_minutes=15,
datasetinputs=5, learningrate=0.005, bias=False, momentum=0.1, weightdecay=0.0, recurrent=False,
timedelta_back_in_granularity_increments=0)
| 5 | |
| 6 | |
| 7 | def predict_v2(ticker, hidden_layers=15, NUM_MINUTES_BACK=1000, NUM_EPOCHS=1000, granularity_minutes=15, |
| 8 | datasetinputs=5, learningrate=0.005, bias=False, momentum=0.1, weightdecay=0.0, recurrent=False, |
| 9 | timedelta_back_in_granularity_increments=0): |
| 10 | |
| 11 | # setup |
| 12 | print_and_log("(p)starting ticker:{} hidden:{} min:{} epoch:{} gran:{} dsinputs:{} learningrate:{} bias:{} momentum:{} weightdecay:{}\ |
| 13 | recurrent:{}, timedelta_back_in_granularity_increments:{} ".format( |
| 14 | ticker, hidden_layers, NUM_MINUTES_BACK, NUM_EPOCHS, granularity_minutes, datasetinputs, |
| 15 | learningrate, bias, momentum, weightdecay, recurrent, timedelta_back_in_granularity_increments)) |
| 16 | pt = PredictionTest() |
| 17 | pt.type = 'mock' |
| 18 | pt.symbol = ticker |
| 19 | pt.datasetinputs = datasetinputs |
| 20 | pt.hiddenneurons = hidden_layers |
| 21 | pt.minutes_back = NUM_MINUTES_BACK |
| 22 | pt.epochs = NUM_EPOCHS |
| 23 | pt.momentum = momentum |
| 24 | pt.granularity = granularity_minutes |
| 25 | pt.bias = bias |
| 26 | pt.bias_chart = -1 if pt.bias is None else (1 if pt.bias else 0) |
| 27 | pt.learningrate = learningrate |
| 28 | pt.weightdecay = weightdecay |
| 29 | pt.recurrent = recurrent |
| 30 | pt.recurrent_chart = -1 if pt.recurrent is None else (1 if pt.recurrent else 0) |
| 31 | pt.timedelta_back_in_granularity_increments = timedelta_back_in_granularity_increments |
| 32 | all_output = "" |
| 33 | start_time = int(time.time()) |
| 34 | |
| 35 | # get neural network & data |
| 36 | pt.get_nn() |
| 37 | sample_data, test_data = pt.get_train_and_test_data() |
| 38 | |
| 39 | # output / testing |
| 40 | round_to = 2 |
| 41 | num_times_directionally_correct = 0 |
| 42 | num_times = 0 |
| 43 | diffs = [] |
| 44 | profitloss_pct = [] |
| 45 | for i, val in enumerate(test_data): |
| 46 | try: |
| 47 | # get NN projection |
| 48 | sample = create_sample_row(test_data, i, datasetinputs) |
| 49 | recommend, nn_price, last_sample, projected_change_pct = pt.predict(sample) |
| 50 | |
| 51 | # calculate profitability |
| 52 | actual_price = test_data[i+datasetinputs] |
| 53 | diff = nn_price - actual_price |
| 54 | diff_pct = 100 * diff / actual_price |
| 55 | directionally_correct = ((actual_price - last_sample) > 0 and (nn_price - last_sample) > 0) \ |
| 56 | or ((actual_price - last_sample) < 0 and (nn_price - last_sample) < 0) |
| 57 | if recommend != 'HOLD': |
| 58 | profitloss_pct = profitloss_pct + [abs((actual_price - last_sample) / last_sample) * |
| 59 | (1 if directionally_correct else -1)] |
| 60 | if directionally_correct: |
| 61 | num_times_directionally_correct = num_times_directionally_correct + 1 |
| 62 | num_times = num_times + 1 |
| 63 | diffs.append(diff) |
| 64 | output = "{}) seq ending in {} => {} (act {}, {}/{} pct off); Recommend: {}; Was Directionally Correct:{}\ |
no test coverage detected