Files
OpenBB/openbb_terminal/common/technical_analysis/volume_model.py
jmaslek b71abcfbf4 Updating some names (#1575)
* quick econ fix

* black

* keys and feature flags

* terminal name 👀

* some more replacements

* some more replacements

* edit pyproject

* gst -> openbb

* add example portfolios back to git

* Update api from gst

* sorry.  skipping some tests

* another round of names

* another round of test edits

* Missed some .gst refs and update timezone

* water mark stuff

* Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS

* fix more GST to OpenBB Terminal

* Logging : merge conflicts with main

* Revert wrong files

Co-authored-by: Andrew <andrew.kenreich@gmail.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
2022-03-29 09:46:26 -04:00

106 lines
2.4 KiB
Python

"""Volume Technical Analysis"""
__docformat__ = "numpy"
import logging
import pandas as pd
import pandas_ta as ta
from openbb_terminal.decorators import log_start_end
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def ad(df_stock: pd.DataFrame, use_open: bool = False) -> pd.DataFrame:
"""Calculate AD technical indicator
Parameters
----------
df_stock : pd.DataFrame
Dataframe of prices with OHLC and Volume
use_open : bool
Whether to use open prices
Returns
-------
pd.DataFrame
Dataframe with technical indicator
"""
if use_open:
df_ta = ta.ad(
high=df_stock["High"],
low=df_stock["Low"],
close=df_stock["Close"],
volume=df_stock["Volume"],
open_=df_stock["Open"],
).dropna()
# Do not use open stock values
else:
df_ta = ta.ad(
high=df_stock["High"],
low=df_stock["Low"],
close=df_stock["Close"],
volume=df_stock["Volume"],
).dropna()
return pd.DataFrame(df_ta)
@log_start_end(log=logger)
def adosc(
df_stock: pd.DataFrame, use_open: bool = False, fast: int = 3, slow: int = 10
) -> pd.DataFrame:
"""Calculate AD oscillator technical indicator
Parameters
----------
df_stock : pd.DataFrame
Dataframe of prices
use_open : bool
Whether to use open prices
Returns
-------
pd.DataFrame
Dataframe with technical indicator
"""
if use_open:
df_ta = ta.adosc(
high=df_stock["High"],
low=df_stock["Low"],
close=df_stock["Close"],
volume=df_stock["Volume"],
open_=df_stock["Open"],
fast=fast,
slow=slow,
).dropna()
else:
df_ta = ta.adosc(
high=df_stock["High"],
low=df_stock["Low"],
close=df_stock["Close"],
volume=df_stock["Volume"],
fast=fast,
slow=slow,
).dropna()
return pd.DataFrame(df_ta)
@log_start_end(log=logger)
def obv(df_stock: pd.DataFrame) -> pd.DataFrame:
"""On Balance Volume
Parameters
----------
df_stock: pd.DataFrame
Dataframe of stock prices
Returns
-------
pd.DataFrame
Dataframe with technical indicator
"""
return pd.DataFrame(
ta.obv(close=df_stock["Adj Close"], volume=df_stock["Volume"]).dropna()
)