diff options
author | sotech117 <michael_foiani@brown.edu> | 2025-07-31 17:27:24 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2025-07-31 17:27:24 -0400 |
commit | 5bf22fc7e3c392c8bd44315ca2d06d7dca7d084e (patch) | |
tree | 8dacb0f195df1c0788d36dd0064f6bbaa3143ede /simulate.py | |
parent | b832d364da8c2efe09e3f75828caf73c50d01ce3 (diff) |
add code for analysis of data
Diffstat (limited to 'simulate.py')
-rw-r--r-- | simulate.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/simulate.py b/simulate.py index 2e28959..26aae8c 100644 --- a/simulate.py +++ b/simulate.py @@ -62,6 +62,7 @@ def backtest_algo(algo : Algo, timestamps, prices, init_offset=5, starting_money "starting_assets" : starting_money, "final_assets" : assets, "algo_name" : algo.name, + "algo_params" : algo.params, "algo_graph_data" : algo.graph_data } @@ -103,7 +104,7 @@ def run_batch(batch_name, algo, num_trials=100): # pull chart data for these params and run the algo data = fetch_chart_data_backtest(rand_ticker, '1Min', rand_date) - results = backtest_algo(algo, data['timestamps'], data['prices'], 13) + results = backtest_algo(algo, data['timestamps'], data['prices'], 23) # TODO: make this generalized url_params = { @@ -129,11 +130,11 @@ def run_batch(batch_name, algo, num_trials=100): return except Exception as e: print(f"An error occurred: {e}") - return percent_gain = results['percent_gain'] date_format = datetime.datetime.timestamp(rand_date) - file_name = f'{path}/{str(percent_gain).replace('-', 'neg').replace('.', 'd')}_{rand_ticker.replace('/', '')}_{date_format}.json' + # file_name = f'{path}/{str(percent_gain).replace('-', 'n').replace('.', 'd')}_{rand_ticker.replace('/', '')}_{date_format}.json' + file_name = f'{path}/{i}_{rand_ticker.replace("/", "")}_{date_format}.json' fd = open(file_name, 'w') fd.write(json.dumps(trial_data)) fd.close() @@ -165,7 +166,8 @@ def test(): "interval" : interval, } - results = backtest_algo(ema_algo, data['timestamps'], data['prices'], 13) + print(len(data['timestamps']), len(data['prices'])) + results = backtest_algo(ema_algo, data['timestamps'], data['prices'], 23) # write the data into a json to be viewed in a chart @@ -178,5 +180,5 @@ def test(): fd = open('bt-recent.json', 'w') fd.write(json.dumps(trial_data)) fd.close() -test() -# run_batch('test-1-ema', Ema_Algo(), 10)
\ No newline at end of file +# test() +run_batch('test-1-ema', Ema_Algo(11, 23), 10)
\ No newline at end of file |