Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Automated YAPF Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 29, 2023
1 parent 46f1662 commit 3377ff9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
5 changes: 2 additions & 3 deletions backtest_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def backtest(algorithm, prices, timestamps, balance=200, strength_to_usd=200, pl
'strength': strength,
'current_balance': balance,
'current_shares': shares,
'timestamp': timestamps[index-1]
'timestamp': timestamps[index - 1]
})

return {
Expand All @@ -63,7 +63,6 @@ def plot(back_test_data):
plt.subplot(gs[0, :])
plt.plot(timestamps, balances, color=colors.primary())


buy_signals = np.where(np.array(signals) == 'buy')[0]
plt.scatter(buy_signals, [balances[i] for i in buy_signals], color=colors.lower())

Expand All @@ -81,4 +80,4 @@ def plot(back_test_data):
plt.close() # Solved plots overwriting each other
svg_buffer.close()

return plot_data
return plot_data
2 changes: 1 addition & 1 deletion plots/styling.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def style_plots(interval=0, dates=True):
xfmt = md.DateFormatter('%Y')
elif interval >= 1440:
xfmt = md.DateFormatter('%y/%m')
elif interval >= 240 or interval == 0:
elif interval >= 240 or interval == 0:
xfmt = md.DateFormatter('%m/%d')
elif interval >= 15:
xfmt = md.DateFormatter('%d')
Expand Down
3 changes: 2 additions & 1 deletion price.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def get_cached_prices(interval='default'):
if len(prices) < 1:
return np.zeros(point_count), np.zeros(point_count), 0

return np.array(prices).astype(float), interpolate_timestamps(timestamps, interval).astype(float), int(last_complete_point)
return np.array(prices).astype(float), interpolate_timestamps(timestamps,
interval).astype(float), int(last_complete_point)

# Price Caching On Redis DataBase
def update_cached_prices(log=True):
Expand Down
3 changes: 1 addition & 2 deletions test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def test_views(self):
plot_response = app_client.get(f'/backtest/{algorithm}?interval={interval}')
self.assertEqual(plot_response.status_code, 200)
time.sleep(5)
time.sleep(5) #Solved to many requests from kraken

time.sleep(5) #Solved to many requests from kraken

if __name__ == '__main__':
unittest.main()
20 changes: 10 additions & 10 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def svg_plot():
return plot_data

def interpolate_timestamps(timestamps, interval):
timestamps = np.array(timestamps, dtype='float64') # Convert to float
interval_seconds = interval * 60 # Convert minutes to seconds
# Calculate the number of intervals needed
num_intervals = int((timestamps[-1] - timestamps[0]) / interval_seconds) + 1
# Generate new timestamps using np.arange
new_timestamps = np.arange(timestamps[0], timestamps[0] + num_intervals * interval_seconds, interval_seconds)
return new_timestamps
timestamps = np.array(timestamps, dtype='float64') # Convert to float
interval_seconds = interval * 60 # Convert minutes to seconds

# Calculate the number of intervals needed
num_intervals = int((timestamps[-1] - timestamps[0]) / interval_seconds) + 1

# Generate new timestamps using np.arange
new_timestamps = np.arange(timestamps[0], timestamps[0] + num_intervals * interval_seconds, interval_seconds)

return new_timestamps
3 changes: 1 addition & 2 deletions views/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from mpld3 import fig_to_html
from flask import request


mpl.use('Agg')

figure_size = mpl.rcParams['figure.figsize']
Expand Down Expand Up @@ -46,5 +45,5 @@ def plot(algorithm_name):

style_plots(interval)

# @TODO change d3 and mpld3 urls to local ones
# @TODO change d3 and mpld3 urls to local ones
return fig_to_html(figure) if interactive else svg_plot()

0 comments on commit 3377ff9

Please sign in to comment.