Put yf.info behind an exchange flag on load (#3951)

* Put yf.info behind an exchange flag

* Guides

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
This commit is contained in:
James Maslek
2023-01-13 17:45:27 -05:00
committed by GitHub
parent e9b832f779
commit 6ae8d88d2d
3 changed files with 52 additions and 75 deletions

View File

@@ -1,7 +1,7 @@
"""Parent Classes."""
__docformat__ = "numpy"
# pylint: disable=C0301,C0302,R0902,global-statement
# pylint: disable=C0301,C0302,R0902,global-statement,too-many-boolean-expressions
import argparse
import difflib
@@ -960,7 +960,7 @@ class StockBaseController(BaseController, metaclass=ABCMeta):
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="load",
description="Load stock ticker to perform analysis on. When the data source"
+ " is syf', an Indian ticker can be"
+ " is yf, an Indian ticker can be"
+ " loaded by using '.NS' at the end, e.g. 'SBIN.NS'. See available market in"
+ " https://help.yahoo.com/kb/exchanges-data-providers-yahoo-finance-sln2310.html.",
)
@@ -1039,7 +1039,20 @@ class StockBaseController(BaseController, metaclass=ABCMeta):
type=str,
default="ytd",
)
parser.add_argument(
"--exchange",
dest="exchange",
action="store_true",
default=False,
help="Show exchange information.",
)
parser.add_argument(
"--performance",
dest="performance",
action="store_true",
default=False,
help="Show performance information.",
)
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-t")
@@ -1088,17 +1101,20 @@ class StockBaseController(BaseController, metaclass=ABCMeta):
return
if not df_stock_candidate.empty:
self.stock = df_stock_candidate
self.add_info = stocks_helper.additional_info_about_ticker(
ns_parser.ticker
)
console.print(self.add_info)
if ns_parser.exchange:
self.add_info = stocks_helper.additional_info_about_ticker(
ns_parser.ticker
)
console.print(self.add_info)
if (
ns_parser.interval == 1440
and not ns_parser.weekly
and not ns_parser.monthly
and ns_parser.filepath is None
and self.PATH == "/stocks/"
and ns_parser.performance
):
console.print()
stocks_helper.show_quick_performance(self.stock, ns_parser.ticker)
if "." in ns_parser.ticker:
self.ticker, self.suffix = ns_parser.ticker.upper().split(".")

View File

