Added raw stock data #817 (#820)

This commit is contained in:
Colin Delahunty
2021-10-18 19:07:02 -04:00
committed by GitHub
parent 88260f4889
commit ede36834c5
5 changed files with 136 additions and 5 deletions

View File

@@ -497,3 +497,48 @@ def display_unitroot(
"unitroot",
data,
)
def display_raw(
df: pd.DataFrame, export: str, sort: str, des: bool, num: int = 20
) -> None:
"""Return raw stock data
Parameters
----------
df : DataFrame
DataFrame with historical information
export : str
Export data as CSV, JSON, XLSX
sort : str
The column to sort by
des : bool
Whether to sort descending
num : int
Number of rows to show
"""
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"history",
df,
)
if sort:
df = df.sort_values(by=sort, ascending=des)
if gtff.USE_TABULATE_DF:
print(
tabulate(
df.head(num),
headers=[x.title() if x != "" else "Date" for x in df.columns],
tablefmt="fancy_grid",
showindex=True,
floatfmt=".2f",
)
)
else:
print(df.to_string(index=False))
print("")

View File

@@ -34,6 +34,7 @@ from gamestonk_terminal.stocks.screener import screener_controller
from gamestonk_terminal.stocks.stocks_helper import candle, load, quote
from gamestonk_terminal.stocks.technical_analysis import ta_controller
from gamestonk_terminal.helper_funcs import valid_date
from gamestonk_terminal.common.quantitative_analysis import qa_view
# pylint: disable=R1710
@@ -209,10 +210,75 @@ Market {('CLOSED', 'OPEN')[b_is_stock_market_open()]}
def call_candle(self, other_args: List[str]):
"""Process candle command"""
candle(
self.ticker + "." + self.suffix if self.suffix else self.ticker,
other_args,
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="data",
description="Shows historic data for a stock",
)
parser.add_argument(
"--export",
choices=["csv", "json", "xlsx"],
default="",
type=str,
dest="export",
help="Export dataframe data to csv,json,xlsx file",
)
parser.add_argument(
"-s",
"--sort",
choices=[
"AdjClose",
"Open",
"Close",
"High",
"Low",
"Volume",
"Returns",
"LogRet",
],
default="",
type=str,
dest="sort",
help="Choose a column to sort by",
)
parser.add_argument(
"-d",
"--descending",
action="store_false",
dest="descending",
default=True,
help="Sort selected column descending",
)
parser.add_argument(
"--raw",
action="store_true",
dest="raw",
default=False,
help="Shows raw data instead of chart",
)
try:
ns_parser = parse_known_args_and_warn(parser, other_args)
if not ns_parser:
return
if ns_parser.raw:
qa_view.display_raw(
self.stock,
ns_parser.export,
ns_parser.sort,
ns_parser.descending,
)
else:
candle(
self.ticker + "." + self.suffix if self.suffix else self.ticker,
other_args,
)
except Exception as e:
print(e, "\n")
def call_news(self, other_args: List[str]):
"""Process news command"""

View File

@@ -1,14 +1,18 @@
```
usage: candle [-s S_START] [--plotly] [-h]
usage: candle [-s S_START] [--plotly] [-h] [--raw] [-e {csv, json, xlsx}] -s SORT] [-d]
```
Displays candle chart of loaded ticker
Displays candle chart of loaded ticker, or shows raw data with --raw
```
optional arguments:
-s S_START, --start_date S_START
Start date for candle data (default: 2021-03-19)
--plotly Flag to show interactive plot using plotly. (default: False)
--raw shows the raw data instead of a chart
-e, --export The format to export the information into
-s, --sort Which column to sort the information by
-d, --descending Show the information in descending order
-h, --help show this help message (default: False)
```

View File

@@ -0,0 +1,14 @@
```
usage: data [-e {csv, json, xlsx}] [-s SORT] [-d] [-n NUMBER] [-h]
```
Shows a table of historical information for a stock with the option to export the data [Source: Yahoo Finance]
```
optional arguments:
-e, --export The format to export the information into
-s, --sort Which column to sort the information by
-d, --descending Show the information in descending order
-n, --num Number of results to show
-h, Help
```

View File

@@ -487,6 +487,8 @@ main:
ref: "/stocks/quantitative_analysis/cusum"
- name: capm
ref: "/stocks/quantitative_analysis/capm"
- name: data
ref: "/stocks/quantitative_analysis/data"
- name: prediction techniques
ref: "/stocks/prediction_techniques"
sub: