mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Add corporate lobbying data to government menu (#486)
* Add corporate lobbying data to government menu * Update README.md * Update quiverquant_view.py
This commit is contained in:
@@ -27,6 +27,8 @@ This data has been provided by [quiverquant](https://www.quiverquant.com).
|
||||
* plot sum of last government contracts
|
||||
* [qtr_contracts](#qtr_contracts)
|
||||
* quarterly government contracts best regression
|
||||
* [top_lobbying](#top_lobbying)
|
||||
* top corporate lobbying tickers
|
||||
|
||||
#### WITH TICKER PROVIDED
|
||||
|
||||
@@ -48,6 +50,8 @@ This data has been provided by [quiverquant](https://www.quiverquant.com).
|
||||
* plot sum of contracts on the ticker
|
||||
* [qtr_contracts_hist](#qtr_contracts_hist)
|
||||
* quarterly government contracts historical
|
||||
* [lobbying](#lobbying)
|
||||
* corporate lobbying details
|
||||
|
||||
## last_congress <a name="last_congress"></a>
|
||||
```text
|
||||
@@ -187,6 +191,17 @@ Quarterly government contracts best regression. [Source: www.quiverquant.com]
|
||||

|
||||
|
||||
|
||||
## top_lobbying <a name="top_lobbying"></a>
|
||||
```text
|
||||
usage: top_lobbying [-t TOP]
|
||||
```
|
||||
Top lobbying spent. [Source: www.quiverquant.com]
|
||||
|
||||
* -t : Top corporate lobbying tickers with biggest amounts. Default 10.
|
||||
|
||||

|
||||
|
||||
|
||||
#### WITH TICKER PROVIDED
|
||||
|
||||
## raw_congress <a name="raw_congress"></a>
|
||||
@@ -285,3 +300,14 @@ Quarterly government contracts historical. [Source: www.quiverquant.com]
|
||||
|
||||

|
||||
|
||||
|
||||
## lobbying <a name="lobbying"></a>
|
||||
```text
|
||||
usage: lobbying [-l LAST]
|
||||
```
|
||||
Lobbying details. [Source: www.quiverquant.com]
|
||||
|
||||
* -l : Last corporate lobbying details. Default: 10.
|
||||
|
||||
<img width="1222" alt="Captura de ecrã 2021-06-03, às 21 25 02" src="https://user-images.githubusercontent.com/25267873/120707931-d1528100-c4b2-11eb-9619-82c896aaa9e7.png">
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ class GovController:
|
||||
"contracts",
|
||||
"qtr_contracts",
|
||||
"qtr_contracts_hist",
|
||||
"top_lobbying",
|
||||
"lobbying",
|
||||
]
|
||||
|
||||
def __init__(
|
||||
@@ -75,6 +77,7 @@ class GovController:
|
||||
print(" last_contracts last government contracts")
|
||||
print(" sum_contracts plot sum of last government contracts")
|
||||
print(" qtr_contracts quarterly government contracts best regression")
|
||||
print(" top_lobbying top corporate lobbying tickers")
|
||||
print("")
|
||||
if self.ticker:
|
||||
print(f"Ticker: {self.ticker}")
|
||||
@@ -87,6 +90,7 @@ class GovController:
|
||||
print(" raw_contracts raw contracts on the ticker")
|
||||
print(" contracts plot sum of contracts on the ticker")
|
||||
print(" qtr_contracts_hist quarterly government contracts historical")
|
||||
print(" lobbying corporate lobbying details")
|
||||
print("")
|
||||
return
|
||||
|
||||
@@ -196,11 +200,19 @@ class GovController:
|
||||
|
||||
def call_qtr_contracts(self, other_args: List[str]):
|
||||
"""Process qtr_contracts command"""
|
||||
quiverquant_view.call_qtr_contracts(other_args)
|
||||
quiverquant_view.qtr_contracts(other_args)
|
||||
|
||||
def call_qtr_contracts_hist(self, other_args: List[str]):
|
||||
"""Process qtr_contracts_hist command"""
|
||||
quiverquant_view.call_qtr_contracts_hist(other_args, self.ticker)
|
||||
quiverquant_view.qtr_contracts_hist(other_args, self.ticker)
|
||||
|
||||
def call_top_lobbying(self, other_args: List[str]):
|
||||
"""Process top_lobbying command"""
|
||||
quiverquant_view.top_lobbying(other_args)
|
||||
|
||||
def call_lobbying(self, other_args: List[str]):
|
||||
"""Process lobbying command"""
|
||||
quiverquant_view.lobbying(other_args, self.ticker)
|
||||
|
||||
|
||||
def menu(ticker: str):
|
||||
|
||||
@@ -13,7 +13,7 @@ def get_government_trading(gov_type: str, ticker: str = "") -> pd.DataFrame:
|
||||
Parameters
|
||||
----------
|
||||
gov_type: str
|
||||
Type of government data between: Congress, Senate, House, Contracts and Quarter-Contracts
|
||||
Type of government data between: Congress, Senate, House, Contracts, Quarter-Contracts and Corporate-Lobbying
|
||||
ticker : str
|
||||
Ticker to get congress trading data from
|
||||
|
||||
@@ -57,6 +57,12 @@ def get_government_trading(gov_type: str, ticker: str = "") -> pd.DataFrame:
|
||||
else:
|
||||
url = "https://api.quiverquant.com/beta/live/govcontracts"
|
||||
|
||||
elif gov_type == "corporate-lobbying":
|
||||
if ticker:
|
||||
url = f"https://api.quiverquant.com/beta/historical/lobbying/{ticker}"
|
||||
else:
|
||||
url = "https://api.quiverquant.com/beta/live/lobbying"
|
||||
|
||||
else:
|
||||
return pd.DataFrame()
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ from gamestonk_terminal.helper_funcs import (
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
# pylint: disable=C0302
|
||||
|
||||
|
||||
def last_government(other_args: List[str], gov_type: str):
|
||||
"""Last government trading
|
||||
@@ -765,7 +767,7 @@ def contracts(other_args: List[str], ticker: str):
|
||||
print(e, "\n")
|
||||
|
||||
|
||||
def call_qtr_contracts(other_args: List[str]):
|
||||
def qtr_contracts(other_args: List[str]):
|
||||
"""Quarter contracts
|
||||
|
||||
Parameters
|
||||
@@ -859,7 +861,6 @@ def call_qtr_contracts(other_args: List[str]):
|
||||
plt.title("Quarterly Government Contracts - Top promising stocks")
|
||||
plt.xlabel("Date")
|
||||
plt.ylabel("Amount [1k $]")
|
||||
plt.show()
|
||||
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
@@ -871,7 +872,7 @@ def call_qtr_contracts(other_args: List[str]):
|
||||
print(e, "\n")
|
||||
|
||||
|
||||
def call_qtr_contracts_hist(other_args: List[str], ticker: str):
|
||||
def qtr_contracts_hist(other_args: List[str], ticker: str):
|
||||
"""Quarter contracts
|
||||
|
||||
Parameters
|
||||
@@ -918,7 +919,6 @@ def call_qtr_contracts_hist(other_args: List[str], ticker: str):
|
||||
plt.title(f"Quarterly Government Contracts Historical on {ticker.upper()}")
|
||||
plt.xlabel("Date")
|
||||
plt.ylabel("Amount [1k $]")
|
||||
plt.show()
|
||||
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
@@ -928,3 +928,129 @@ def call_qtr_contracts_hist(other_args: List[str], ticker: str):
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
|
||||
def top_lobbying(other_args: List[str]):
|
||||
"""Top lobbying based on tickers that have biggest amounts for the past couple months
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
Command line arguments to be processed with argparse
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="top_lobbying",
|
||||
description="Top lobbying. [Source: www.quiverquant.com]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--top",
|
||||
action="store",
|
||||
dest="top",
|
||||
type=check_positive,
|
||||
default=10,
|
||||
help="Top corporate lobbying tickers with biggest amounts",
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
df_lobbying = quiverquant_model.get_government_trading("corporate-lobbying")
|
||||
|
||||
if df_lobbying.empty:
|
||||
print("No corporate lobbying found\n")
|
||||
return
|
||||
|
||||
d_lobbying = {}
|
||||
for symbol in df_lobbying["Ticker"].unique():
|
||||
d_lobbying[symbol] = sum(
|
||||
float(amount)
|
||||
for amount in df_lobbying[df_lobbying["Ticker"] == symbol]
|
||||
.replace(np.nan, 0)["Amount"]
|
||||
.values
|
||||
)
|
||||
|
||||
df_amount = pd.DataFrame.from_dict(
|
||||
d_lobbying, orient="index", columns=["Amount"]
|
||||
).sort_values(by=["Amount"], ascending=False)
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
plt.bar(
|
||||
df_amount.head(ns_parser.top).index,
|
||||
df_amount.head(ns_parser.top).values.flatten() / 1000,
|
||||
)
|
||||
plt.xlabel("Ticker")
|
||||
plt.ylabel("Sum Amount [1k $]")
|
||||
plt.title(
|
||||
f"Total amount spent on corporate lobbying since {df_lobbying['Date'].min()}"
|
||||
)
|
||||
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
|
||||
plt.show()
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
|
||||
def lobbying(other_args: List[str], ticker: str):
|
||||
"""Corporate lobbying details
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
Command line arguments to be processed with argparse
|
||||
ticker: str
|
||||
Ticker to get corporate lobbying data from
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="lobbying",
|
||||
description="Lobbying details [Source: www.quiverquant.com]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--last",
|
||||
action="store",
|
||||
dest="last",
|
||||
type=check_positive,
|
||||
default=10,
|
||||
help="Last corporate lobbying details",
|
||||
)
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
df_lobbying = quiverquant_model.get_government_trading(
|
||||
"corporate-lobbying", ticker=ticker
|
||||
)
|
||||
|
||||
if df_lobbying.empty:
|
||||
print("No corporate lobbying found\n")
|
||||
return
|
||||
|
||||
for _, row in (
|
||||
df_lobbying.sort_values(by=["Date"], ascending=False)
|
||||
.head(ns_parser.last)
|
||||
.iterrows()
|
||||
):
|
||||
amount = (
|
||||
"$" + str(int(float(row["Amount"])))
|
||||
if row["Amount"] is not None
|
||||
else "N/A"
|
||||
)
|
||||
print(f"{row['Date']}: {row['Client']} {amount}")
|
||||
if row["Amount"] is not None:
|
||||
print("\t" + row["Specific_Issue"].replace("\n", " ").replace("\r", ""))
|
||||
print("")
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
Reference in New Issue
Block a user