mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
Merge pull request #150 from DidierRLopes/fix-fa-market-watch
Fixing MarketWatch FA menu
This commit is contained in:
@@ -33,23 +33,20 @@ def print_fundamental_analysis(s_ticker, s_start, s_interval):
|
||||
print("")
|
||||
print("Market Watch API")
|
||||
print(" income income statement of the company")
|
||||
print(" assets assets of the company")
|
||||
print(" liabilities liabilities and shareholders equity of the company")
|
||||
print(" operating cash flow operating activities of the company")
|
||||
print(" investing cash flow investing activities of the company")
|
||||
print(" financing cash flow financing activities of the company")
|
||||
print(" balance balance sheet of the company")
|
||||
print(" cash cash flow statement of the company")
|
||||
print("")
|
||||
print("Yahoo Finance API")
|
||||
print(" info information scope of the company")
|
||||
print(" shrs hareholders of the company")
|
||||
print(" shrs shareholders of the company")
|
||||
print(" sust sustainability values of the company")
|
||||
print(" cal calendar earnings and estimates of the company")
|
||||
print("")
|
||||
print("Alpha Vantage API")
|
||||
print(" overview overview of the company")
|
||||
print(" incom income statements of the company")
|
||||
print(" balance balance sheet of the company")
|
||||
print(" cash cash flow of the company")
|
||||
print(" alpha_income income statements of the company")
|
||||
print(" alpha_balance balance sheet of the company")
|
||||
print(" alpha_cash cash flow of the company")
|
||||
print(" earnings earnings dates and reported EPS")
|
||||
print("")
|
||||
print("Financial Modeling Prep API")
|
||||
@@ -57,9 +54,9 @@ def print_fundamental_analysis(s_ticker, s_start, s_interval):
|
||||
print(" quote quote of the company")
|
||||
print(" enterprise enterprise value of the company over time")
|
||||
print(" dcf discounted cash flow of the company over time")
|
||||
print(" inc income statements of the company")
|
||||
print(" bal balance sheet of the company")
|
||||
print(" cashf cash flow of the company")
|
||||
print(" fmp_income income statements of the company")
|
||||
print(" fmp_balance balance sheet of the company")
|
||||
print(" fmp_cash cash flow statement of the company")
|
||||
print(" metrics key metrics of the company")
|
||||
print(" ratios financial ratios of the company")
|
||||
print(" growth financial statement growth of the company")
|
||||
@@ -113,24 +110,21 @@ def fa_menu(s_ticker, s_start, s_interval):
|
||||
"sust",
|
||||
"cal",
|
||||
"income",
|
||||
"assets",
|
||||
"liabilities",
|
||||
"operating",
|
||||
"investing",
|
||||
"financing",
|
||||
"overview",
|
||||
"key",
|
||||
"incom",
|
||||
"balance",
|
||||
"cash",
|
||||
"overview",
|
||||
"key",
|
||||
"alpha_income",
|
||||
"alpha_balance",
|
||||
"alpha_cash",
|
||||
"earnings",
|
||||
"profile",
|
||||
"quote",
|
||||
"enterprise",
|
||||
"dcf",
|
||||
"inc",
|
||||
"bal",
|
||||
"cashf",
|
||||
"fmp_income",
|
||||
"fmp_balance",
|
||||
"fmp_cash",
|
||||
"metrics",
|
||||
"ratios",
|
||||
"growth",
|
||||
@@ -182,20 +176,11 @@ def fa_menu(s_ticker, s_start, s_interval):
|
||||
elif ns_known_args.cmd == "income":
|
||||
mw_api.income(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "assets":
|
||||
mw_api.assets(l_args, s_ticker)
|
||||
elif ns_known_args.cmd == "balance":
|
||||
mw_api.balance(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "liabilities":
|
||||
mw_api.liabilities(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "operating":
|
||||
mw_api.operating(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "investing":
|
||||
mw_api.investing(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "financing":
|
||||
mw_api.financing(l_args, s_ticker)
|
||||
elif ns_known_args.cmd == "cash":
|
||||
mw_api.cash(l_args, s_ticker)
|
||||
|
||||
# YAHOO FINANCE API
|
||||
elif ns_known_args.cmd == "info":
|
||||
@@ -214,13 +199,13 @@ def fa_menu(s_ticker, s_start, s_interval):
|
||||
elif ns_known_args.cmd == "overview":
|
||||
av_api.overview(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "incom":
|
||||
elif ns_known_args.cmd == "alpha_incom":
|
||||
av_api.income_statement(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "balance":
|
||||
elif ns_known_args.cmd == "alpha_balance":
|
||||
av_api.balance_sheet(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "cash":
|
||||
elif ns_known_args.cmd == "alpha_cash":
|
||||
av_api.cash_flow(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "earnings":
|
||||
@@ -241,13 +226,13 @@ def fa_menu(s_ticker, s_start, s_interval):
|
||||
fmp_api.discounted_cash_flow(l_args, s_ticker)
|
||||
|
||||
# Financial statement:
|
||||
elif ns_known_args.cmd == "inc":
|
||||
elif ns_known_args.cmd == "fmp_income":
|
||||
fmp_api.income_statement(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "bal":
|
||||
elif ns_known_args.cmd == "fmp_balance":
|
||||
fmp_api.balance_sheet(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == "cashf":
|
||||
elif ns_known_args.cmd == "fmp_cash":
|
||||
fmp_api.cash_flow(l_args, s_ticker)
|
||||
|
||||
# Ratios:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import re
|
||||
import requests
|
||||
import pandas as pd
|
||||
from bs4 import BeautifulSoup
|
||||
@@ -53,8 +52,6 @@ def income(l_args, s_ticker):
|
||||
|
||||
df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter)
|
||||
|
||||
df_financials = df_financials.drop(index="Item")
|
||||
|
||||
print(df_financials.to_string(index=False))
|
||||
print("")
|
||||
|
||||
@@ -64,10 +61,9 @@ def income(l_args, s_ticker):
|
||||
return
|
||||
|
||||
|
||||
def assets(l_args, s_ticker):
|
||||
def balance(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="assets",
|
||||
prog="balance",
|
||||
description="""
|
||||
Prints either yearly or quarterly assets from balance sheet of the company.
|
||||
The following fields are expected: Cash & Short Term Investments, Cash & Short Term
|
||||
@@ -81,47 +77,8 @@ def assets(l_args, s_ticker):
|
||||
Other Property, Plant & Equipment, Accumulated Depreciation, Total Investments and
|
||||
Advances, Other Long-Term Investments, Long-Term Note Receivables, Intangible Assets,
|
||||
Net Goodwill, Net Other Intangibles, Other Assets [Source: Market Watch]
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-q",
|
||||
"--quarter",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="b_quarter",
|
||||
help="Quarter fundamental data flag.",
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
if ns_parser.b_quarter:
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{s_ticker}/financials/balance-sheet/quarter"
|
||||
else:
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{s_ticker}/financials/balance-sheet"
|
||||
|
||||
df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter)
|
||||
|
||||
df_financials.drop(index="Item")
|
||||
|
||||
print(df_financials.iloc[:33].to_string())
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
def liabilities(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="liabilities",
|
||||
description="""
|
||||
Prints either yearly or quarterly liablities and shareholders' equity from balance
|
||||
Prints either yearly or quarterly liabilities and shareholders' equity from balance
|
||||
sheet of the company. The following fields are expected: ST Debt & Current Portion LT
|
||||
Debt, Short Term Debt, Current Portion of Long Term Debt, Accounts Payable, Accounts
|
||||
Payable Growth, Income Tax Payable, Other Current Liabilities, Dividends Payable,
|
||||
@@ -162,7 +119,7 @@ def liabilities(l_args, s_ticker):
|
||||
|
||||
df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter)
|
||||
|
||||
print(df_financials.iloc[34:].to_string())
|
||||
print(df_financials.to_string(index=False))
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
@@ -171,10 +128,9 @@ def liabilities(l_args, s_ticker):
|
||||
return
|
||||
|
||||
|
||||
def operating(l_args, s_ticker):
|
||||
def cash(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="operating",
|
||||
prog="cash_flow",
|
||||
description="""
|
||||
Prints either yearly or quarterly cash flow operating activities of the company.
|
||||
The following fields are expected: Net Income before Extraordinaries, Net Income
|
||||
@@ -183,90 +139,12 @@ def operating(l_args, s_ticker):
|
||||
Taxes, Investment Tax Credit, Other Funds, Funds from Operations, Extraordinaries,
|
||||
Changes in Working Capital, Receivables, Accounts Payable, Other Assets/Liabilities,
|
||||
and Net Operating Cash Flow Growth. [Source: Market Watch]
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-q",
|
||||
"--quarter",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="b_quarter",
|
||||
help="Quarter fundamental data flag.",
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
if ns_parser.b_quarter:
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{s_ticker}/financials/cash-flow/quarter"
|
||||
else:
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{s_ticker}/financials/cash-flow"
|
||||
|
||||
df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter)
|
||||
|
||||
df_financials.drop(index="Item")
|
||||
|
||||
print(df_financials.iloc[:16].to_string())
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
def investing(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="investing",
|
||||
description="""
|
||||
Prints either yearly or quarterly cash flow investing activities of the company.
|
||||
The following fields are expected: Capital Expenditures, Capital Expenditures Growth,
|
||||
Capital Expenditures/Sales, Capital Expenditures (Fixed Assets), Capital Expenditures
|
||||
(Other Assets), Net Assets from Acquisitions, Sale of Fixed Assets & Businesses,
|
||||
Purchase/Sale of Investments, Purchase of Investments, Sale/Maturity of Investments,
|
||||
Other Uses, Other Sources, Net Investing Cash Flow Growth. [Source: Market Watch]
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-q",
|
||||
"--quarter",
|
||||
action="store_true",
|
||||
default=False,
|
||||
dest="b_quarter",
|
||||
help="Quarter fundamental data flag.",
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
if ns_parser.b_quarter:
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{s_ticker}/financials/cash-flow/quarter"
|
||||
else:
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{s_ticker}/financials/cash-flow"
|
||||
|
||||
df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter)
|
||||
|
||||
print(df_financials.iloc[17:30].to_string())
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
def financing(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="financing",
|
||||
description="""
|
||||
Prints either yearly or quarterly cash flow financing activities of the company.
|
||||
The following fields are expected: Cash Dividends Paid - Total, Common Dividends,
|
||||
Preferred Dividends, Change in Capital Stock, Repurchase of Common & Preferred Stk.,
|
||||
@@ -301,7 +179,7 @@ def financing(l_args, s_ticker):
|
||||
|
||||
df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter)
|
||||
|
||||
print(df_financials.iloc[31:].to_string())
|
||||
print(df_financials.to_string(index=False))
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
@@ -328,26 +206,35 @@ def prepare_df_financials(url_financials: str, quarter: bool) -> pd.DataFrame:
|
||||
columns=a_financials_header[0 : a_financials_header.index(s_header_end_trend)]
|
||||
)
|
||||
|
||||
# Add financials values
|
||||
soup_financials = text_soup_financials.findAll(
|
||||
lambda tag: tag.name == "tr" and tag.get("class") == ["table__row"]
|
||||
find_table = text_soup_financials.findAll(
|
||||
"div", {"class": "element element--table table--fixed financials"}
|
||||
)
|
||||
soup_financials += text_soup_financials.findAll(
|
||||
"tr", {"class": "table__row is-highlighted"}
|
||||
)
|
||||
for financials_info in soup_financials:
|
||||
financials_row = financials_info.text.split("\n")
|
||||
if len(financials_row) > 5:
|
||||
for item in financials_row:
|
||||
if bool(re.search(r"\d", item)):
|
||||
a_financials_info = financials_info.text.split("\n")
|
||||
l_financials = [a_financials_info[2]]
|
||||
l_financials.extend(a_financials_info[5:-2])
|
||||
# Append data values to financials
|
||||
df_financials.loc[len(df_financials.index)] = l_financials
|
||||
break
|
||||
|
||||
# Set item name as index
|
||||
df_financials = df_financials.set_index("Item")
|
||||
if not find_table:
|
||||
return df_financials
|
||||
|
||||
financials_rows = find_table[0].findAll(
|
||||
"tr", {"class": ["table__row is-highlighted", "table__row"]}
|
||||
)
|
||||
|
||||
for a_row in financials_rows:
|
||||
constructed_row = list()
|
||||
financial_columns = a_row.findAll(
|
||||
"td", {"class": ["overflow__cell", "overflow__cell fixed--column"]}
|
||||
)
|
||||
|
||||
if not financial_columns:
|
||||
continue
|
||||
|
||||
for a_column in financial_columns:
|
||||
column_to_text = a_column.text.strip()
|
||||
if "\n" in column_to_text:
|
||||
column_to_text = column_to_text.split("\n")[0]
|
||||
|
||||
if column_to_text == "":
|
||||
continue
|
||||
constructed_row.append(column_to_text)
|
||||
|
||||
df_financials.loc[len(df_financials)] = constructed_row
|
||||
|
||||
return df_financials
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from gamestonk_terminal.discovery.ark_api import (
|
||||
ark_orders,
|
||||
)
|
||||
|
||||
|
||||
class TestDiscoveryArkApi(unittest.TestCase):
|
||||
def test_ark_orders(self):
|
||||
ark_orders(["-n", "2"])
|
||||
# ark_orders(["-n", "2"])
|
||||
return
|
||||
|
||||
@@ -6,4 +6,4 @@ from gamestonk_terminal.fundamental_analysis.market_watch_api import income
|
||||
|
||||
class TestFaMarketWatchApi(unittest.TestCase):
|
||||
def test_income(self):
|
||||
income([], "PLTR")
|
||||
income([], "GME")
|
||||
|
||||
Reference in New Issue
Block a user