Files
OpenBB/openbb_terminal/stocks/technical_analysis/rsp_model.py
Colin Delahunty 8772ac738f Added error handling (#3070)
* Added error handling

* Added command to SDK

* Updated docs

* Fixed tests to account for new error handling
2022-10-31 13:31:33 -04:00

54 lines
1.5 KiB
Python

""" Relative Strength Percentile Model """
__docformat__ = "numpy"
import logging
from typing import Tuple
import pandas as pd
from openbb_terminal.decorators import log_start_end
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def get_rsp(
s_ticker: str = "",
) -> Tuple[pd.DataFrame]:
"""Relative strength percentile [Source: https://github.com/skyte/relative-strength]
Currently takes from https://github.com/soggyomelette/rs-log in order to get desired output
Parameters
----------
s_ticker : str
Stock Ticker
Returns
----------
pd.DataFrame
Dataframe of stock percentile
pd.Dataframe
Dataframe of industry percentile
pd.Dataframe
Raw stock dataframe for export
pd.Dataframe
Raw industry dataframe for export
"""
df_stock_p = pd.read_csv(
"https://raw.githubusercontent.com/soggyomelette/rs-log/main/output/rs_stocks.csv"
)
df_industries_p = pd.read_csv(
"https://raw.githubusercontent.com/soggyomelette/rs-log/main/output/rs_industries.csv"
)
rsp_stock = pd.DataFrame()
rsp_industry = pd.DataFrame()
if s_ticker != "":
rsp_stock = df_stock_p[df_stock_p["Ticker"].str.match(s_ticker)]
for i in range(len(df_industries_p)):
if s_ticker in df_industries_p.iloc[i]["Tickers"]:
rsp_industry = df_industries_p.iloc[[i]]
return (rsp_stock, rsp_industry, df_stock_p, df_industries_p) # type: ignore