Merge pull request #317 from DidierRLopes/add-trendline-view-ta

Add view command to technical analysis with trendlines
This commit is contained in:
DidierRLopes
2021-04-07 00:26:28 +01:00
committed by GitHub
5 changed files with 79 additions and 3 deletions

View File

@@ -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)

View File

@@ -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!"

View File

@@ -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 <a name="view"></a>
```
usage: view
```
View historical price with trendlines. [Source: Finviz]
![aapl](https://user-images.githubusercontent.com/25267873/113757843-02107700-970b-11eb-99ab-eb9b1312547f.png)
## summary <a name="summary"></a>
```
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]
<img width="976" alt="Captura de ecrã 2021-03-29, às 00 31 29" src="https://user-images.githubusercontent.com/25267873/112772089-db758080-9026-11eb-93d5-9fd7a4b40380.png">

View File

@@ -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("")

View File

@@ -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)