diff --git a/ROADMAP.md b/ROADMAP.md index 1e76964f59f..96116af982a 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -68,6 +68,7 @@ * [x] Add initial implementation of trendline analysis (@aia) - [PR #173](https://github.com/DidierRLopes/GamestonkTerminal/pull/173) * [x] Add technical summary report provided by FinBrain (@didier) - [PR #294](https://github.com/DidierRLopes/GamestonkTerminal/pull/294) * [x] Add recommendation based on technical indicators from Tradingview (@didier) - [PR #301](https://github.com/DidierRLopes/GamestonkTerminal/pull/301) +* [x] Add view of stock historical price with trendlines (support, resistance) by Finviz (@didier) - [PR #317](https://github.com/DidierRLopes/GamestonkTerminal/pull/317) **NEXT** * [ ] Add auto-recognition of major TA patterns (@didier) diff --git a/gamestonk_terminal/discovery/disc_controller.py b/gamestonk_terminal/discovery/disc_controller.py index a39f67e9d1f..c7a4ac40e33 100644 --- a/gamestonk_terminal/discovery/disc_controller.py +++ b/gamestonk_terminal/discovery/disc_controller.py @@ -103,8 +103,10 @@ class DiscoveryController: # Due to Finviz implementation of Spectrum, we delete the generated spectrum figure # after saving it and displaying it to the user if self.spectrum_img_to_delete: - os.remove(self.spectrum_img_to_delete + ".jpg") - self.spectrum_img_to_delete = "" + # Confirm that file exists + if os.path.isfile(self.spectrum_img_to_delete + ".jpg"): + os.remove(self.spectrum_img_to_delete + ".jpg") + self.spectrum_img_to_delete = "" return getattr( self, "call_" + known_args.cmd, lambda: "Command not recognized!" diff --git a/gamestonk_terminal/technical_analysis/README.md b/gamestonk_terminal/technical_analysis/README.md index c670dfa7dbe..c35ebb6bdaa 100644 --- a/gamestonk_terminal/technical_analysis/README.md +++ b/gamestonk_terminal/technical_analysis/README.md @@ -2,6 +2,8 @@ This menu aims to perform a technical analysis on a pre-loaded ticker chart, and the usage of the following commands along with an example will be exploited below. + * [view](#view) + - view historical data and trendlines [Finviz] * [summary](#summary) - technical summary report [FinBrain API] * [recom](#recom) @@ -43,12 +45,22 @@ This menu aims to perform a technical analysis on a pre-loaded ticker chart, and **S/O to https://github.com/twopirllc/pandas-ta** _Owing to this library, it is fairly easy to add other technical indicators. So, let me know if there's any that you would like. Personally I use mostly these ones, hence why I didn't add more._ +## view +``` +usage: view +``` + +View historical price with trendlines. [Source: Finviz] + +![aapl](https://user-images.githubusercontent.com/25267873/113757843-02107700-970b-11eb-99ab-eb9b1312547f.png) + + ## summary ``` usage: summary ``` -Technical summary report provided by FinBrain's API. FinBrain Technologies develops deep learning algorithms for financial analysis and prediction, which currently serves traders from more than 150 countries all around the world. [Source: See https://finbrain.tech] +Technical summary report provided by FinBrain's API. FinBrain Technologies develops deep learning algorithms for financial analysis and prediction, which currently serves traders from more than 150 countries all around the world. [Source: https://finbrain.tech] Captura de ecrã 2021-03-29, às 00 31 29 diff --git a/gamestonk_terminal/technical_analysis/finviz_view.py b/gamestonk_terminal/technical_analysis/finviz_view.py new file mode 100644 index 00000000000..0fc3f794356 --- /dev/null +++ b/gamestonk_terminal/technical_analysis/finviz_view.py @@ -0,0 +1,43 @@ +""" Finviz View """ +__docformat__ = "numpy" + +import argparse +from typing import List +from gamestonk_terminal.helper_funcs import parse_known_args_and_warn +from finvizfinance.quote import finvizfinance +from PIL import Image + + +def view(other_args: List[str], ticker: str): + """View historical price with trendlines. [Source: Finviz] + + Parameters + ---------- + other_args : List[str] + argparse other args + ticker: str + stock ticker + """ + parser = argparse.ArgumentParser( + add_help=False, + prog="view", + description=""" + View historical price with trendlines. [Source: Finviz] + """, + ) + + try: + ns_parser = parse_known_args_and_warn(parser, other_args) + if not ns_parser: + return + + stock = finvizfinance(ticker) + stock.TickerCharts() + + img = Image.open(ticker + ".jpg") + img.show() + + print("") + + except SystemExit: + print("") diff --git a/gamestonk_terminal/technical_analysis/ta_controller.py b/gamestonk_terminal/technical_analysis/ta_controller.py index f53c8ef4e37..7362b2edb26 100644 --- a/gamestonk_terminal/technical_analysis/ta_controller.py +++ b/gamestonk_terminal/technical_analysis/ta_controller.py @@ -2,6 +2,7 @@ __docformat__ = "numpy" import argparse +import os import pandas as pd from typing import List from datetime import datetime @@ -16,6 +17,7 @@ from gamestonk_terminal.technical_analysis import volatility as ta_volatility from gamestonk_terminal.technical_analysis import volume as ta_volume from gamestonk_terminal.technical_analysis import finbrain_view from gamestonk_terminal.technical_analysis import tradingview_view +from gamestonk_terminal.technical_analysis import finviz_view from prompt_toolkit.completion import NestedCompleter @@ -27,6 +29,7 @@ class TechnicalAnalysisController: "help", "q", "quit", + "view", "summary", "recom", "ema", @@ -55,6 +58,7 @@ class TechnicalAnalysisController: self.ticker = ticker self.start = start self.interval = interval + self.delete_img = False self.ta_parser = argparse.ArgumentParser(add_help=False, prog="ta") self.ta_parser.add_argument( "cmd", @@ -79,6 +83,7 @@ class TechnicalAnalysisController: print(" q quit this menu, and shows back to main menu") print(" quit quit to abandon program") print("") + print(" view view historical data and trendlines [Finviz]") print(" summary technical summary report [FinBrain API]") print( " recom recommendation based on Technical Indicators [Tradingview API]" @@ -115,6 +120,14 @@ class TechnicalAnalysisController: """ (known_args, other_args) = self.ta_parser.parse_known_args(an_input.split()) + # Due to Finviz implementation of Spectrum, we delete the generated spectrum figure + # after saving it and displaying it to the user + if self.delete_img: + # Confirm that file exists + if os.path.isfile(self.ticker + ".jpg"): + os.remove(self.ticker + ".jpg") + self.delete_img = False + return getattr( self, "call_" + known_args.cmd, lambda: "Command not recognized!" )(other_args) @@ -131,6 +144,11 @@ class TechnicalAnalysisController: """Process Quit command - quit the program""" return True + def call_view(self, other_args: List[str]): + """Process view command""" + finviz_view.view(other_args, self.ticker) + self.delete_img = True + def call_summary(self, other_args: List[str]): """Process summary command""" finbrain_view.technical_summary_report(other_args, self.ticker)