aboutsummaryrefslogtreecommitdiff
path: root/simulate.py
diff options
context:
space:
mode:
Diffstat (limited to 'simulate.py')
-rw-r--r--simulate.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/simulate.py b/simulate.py
index 746405b..2e28959 100644
--- a/simulate.py
+++ b/simulate.py
@@ -5,6 +5,7 @@ import datetime
import json
import random
import os
+import pytz
"""
Function that takes in data and returns a buy, sell, or hold singal per interval
@@ -69,8 +70,8 @@ def backtest_algo(algo : Algo, timestamps, prices, init_offset=5, starting_money
# store all algo name, buy, sell, price data, timestamps, into a json so it can be viewed as a trial
# caluclate some metrics (NOW: only how much money gained, how many trades, trades per day... etc)
-ticker_bank = ['BTC-USD', 'ADA-USD', 'ETH-USD', 'ETC-USD', 'DOGE-USD']
-year_bank = [2020, 2021, 2022, 2023, 2024, 2025]
+ticker_bank = ['BTC/USD', 'ETH/USD', 'XRP/USD']
+year_bank = [2024, 2025]
# time_bank = [0]
# max_seconds = 24 * 60 * 60
# timedelta(seconds=rand_second) + datetime(created with 0 time)
@@ -101,14 +102,14 @@ def run_batch(batch_name, algo, num_trials=100):
continue
# pull chart data for these params and run the algo
- data = fetch_chart_data_backtest(rand_ticker, '1m', rand_date)
+ data = fetch_chart_data_backtest(rand_ticker, '1Min', rand_date)
results = backtest_algo(algo, data['timestamps'], data['prices'], 13)
# TODO: make this generalized
url_params = {
"ticker" : rand_ticker,
- "period" : '8d',
- "interval" : '1m',
+ "period" : '5D',
+ "interval" : '1Min',
}
# store the results in into a file
trial_data = {
@@ -118,7 +119,7 @@ def run_batch(batch_name, algo, num_trials=100):
}
# make a new directory for the batch
- path = f'batches_{algo.name}/{batch_name}'
+ path = f'batches/{batch_name}'
if i == 1:
print(path)
try:
@@ -131,8 +132,8 @@ def run_batch(batch_name, algo, num_trials=100):
return
percent_gain = results['percent_gain']
- date_format = datetime.datetime.isoformat(rand_date)
- file_name = f'{path}/{percent_gain}_{rand_ticker}_{date_format}.json'
+ date_format = datetime.datetime.timestamp(rand_date)
+ file_name = f'{path}/{str(percent_gain).replace('-', 'neg').replace('.', 'd')}_{rand_ticker.replace('/', '')}_{date_format}.json'
fd = open(file_name, 'w')
fd.write(json.dumps(trial_data))
fd.close()
@@ -155,7 +156,7 @@ def test():
# data = fetch_chart_data(ticker, period, interval)
# period_end_date = datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(days=7)
# print(period_end_date)
- data = fetch_chart_data_yahoo('XRP-USD', '1h', None, datetime.timedelta(weeks=52))
+ data = fetch_chart_data_backtest('XRP/USD', '1D', None, datetime.timedelta(weeks=52))
print(data.keys())
url_params = {
@@ -177,5 +178,5 @@ def test():
fd = open('bt-recent.json', 'w')
fd.write(json.dumps(trial_data))
fd.close()
-
-test() \ No newline at end of file
+test()
+# run_batch('test-1-ema', Ema_Algo(), 10) \ No newline at end of file