@@ -48,17 +48,17 @@ Continuing with the example mentioned at `quit`, revisit the `stocks` menu and l
```
2022 May 19, 05:27 (🦋) /stocks/ $ load -h
usage: load [-t TICKER] [-s START] [-e END] [-i {1,5,15,30,60}] [-p] [-f FILEPATH] [-m] [-w] [-r {ytd,1y,2y,5y,6m}] [-h] [--source {yf,av,iex,polygon}]
usage: load [-t TICKER] [-s START] [-e END] [-i {1,5,15,30,60}] [-p] [-f FILEPATH] [-m] [-w] [-r {ytd,1y,2y,5y,6m}] [--exchange] [--performance] [-h] [--export EXPORT]
[--source {YahooFinance,IEXCloud,AlphaVantage,Polygon,EODHD}]
Load stock ticker to perform analysis on. When the data source is Yahoo Finance, an Indian ticker can be loaded by
using '.NS' at the end, e.g. 'SBIN.NS'. American tickers do not have this addition, e.g. AMZN.
Load stock ticker to perform analysis on. When the data source is yf, an Indian ticker can be loaded by using '.NS' at the end, e.g. 'SBIN.NS'.
optional arguments:
-t TICKER, --ticker TICKER
Stock ticker (default: None)
-s START, --start START
The starting date (format YYYY-MM-DD) of the stock (default: 2019-07-01)
-e END, --end END The ending date (format YYYY-MM-DD) of the stock (default: 2022-07-05)
The starting date (format YYYY-MM-DD) of the stock (default: 2020-01-09)
-e END, --end END The ending date (format YYYY-MM-DD) of the stock (default: 2023-01-13)
-i {1,5,15,30,60}, --interval {1,5,15,30,60}
Intraday stock minutes (default: 1440)
-p, --prepost Pre/After market hours. Only works for 'yf' source, and intraday data (default: False)
@@ -67,33 +67,24 @@ optional arguments:
-m, --monthly Load monthly data (default: False)
-w, --weekly Load weekly data (default: False)
-r {ytd,1y,2y,5y,6m}, --iexrange {ytd,1y,2y,5y,6m}
Range for using the iexcloud api. Note that longer range requires more tokens in account (default: ytd)
Range for using the iexcloud api. Longer range requires more tokens in account (default: ytd)
--exchange Show exchange information. (default: False)
--performance Show performance information. (default: False)
-h, --help show this help message (default: False)
--source {yf,av,iex,polygon}
Data source to select from (default: yf)
--export EXPORT Export raw data into csv, json, xlsx (default: )
--source {YahooFinance,IEXCloud,AlphaVantage,Polygon,EODHD}
Data source to select from (default: YahooFinance)
For more information and examples, use 'about load' to access the related guide.
```
This shows you all **arguments** the command has. These are additional options you can provide to the command. Each default value is also displayed which is used when you do not select this option. For example, if I would use the <a href="https://www.investopedia.com/ask/answers/12/what-is-a-stock-ticker.asp" target="_blank" rel="noreferrer noopener">stock ticker</a> of Amazon (AMZN, which can also be found with `search amazon`), I can use `load AMZN` which will return the following:
```
2022 May 19, 05:27 (🦋) /stocks/ $ load AMZN
2023 Jan 13, 11:22 (🦋) /stocks/ $ load AMZN
Loading Daily AMZN stock with starting period 2019-05-15 for analysis.
Datetime: 2022 May 19 05:33
Timezone: America/New_York
Currency: USD
Market: OPEN
Company: Amazon.com, Inc.
AMZN Performance
┏━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ 1 Day ┃ 1 Week ┃ 1 Month ┃ 1 Year ┃ YTD ┃ Volatility (1Y) ┃ Volume (10D avg) ┃ Last Price ┃
┡━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ -3.34 % │ 1.65 % │ -32.26 % │ -33.71 % │ -37.14 % │ 31.36 % │ 5.51 M │ 2142.25 │
└─────────┴────────┴──────────┴──────────┴──────────┴─────────────────┴──────────────────┴────────────┘
Loading Daily data for AMZN with starting period 2020-01-09.
```
The default values you see within `load -h` have been inputted here. E.g. the starting period is 2019-05-15. I can decide to change these default values by calling the argument and inputting a different value.
@@ -103,22 +94,9 @@ Whenever you wish to apply an optional argument, you use the related shortcode,
Let's change the starting and ending period of the data that is being loaded in by doing the following:
```
2022 May 19, 05:38 (🦋) /stocks/ $ load AMZN -s 2005-01-01 -e 2010-01-01
2023 Jan 13, 11:23 (🦋) /stocks/ $ load AMZN -s 2005-01-01 -e 2010-01-01
Loading Daily AMZN stock with starting period 2005-01-01 for analysis.
Datetime: 2022 May 19 05:43
Timezone: America/New_York
Currency: USD
Market: OPEN
Company: Amazon.com, Inc.
AMZN Performance
┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ 1 Day ┃ 1 Week ┃ 1 Month ┃ 1 Year ┃ Period ┃ Volatility (1Y) ┃ Volume (10D avg) ┃ Last Price ┃
┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ -3.51 % │ -3.18 % │ -2.87 % │ 162.32 % │ 203.73 % │ 49.78 % │ 8.53 M │ 134.52 │
└─────────┴─────────┴─────────┴──────────┴──────────┴─────────────────┴──────────────────┴────────────┘
Loading Daily data for AMZN with starting period 2005-01-03.
```
We can check that this period has changed by looking into the <a href="https://www.investopedia.com/trading/candlestick-charting-what-is-it/" target="_blank" rel="noreferrer noopener">candle chart</a> with `candle`. This, again shares the same `-h` argument. This results in the following which indeed depicts our selected period.

View File

