mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
* example changes in slopes * change lettering size and side bar capitalization * revert back to Fira * start automatic website generation * this was autogen * add examples to slopes model * generate slopes doc * change to _index.md * allow italic formatting * fix regex * option to regenerate paths * update alt docs * fix generate * update alt * fix generate * update common * target italic only for types * format alt * format italic common * add sig indentation * update sig indent alt * update common ident * add todo * generate docstrings for all menus * fix maxdd * fix returns font size * fix keys docs * fix more docstrings * escape literal symbols * escape literal symbols * reformat keys * format opt * remove literal escape * remove another literal escape * remove another literal escape * unindent returns * update docs return unindent * add comma in last arg * fix funcs without params * fix signature * compact some code * refactor some more code * refactor some code * some final cleanup * write docstrings * change main * move futures paths * generate futures docs * add external axes references * fix typo * revert to double docstring * fix small bug * remove docs folder * generate.py in website folder * add forecast to docs * clear some warnings * fix underscore * remove cite * refresh website docs * fix forecast docstrings * fix po * fix po docs and remove italic * fix more docstrings * remove last warning * codespell * flake8 * exclude website contente from flake * noqa on optimizer * update website * fix mypy * remove setup from mypy * mypy to openbbterminal * update precommit * pylint * try to remove sdk loading issue * avoid logging on test Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
163 lines
4.1 KiB
Python
163 lines
4.1 KiB
Python
"""Overlap Technical Analysis"""
|
|
___docformat__ = "numpy"
|
|
|
|
import logging
|
|
|
|
import pandas as pd
|
|
import pandas_ta as ta
|
|
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.rich_config import console
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
WINDOW_LENGTHS = [20, 50]
|
|
WINDOW_LENGTHS2 = [10, 20]
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def ema(data: pd.Series, length: int = 50, offset: int = 0) -> pd.DataFrame:
|
|
"""Gets exponential moving average (EMA) for stock
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.Series
|
|
Dataframe of dates and prices
|
|
length: int
|
|
Length of EMA window
|
|
offset: int
|
|
Length of offset
|
|
|
|
Returns
|
|
----------
|
|
pd.DataFrame
|
|
Dataframe containing prices and EMA
|
|
"""
|
|
if isinstance(data, pd.DataFrame):
|
|
console.print("[red]Please send a series and not a DataFrame.[/red]\n")
|
|
return pd.DataFrame()
|
|
return pd.DataFrame(ta.ema(data, length=length, offset=offset)).dropna()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def sma(data: pd.Series, length: int = 50, offset: int = 0) -> pd.DataFrame:
|
|
"""Gets simple moving average (EMA) for stock
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.Series
|
|
Dataframe of dates and prices
|
|
length: int
|
|
Length of SMA window
|
|
offset: int
|
|
Length of offset
|
|
|
|
Returns
|
|
----------
|
|
pd.DataFrame
|
|
Dataframe containing prices and SMA
|
|
"""
|
|
if isinstance(data, pd.DataFrame):
|
|
console.print("[red]Please send a series and not a DataFrame.[/red]\n")
|
|
return pd.DataFrame()
|
|
return pd.DataFrame(ta.sma(data, length=length, offset=offset)).dropna()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def wma(data: pd.Series, length: int = 50, offset: int = 0) -> pd.DataFrame:
|
|
"""Gets weighted moving average (WMA) for stock
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.Series
|
|
Dataframe of dates and prices
|
|
length: int
|
|
Length of SMA window
|
|
offset: int
|
|
Length of offset
|
|
|
|
Returns
|
|
----------
|
|
df_ta: pd.DataFrame
|
|
Dataframe containing prices and WMA
|
|
"""
|
|
if isinstance(data, pd.DataFrame):
|
|
console.print("[red]Please send a series and not a DataFrame.[/red]\n")
|
|
return pd.DataFrame()
|
|
return pd.DataFrame(ta.wma(data, length=length, offset=offset)).dropna()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def hma(data: pd.Series, length: int = 50, offset: int = 0) -> pd.DataFrame:
|
|
"""Gets hull moving average (HMA) for stock
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.Series
|
|
Dataframe of dates and prices
|
|
length: int
|
|
Length of SMA window
|
|
offset: int
|
|
Length of offset
|
|
|
|
Returns
|
|
----------
|
|
df_ta: pd.DataFrame
|
|
Dataframe containing prices and HMA
|
|
"""
|
|
if isinstance(data, pd.DataFrame):
|
|
console.print("[red]Please send a series and not a DataFrame.[/red]\n")
|
|
return pd.DataFrame()
|
|
return pd.DataFrame(ta.hma(data, length=length, offset=offset)).dropna()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def zlma(data: pd.Series, length: int = 50, offset: int = 0) -> pd.DataFrame:
|
|
"""Gets zero-lagged exponential moving average (ZLEMA) for stock
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.Series
|
|
Dataframe of dates and prices
|
|
length: int
|
|
Length of EMA window
|
|
offset: int
|
|
Length of offset
|
|
|
|
Returns
|
|
----------
|
|
df_ta: pd.DataFrame
|
|
Dataframe containing prices and EMA
|
|
"""
|
|
if isinstance(data, pd.DataFrame):
|
|
console.print("[red]Please send a series and not a DataFrame.[/red]\n")
|
|
return pd.DataFrame()
|
|
return pd.DataFrame(ta.zlma(data, length=length, offset=offset)).dropna()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def vwap(data: pd.Series, offset: int = 0) -> pd.DataFrame:
|
|
"""Gets volume weighted average price (VWAP)
|
|
|
|
Parameters
|
|
----------
|
|
data: pd.DataFrame
|
|
Dataframe of dates and prices
|
|
offset: int
|
|
Length of offset
|
|
Returns
|
|
----------
|
|
df_vwap: pd.DataFrame
|
|
Dataframe with VWAP data
|
|
"""
|
|
|
|
df_vwap = ta.vwap(
|
|
high=data["High"],
|
|
low=data["Low"],
|
|
close=data["Close"],
|
|
volume=data["Volume"],
|
|
offset=offset,
|
|
)
|
|
|
|
return pd.DataFrame(df_vwap)
|