Add sectors performance

This commit is contained in:
didier
2020-12-27 15:16:30 +00:00
parent 64295c97e0
commit 8c1d733ea4
3 changed files with 41 additions and 1 deletions

View File

@@ -113,7 +113,7 @@ def main():
main_parser = argparse.ArgumentParser(prog='stock_market_bot', add_help=False)
# Add list of arguments that the main parser accepts
main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers' ,'view', 'load', 'clear',
main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers', 'sectors', 'view', 'load', 'clear',
'sma', 'ema', 'macd', 'vwap', 'stoch', 'rsi', 'adx',
'cci', 'aroon', 'bbands', 'ad', 'obv', 'ratings'])
@@ -143,6 +143,11 @@ def main():
smm.gainers(l_args)
continue
# --------------------------------------------------- GAINERS --------------------------------------------------
if ns_known_args.cmd == 'sectors':
smm.sectors(l_args)
continue
# --------------------------------------------------- CLEAR ----------------------------------------------------
elif ns_known_args.cmd == 'clear':
print("Clearing stock ticker to be used for analysis")

View File

@@ -126,3 +126,15 @@ def b_is_stock_market_open():
# Otherwise, Stock Market is open!
return True
# -----------------------------------------------------------------------------------------------------------------------
def long_number_format(s_num):
if s_num.lstrip("-").isdigit():
n_num = int(s_num)
magnitude = 0
while abs(n_num) >= 1000:
magnitude += 1
n_num /= 1000.0
# add more suffixes if you need them
return '%.2f%s' % (n_num, ['', ' K', ' M', ' G', ' T', ' P'][magnitude])
return s_num

View File

@@ -1,10 +1,33 @@
import argparse
from alpha_vantage.sectorperformance import SectorPerformances
from alpha_vantage.timeseries import TimeSeries
import re
import config_bot as cfg
import pandas as pd
from stock_market_helper_funcs import *
# ---------------------------------------------------- SECTORS ----------------------------------------------------
def sectors(l_args):
parser = argparse.ArgumentParser(prog='sectors', description='Plot sectors performance')
try:
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
except SystemExit:
print("")
return
if l_unknown_args:
print(f"The following args couldn't be interpreted: {l_unknown_args}")
sp = SectorPerformances(key=cfg.API_KEY_ALPHAVANTAGE, output_format='pandas')
df_sectors, d_meta_data = sp.get_sector()
df_sectorsf['Rank A: Real-Time Performance'].plot(kind='bar')
plt.title('Real Time Performance (%) per Sector')
plt.tight_layout()
plt.grid()
plt.show()
print("")
# ---------------------------------------------------- GAINERS ----------------------------------------------------
def gainers(l_args):