mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
Merge branch 'feature/plotly-react' of https://github.com/tehcoderer/OpenBBTerminal into feature/plotly-react
This commit is contained in:
@@ -11,6 +11,7 @@ candle
|
||||
candle -t --ma 5,10
|
||||
candle --raw
|
||||
candle --sort AdjClose -r --raw
|
||||
candle --ha
|
||||
codes
|
||||
news -l 3
|
||||
news -h
|
||||
|
||||
@@ -383,13 +383,13 @@ class StocksController(StockBaseController):
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="candle",
|
||||
description="Shows historic data for a stock",
|
||||
description="Shows historic price and volume for the asset.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--ticker",
|
||||
dest="ticker",
|
||||
help="Ticker to analyze",
|
||||
help="Ticker to analyze.",
|
||||
type=str,
|
||||
default=None,
|
||||
required=not any(x in other_args for x in ["-h", "--help"])
|
||||
@@ -401,7 +401,7 @@ class StocksController(StockBaseController):
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="prepost",
|
||||
help="Pre/After market hours. Only works for 'yf' source, and intraday data",
|
||||
help="Pre/After market hours. Only works for intraday data.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--sort",
|
||||
@@ -428,13 +428,13 @@ class StocksController(StockBaseController):
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
help="Shows raw data instead of chart.",
|
||||
help="Shows raw data instead of a chart.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--trend",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Flag to add high and low trends to candle",
|
||||
help="Flag to add high and low trends to candle.",
|
||||
dest="trendlines",
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -447,6 +447,13 @@ class StocksController(StockBaseController):
|
||||
),
|
||||
default=None,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ha",
|
||||
dest="ha",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Flag to show Heikin Ashi candles.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log",
|
||||
help="Plot with y axis on log scale",
|
||||
@@ -498,8 +505,9 @@ class StocksController(StockBaseController):
|
||||
data=data,
|
||||
add_trend=ns_parser.trendlines,
|
||||
ma=mov_avgs,
|
||||
ha=ns_parser.ha,
|
||||
prepost=ns_parser.prepost,
|
||||
asset_type="Stock",
|
||||
asset_type="",
|
||||
yscale="log" if ns_parser.logy else "linear",
|
||||
external_axes=ns_parser.is_image,
|
||||
)
|
||||
|
||||
@@ -17,6 +17,7 @@ import pandas as pd
|
||||
import pytz
|
||||
import yfinance as yf
|
||||
from pandas.tseries.holiday import USFederalHolidayCalendar
|
||||
from pandas_ta import candles
|
||||
from requests.exceptions import ReadTimeout
|
||||
from scipy import stats
|
||||
|
||||
@@ -577,6 +578,7 @@ def display_candle(
|
||||
source: str = "YahooFinance",
|
||||
weekly: bool = False,
|
||||
monthly: bool = False,
|
||||
ha: Optional[bool] = False,
|
||||
external_axes: bool = False,
|
||||
raw: bool = False,
|
||||
yscale: str = "linear",
|
||||
@@ -611,6 +613,8 @@ def display_candle(
|
||||
Flag to get weekly data
|
||||
monthly: bool
|
||||
Flag to get monthly data
|
||||
ha: bool
|
||||
Flag to show Heikin Ashi candles.
|
||||
external_axes : bool, optional
|
||||
Whether to return the figure object or not, by default False
|
||||
raw : bool, optional
|
||||
@@ -672,6 +676,14 @@ def display_candle(
|
||||
|
||||
data.name = f"{asset_type} {symbol}"
|
||||
|
||||
if ha:
|
||||
data_ = heikin_ashi(data)
|
||||
data["Open"] = data_["HA Open"]
|
||||
data["High"] = data_["HA High"]
|
||||
data["Low"] = data_["HA Low"]
|
||||
data["Close"] = data_["HA Close"]
|
||||
data.name = f"{symbol} - Heikin Ashi Candles"
|
||||
|
||||
fig = PlotlyTA.plot(data, dict(**kwargs), prepost=prepost)
|
||||
|
||||
if add_trend:
|
||||
@@ -888,7 +900,10 @@ def clean_function(entry: str) -> Union[str, float]:
|
||||
return entry
|
||||
|
||||
|
||||
def show_quick_performance(stock_df: pd.DataFrame, ticker: str):
|
||||
def show_quick_performance(
|
||||
stock_df: pd.DataFrame,
|
||||
ticker: str,
|
||||
) -> None:
|
||||
"""Show quick performance stats of stock prices.
|
||||
|
||||
Daily prices expected.
|
||||
@@ -925,6 +940,7 @@ def show_quick_performance(stock_df: pd.DataFrame, ticker: str):
|
||||
)
|
||||
|
||||
perf_df["Previous Close"] = str(round(closes[-1], 2))
|
||||
|
||||
print_rich_table(
|
||||
perf_df,
|
||||
show_index=False,
|
||||
@@ -1044,3 +1060,48 @@ def verify_plot_options(command: str, source: str, plot: list) -> bool:
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def heikin_ashi(data: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Return OHLC data as Heikin Ashi Candles.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
data: pd.DataFrame
|
||||
DataFrame containing OHLC data.
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Appended DataFrame with Heikin Ashi candle calculations.
|
||||
"""
|
||||
|
||||
check_columns = ["Open", "High", "Low", "Close"]
|
||||
|
||||
data.rename(
|
||||
columns={"open": "Open", "high": "High", "low": "Low", "close": "Close"},
|
||||
inplace=True,
|
||||
)
|
||||
|
||||
for item in check_columns:
|
||||
if item not in data.columns:
|
||||
raise ValueError(
|
||||
"The expected column labels, "
|
||||
f"{check_columns}"
|
||||
", were not found in DataFrame."
|
||||
)
|
||||
|
||||
ha = candles.ha(
|
||||
data["Open"],
|
||||
data["High"],
|
||||
data["Low"],
|
||||
data["Close"],
|
||||
)
|
||||
ha.columns = [
|
||||
"HA Open",
|
||||
"HA High",
|
||||
"HA Low",
|
||||
"HA Close",
|
||||
]
|
||||
|
||||
return pd.concat([data, ha], axis=1)
|
||||
|
||||
@@ -212,7 +212,7 @@ Loading Daily data for MSFT with starting period 2020-04-08.
|
||||
|
||||

|
||||
|
||||
The help dialogue for the `candle` command shows how this chart can be supplemented with additional data; specifically, `-t` for trend, `--ma` for moving averages, and `--log` for a log scale.
|
||||
The help dialogue for the `candle` command shows how this chart can be supplemented with additional data; specifically, `-t` for trend, `--ma` for moving averages, `--log` for a log scale, and `--ha` to convert the candles to a Heikin Ashi pattern.
|
||||
|
||||
```console
|
||||
candle -h
|
||||
@@ -221,21 +221,22 @@ candle -h
|
||||
Which prints to screen:
|
||||
|
||||
```console
|
||||
usage: candle [-t TICKER] [-p] [--sort {open,high,low,close,adjclose,volume,dividends,stock_splits}] [-r] [--raw] [--trend] [--ma MOV_AVG] [--log] [-h] [--export EXPORT]
|
||||
usage: candle [-t TICKER] [-p] [--sort {open,high,low,close,adjclose,volume,dividends,stock_splits}] [-r] [--raw] [--trend] [--ma MOV_AVG] [--ha] [--log] [-h] [--export EXPORT]
|
||||
[--sheet-name SHEET_NAME [SHEET_NAME ...]] [-l LIMIT]
|
||||
|
||||
Shows historic data for a stock
|
||||
Shows historic price and volume for the asset.
|
||||
|
||||
options:
|
||||
-t TICKER, --ticker TICKER
|
||||
Ticker to analyze (default: None)
|
||||
-p, --prepost Pre/After market hours. Only works for 'yf' source, and intraday data (default: False)
|
||||
Ticker to analyze. (default: None)
|
||||
-p, --prepost Pre/After market hours. Only works for intraday data. (default: False)
|
||||
--sort {open,high,low,close,adjclose,volume,dividends,stock_splits}
|
||||
Choose a column to sort by. Only works when raw data is displayed. (default: )
|
||||
-r, --reverse Data is sorted in descending order by default. Reverse flag will sort it in an ascending way. Only works when raw data is displayed. (default: False)
|
||||
--raw Shows raw data instead of chart. (default: False)
|
||||
--trend Flag to add high and low trends to candle (default: False)
|
||||
--raw Shows raw data instead of a chart. (default: False)
|
||||
--trend Flag to add high and low trends to candle. (default: False)
|
||||
--ma MOV_AVG Add moving average in number of days to plot and separate by a comma. Value for ma (moving average) keyword needs to be greater than 1. (default: None)
|
||||
--ha Flag to show Heikin Ashi candles. (default: False)
|
||||
--log Plot with y axis on log scale (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export EXPORT Export raw data into csv, json, xlsx and figure into png, jpg, pdf, svg (default: )
|
||||
|
||||
Reference in New Issue
Block a user