Fix TA integration script (#2356)

* Fix TA integration script

* test
This commit is contained in:
James Maslek
2022-08-18 15:16:42 -04:00
committed by GitHub
parent d549272faf
commit 52f4d673f8
4 changed files with 26 additions and 22 deletions

View File

@@ -31,7 +31,7 @@ register_matplotlib_converters()
@log_start_end(log=logger)
def view_ma(
series: pd.Series,
length: List[int] = None,
window: List[int] = None,
offset: int = 0,
ma_type: str = "EMA",
symbol: str = "",
@@ -44,7 +44,7 @@ def view_ma(
----------
series: pd.Series
Series of prices
length: List[int]
window: List[int]
Length of EMA window
offset: int
Offset variable
@@ -61,10 +61,10 @@ def view_ma(
price_df = pd.DataFrame(series)
l_legend = [symbol]
if not length:
length = [20, 50]
if not window:
window = [20, 50]
for win in length:
for win in window:
if ma_type == "EMA":
df_ta = overlap_model.ema(series, win, offset)
l_legend.append(f"EMA {win}")
@@ -112,7 +112,7 @@ def view_ma(
export_data(
export,
os.path.dirname(os.path.abspath(__file__)).replace("common", "stocks"),
f"{ma_type.lower()}{'_'.join([str(win) for win in length])}",
f"{ma_type.lower()}{'_'.join([str(win) for win in window])}",
price_df,
)

View File

@@ -26,7 +26,7 @@ logger = logging.getLogger(__name__)
def display_bbands(
data: pd.DataFrame,
symbol: str = "",
limit: int = 15,
window: int = 15,
n_std: float = 2,
mamode: str = "sma",
export: str = "",
@@ -40,7 +40,7 @@ def display_bbands(
Dataframe of ohlc prices
symbol : str
Ticker symbol
limit : int
window : int
Length of window to calculate BB
n_std : float
Number of standard deviations to show
@@ -51,7 +51,7 @@ def display_bbands(
external_axes : Optional[List[plt.Axes]], optional
External axes (1 axis is expected in the list), by default None
"""
df_ta = volatility_model.bbands(data["Adj Close"], limit, n_std, mamode)
df_ta = volatility_model.bbands(data["Adj Close"], window, n_std, mamode)
plot_data = pd.merge(data, df_ta, how="outer", left_index=True, right_index=True)
plot_data = reindex_dates(plot_data)
@@ -188,7 +188,7 @@ def display_donchian(
@log_start_end(log=logger)
def view_kc(
data: pd.DataFrame,
limit: int = 20,
window: int = 20,
scalar: float = 2,
mamode: str = "ema",
offset: int = 0,
@@ -203,7 +203,7 @@ def view_kc(
data: pd.DataFrame
Dataframe of ohlc prices
limit: int
window: int
Length of window
scalar: float
Scalar value
@@ -222,7 +222,7 @@ def view_kc(
data["High"],
data["Low"],
data["Adj Close"],
limit,
window,
scalar,
mamode,
offset,

View File

@@ -71,8 +71,12 @@ def get_tradingview_recommendation(
interval=an_interval,
)
d_recommendation = stock_recommendation.get_analysis().summary
df_recommendation = df_recommendation.append(
d_recommendation, ignore_index=True
df_recommendation = pd.concat(
[
pd.DataFrame.from_dict(d_recommendation, orient="index").T,
df_recommendation,
],
axis=0,
)
index_recommendation.append(INTERVALS[an_interval])
df_recommendation.index = index_recommendation

View File

@@ -1,9 +1,9 @@
Interval,RECOMMENDATION,BUY,SELL,NEUTRAL
1 month,BUY,14,5,7
1 week,BUY,14,3,9
1 day,NEUTRAL,7,9,10
4 hours,NEUTRAL,9,11,6
1 hour,SELL,2,15,9
15 min,SELL,1,15,10
5 min,STRONG_SELL,1,16,9
1 min,STRONG_SELL,0,16,10
1 month,STRONG_SELL,0,16,10
1 week,STRONG_SELL,1,16,9
1 day,SELL,1,15,10
4 hours,SELL,2,15,9
1 hour,NEUTRAL,9,11,6
15 min,NEUTRAL,7,9,10
5 min,BUY,14,3,9
1 min,BUY,14,5,7
1 Interval RECOMMENDATION BUY SELL NEUTRAL
2 1 month BUY STRONG_SELL 14 0 5 16 7 10
3 1 week BUY STRONG_SELL 14 1 3 16 9
4 1 day NEUTRAL SELL 7 1 9 15 10
5 4 hours NEUTRAL SELL 9 2 11 15 6 9
6 1 hour SELL NEUTRAL 2 9 15 11 9 6
7 15 min SELL NEUTRAL 1 7 15 9 10
8 5 min STRONG_SELL BUY 1 14 16 3 9
9 1 min STRONG_SELL BUY 0 14 16 5 10 7