Files
OpenBB/openbb_terminal/stocks/technical_analysis/rsp_model.py
Om Gupta 3a7401dfd0 Adds relative strength percentile to stocks/ta (#2302)
* Adds relative-strength percentile to stocks/ta

* allow exporting tables

* shifted from common to stocks and added tests

* added documentation

* added in nav bar

* fix test

* remove whitespace in docstring

* fix type error

* fix test

* fix tests

* test

* added tickers to a separate table

* add image to doc

Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
2022-08-22 14:54:08 +01: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"
)
if s_ticker == "":
rsp_stock = pd.DataFrame()
rsp_industry = pd.DataFrame()
else:
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