@@ -109,12 +109,12 @@ load -h
Prints the dialogue on the screen:
```console
options:
optional arguments:
-t TICKER, --ticker TICKER
Stock ticker (default: None)
-s START, --start START
The starting date (format YYYY-MM-DD) of the stock (default: 2019-11-27)
-e END, --end END The ending date (format YYYY-MM-DD) of the stock (default: 2022-12-01)
The starting date (format YYYY-MM-DD) of the stock (default: 2020-01-09)
-e END, --end END The ending date (format YYYY-MM-DD) of the stock (default: 2023-01-13)
-i {1,5,15,30,60}, --interval {1,5,15,30,60}
Intraday stock minutes (default: 1440)
-p, --prepost Pre/After market hours. Only works for 'yf' source, and intraday data (default: False)
@@ -124,6 +124,8 @@ options:
-w, --weekly Load weekly data (default: False)
-r {ytd,1y,2y,5y,6m}, --iexrange {ytd,1y,2y,5y,6m}
Range for using the iexcloud api. Longer range requires more tokens in account (default: ytd)
--exchange Show exchange information. (default: False)
--performance Show performance information. (default: False)
-h, --help show this help message (default: False)
--export EXPORT Export raw data into csv, json, xlsx (default: )
--source {YahooFinance,IEXCloud,AlphaVantage,Polygon,EODHD}
@@ -136,21 +138,10 @@ By default, a daily period, with three-years of OHLC+V data, from YahooFinance,
load SPY
```
A message will print indicating the starting date from which the data begins along with a table summarizing its recent performance.
A message will print indicating the starting date from which the data begins.
```console
Loading Daily data for SPY with starting period 2019-11-27.
Company: SPDR S&P 500
Exchange: PCX
Currency: USD
SPY Performance
┏━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ 1 Day ┃ 1 Week ┃ 1 Month ┃ 1 Year ┃ YTD ┃ Volatility (1Y) ┃ Volume (10D avg) ┃ Last Price ┃
┡━━━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 2.97 % │ 1.95 % │ 5.56 % │ -9.16 % │ -13.67 % │ 24.19 % │ 67.92 M │ 407.68 │
└────────┴────────┴─────────┴─────────┴──────────┴─────────────────┴──────────────────┴────────────┘
```
A simple way to get the entire history available from a source is to use an arbitrary starting date from a long time ago, like `1900-01-01`.
@@ -187,10 +178,6 @@ The performance table will not be displayed with intraday data, and we can see t
```console
Loading Intraday 1min data for SPY with starting period 2022-11-25.
Company: SPDR S&P 500
Exchange: PCX
Currency: USD
```
This can be augmented further by adding pre/post market price candles. The `-p` flag is only applicable to YahooFinance, Polygon will automatically include the candles from 4AM-8PM US/Eastern when intraday is selected.
@@ -208,10 +195,6 @@ load spy -s 1990-01-01 -m --export spy_monthly.csv
```console
Loading Daily data for SPY with starting period 1993-02-01.
Company: SPDR S&P 500
Exchange: PCX
Currency: USD
Saved file: /Users/{username}/OpenBBUserData/exports/spy_monthly.csv
```
@@ -281,7 +264,7 @@ The output will look like:
```console
135 news articles for SPDR+S&P+500 were found since 2022-11-24
Earnings Results: Big Lots to address weak results with even lower prices: ‘We will own bargains and treasures’
Earnings Results: Big Lots to address weak results with even lower prices: ‘We will own bargains and treasures’
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Content ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
@@ -292,7 +275,7 @@ The output will look like:
│ https://www.marketwatch.com/story/big-lots-to-address-weak-results-with-even-lower-prices-we-will-own-bargains-and-treasures-11669920117 │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Costco's Sales Update Slams the Stock. Strong Grocery Sales Weren't Enough.
Costco's Sales Update Slams the Stock. Strong Grocery Sales Weren't Enough.
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Content ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
@@ -303,7 +286,7 @@ The output will look like:
│ https://www.barrons.com/articles/costco-november-sales-51669916824 │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Investors Pull $8 Billion From Major Stock ETFs
Investors Pull $8 Billion From Major Stock ETFs
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Content ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
@@ -327,7 +310,7 @@ tob
Which displays an output like:
```console
SPY Top of Book
SPY Top of Book
┏━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Bid Size ┃ Bid Price ┃ Ask Price ┃ Ask Size ┃
┡━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━┩
@@ -354,7 +337,7 @@ quote
Displays a table:
```console
Ticker Quote
Ticker Quote
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ ┃ SPY ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
@@ -393,7 +376,7 @@ load aapl/codes
Prints the output:
```console
AAPL Codes
AAPL Codes
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ ┃ ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
@@ -451,7 +434,7 @@ search -s technology --country india -e india --export csv
The results returned are:
```console
Companies found on an exchange in India in India within Technology
Companies found on an exchange in India in India within Technology
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ ┃ Name ┃ Country ┃ Sector ┃ Industry ┃ Exchange ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