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

Commit

Permalink
remove price utils & small bugfixes
Browse files Browse the repository at this point in the history
Merge pull request #43 from auto-trading-temp-name/fixed-lot-of-things
  • Loading branch information
CelestialCrafter authored Dec 8, 2023
2 parents 44c93ea + e126001 commit 33e1790
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 44 deletions.
12 changes: 3 additions & 9 deletions algorithms/bollinger_bands.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from talib import BBANDS
from price import get_periods, get_max_periods
import matplotlib.pyplot as plt
import plots.colors as colors

def algorithm(prices, window_size=(20, 'days'), standard_deviations=2):
periods = get_periods(*window_size)

if get_max_periods() < periods:
raise Exception(f'Not Enough Datapoints for this Interval')

return BBANDS(prices, timeperiod=periods, nbdevup=standard_deviations, nbdevdn=standard_deviations)
def algorithm(prices, window_size=20, standard_deviations=2):
return BBANDS(prices, timeperiod=window_size, nbdevup=standard_deviations, nbdevdn=standard_deviations)

def signal(prices, data):
upper_band, middle_band, lower_band = data
Expand All @@ -22,7 +16,7 @@ def signal(prices, data):
return 'no_action', 0

def plot(prices, timestamps, **kwargs):
upper_band, middle_band, lower_band = algorithm(prices, window_size=(20, 'days'), **kwargs)
upper_band, middle_band, lower_band = algorithm(prices, **kwargs)

plt.fill_between(timestamps, upper_band, lower_band, color='grey', alpha=0.3)

Expand Down
6 changes: 3 additions & 3 deletions algorithms/custom_bollinger_rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from algorithms.rsi import plot as rsi_plot
from algorithms.bollinger_bands import plot as bollinger_bands_plot

def algorithm(prices, window_size_rsi=(13, 'days'), window_size_bollinger_bands=(1, 'month')):
def algorithm(prices, window_size_rsi=13, window_size_bollinger_bands=30):
bb_data = bollinger_bands(prices, window_size=window_size_bollinger_bands)
rsi_line = rsi(prices, window_size=window_size_rsi)

Expand All @@ -16,7 +16,7 @@ def signal(prices, data):
price = prices[-1]
upper_band, lower_band, middle_band, rsi_line = data

if price >= lower_band[-1] and 30 >= rsi_line[-1]:
if lower_band[-1] >= price and 30 >= rsi_line[-1]:
return 'buy', 0.5

if price >= upper_band[-1] and rsi_line[-1] >= 70:
Expand All @@ -34,7 +34,7 @@ def plot(prices, timestamps, **kwargs):
sliced_prices = prices[:min(upper_band.shape[0], rsi_line.shape[0])]

upper_condition = (prices >= upper_band) & (rsi_line >= 70)
lower_condition = (prices >= lower_band) & (30 >= rsi_line)
lower_condition = (lower_band >= prices) & (30 >= rsi_line)
plt.scatter(timestamps[upper_condition], sliced_prices[upper_condition], color=colors.upper())
plt.scatter(timestamps[lower_condition], sliced_prices[lower_condition], color=colors.lower())

Expand Down
10 changes: 2 additions & 8 deletions algorithms/rsi.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from talib import RSI
from price import get_periods, get_max_periods
import numpy as np
import matplotlib.pyplot as plt
import plots.colors as colors

def algorithm(prices, window_size=(14, 'days')):
periods = get_periods(*window_size)

if get_max_periods() < periods:
raise Exception(f'Not Enough Datapoints for this Interval')

return RSI(prices, timeperiod=get_periods(*window_size))
def algorithm(prices, window_size=14):
return RSI(prices, timeperiod=window_size)

def signal(prices, data, high=70, low=30):
rsi = data
Expand Down
24 changes: 0 additions & 24 deletions price.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,6 @@ def get_cached_prices(interval='default'):

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

def get_periods(period_size, period_type, interval='default'):
if interval == 'default':
interval = get_default_interval()

if 'month' in period_type:
period_multiplier = 30 * 24 * 60
elif 'week' in period_type:
period_multiplier = 7 * 24 * 60
elif 'day' in period_type:
period_multiplier = 24 * 60
elif 'hour' in period_type:
period_multiplier = 60
elif 'minute' in period_type:
period_multiplier = 1
period_seconds = period_size * period_multiplier

return ceil(period_seconds / interval)

def get_max_periods(interval='default'):
if interval == 'default':
interval = get_default_interval()

return ceil(point_count * interval)

# Price Caching
def update_cached_prices():
for interval in cached_intervals:
Expand Down

0 comments on commit 33e1790

Please sign in to comment.