mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Display Energy, Metals, Meats, Grains and Softs Futures (#915)
* Add futures overview * update hugo
This commit is contained in:
5
gamestonk_terminal/economy/README.md
vendored
5
gamestonk_terminal/economy/README.md
vendored
@@ -10,6 +10,11 @@ Command|Description|Source
|
||||
`usbonds` | US bonds overview | [Wall St. Journal](https://www.wsj.com)
|
||||
`glbonds` | global bonds overview | [Wall St. Journal](https://www.wsj.com)
|
||||
`currencies` | currencies overview | [Wall St. Journal](https://www.wsj.com)
|
||||
`energy` | energy futures overview | [Finviz](https://finviz.com/futures.ashx)
|
||||
`metals` | metals futures overview | [Finviz](https://finviz.com/futures.ashx)
|
||||
`meats` | meats futures overview | [Finviz](https://finviz.com/futures.ashx)
|
||||
`grains` | grains futures overview | [Finviz](https://finviz.com/futures.ashx)
|
||||
`softs` | softs futures overview | [Finviz](https://finviz.com/futures.ashx)
|
||||
`map` | S&P500 index stocks map | [Finviz](https://finviz.com/map.ashx)
|
||||
`valuation` | valuation of sectors, industry, country | [Finviz](https://finviz.com/groups.ashx)
|
||||
`performance` | performance of sectors, industry, country | [Finviz](https://finviz.com/groups.ashx)
|
||||
|
||||
@@ -72,6 +72,11 @@ class EconomyController:
|
||||
"glbonds",
|
||||
"futures",
|
||||
"currencies",
|
||||
"energy",
|
||||
"metals",
|
||||
"meats",
|
||||
"grains",
|
||||
"softs",
|
||||
"search",
|
||||
"series",
|
||||
"valuation",
|
||||
@@ -115,6 +120,11 @@ Wall St. Journal:
|
||||
glbonds global bonds overview
|
||||
currencies currencies overview
|
||||
Finviz:
|
||||
energy energy futures overview
|
||||
metals metals futures overview
|
||||
meats meats futures overview
|
||||
grains grains futures overview
|
||||
softs softs futures overview
|
||||
map S&P500 index stocks map
|
||||
valuation valuation of sectors, industry, country
|
||||
performance performance of sectors, industry, country
|
||||
@@ -432,6 +442,136 @@ FRED:
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_energy(self, other_args: List[str]):
|
||||
"""Process energy command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="energy",
|
||||
description="Energy future overview. [Source: Finviz]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
finviz_view.display_future(
|
||||
future_type="Energy",
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_metals(self, other_args: List[str]):
|
||||
"""Process metals command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="metals",
|
||||
description="Metals future overview. [Source: Finviz]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
finviz_view.display_future(
|
||||
future_type="Metals",
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_meats(self, other_args: List[str]):
|
||||
"""Process meats command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="meats",
|
||||
description="Meats future overview. [Source: Finviz]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
finviz_view.display_future(
|
||||
future_type="Meats",
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_grains(self, other_args: List[str]):
|
||||
"""Process grains command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="grains",
|
||||
description="Grains future overview. [Source: Finviz]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
finviz_view.display_future(
|
||||
future_type="Grains",
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_softs(self, other_args: List[str]):
|
||||
"""Process softs command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="softs",
|
||||
description="Softs future overview. [Source: Finviz]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
finviz_view.display_future(
|
||||
future_type="Softs",
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_map(self, other_args: List[str]):
|
||||
"""Process map command"""
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
""" Finviz Model """
|
||||
__docformat__ = "numpy"
|
||||
|
||||
from ast import literal_eval
|
||||
import requests
|
||||
import pandas as pd
|
||||
from finvizfinance.group import performance, spectrum, valuation
|
||||
|
||||
from gamestonk_terminal.helper_funcs import get_user_agent
|
||||
|
||||
|
||||
def get_valuation_performance_data(group: str, data_type: str) -> pd.DataFrame:
|
||||
"""Get group (sectors, industry or country) valuation/performance data
|
||||
"""Get group (sectors, industry or country) valuation/performance data. [Source: Finviz]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -26,7 +30,7 @@ def get_valuation_performance_data(group: str, data_type: str) -> pd.DataFrame:
|
||||
|
||||
|
||||
def get_spectrum_data(group: str):
|
||||
"""Get group (sectors, industry or country) valuation/performance data
|
||||
"""Get group (sectors, industry or country) valuation/performance data. [Source: Finviz]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -34,3 +38,40 @@ def get_spectrum_data(group: str):
|
||||
sectors, industry or country
|
||||
"""
|
||||
spectrum.Spectrum().ScreenerView(group=group)
|
||||
|
||||
|
||||
def get_futures() -> dict:
|
||||
"""Get futures data. [Source: Finviz]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
futures : dict
|
||||
Indices, Energy, Metals, Meats, Grains, Softs, Bonds, Currencies
|
||||
"""
|
||||
source = requests.get(
|
||||
"https://finviz.com/futures.ashx", headers={"User-Agent": get_user_agent()}
|
||||
).text
|
||||
|
||||
slice_source = source[
|
||||
source.find("var groups = ") : source.find(
|
||||
"\r\n\r\n groups.forEach(function(group) "
|
||||
)
|
||||
]
|
||||
groups = literal_eval(
|
||||
slice_source[
|
||||
: slice_source.find("\r\n var tiles = ") - 1
|
||||
].strip("var groups = ")
|
||||
)
|
||||
titles = literal_eval(
|
||||
slice_source[
|
||||
slice_source.find("\r\n var tiles = ") : -1
|
||||
].strip("\r\n var tiles = ")
|
||||
)
|
||||
|
||||
d_futures: dict = {}
|
||||
for future in groups:
|
||||
d_futures[future["label"]] = []
|
||||
for ticker in future["contracts"]:
|
||||
d_futures[future["label"]].append(titles[ticker["ticker"]])
|
||||
|
||||
return d_futures
|
||||
|
||||
@@ -3,6 +3,7 @@ __docformat__ = "numpy"
|
||||
|
||||
import os
|
||||
import webbrowser
|
||||
import pandas as pd
|
||||
|
||||
from PIL import Image
|
||||
from tabulate import tabulate
|
||||
@@ -34,7 +35,7 @@ def map_sp500_view(period: str, map_type: str):
|
||||
|
||||
|
||||
def view_group_data(s_group: str, data_type: str, export: str):
|
||||
"""View group (sectors, industry or country) valuation/performance/spectrum data
|
||||
"""View group (sectors, industry or country) valuation/performance/spectrum data. [Source: Finviz]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -87,3 +88,40 @@ def view_group_data(s_group: str, data_type: str, export: str):
|
||||
print(
|
||||
"Invalid data type. Choose between valuation, performance and spectrum.\n"
|
||||
)
|
||||
|
||||
|
||||
def display_future(future_type: str = "Indices", export: str = ""):
|
||||
"""Display table of a particular future type. [Source: Finviz]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
future_type : str
|
||||
From the following: Indices, Energy, Metals, Meats, Grains, Softs, Bonds, Currencies
|
||||
export : str
|
||||
Export data to csv,json,xlsx or png,jpg,pdf,svg file
|
||||
"""
|
||||
d_futures = finviz_model.get_futures()
|
||||
|
||||
df = pd.DataFrame(d_futures[future_type])
|
||||
df = df.set_index("label")
|
||||
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
df[["prevClose", "last", "change"]].fillna(""),
|
||||
showindex=True,
|
||||
floatfmt=".2f",
|
||||
headers=df.columns,
|
||||
tablefmt="fancy_grid",
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(df[["prevClose", "last", "change"]].fillna("").to_string(index=True))
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
future_type.lower(),
|
||||
df,
|
||||
)
|
||||
print("")
|
||||
|
||||
12
website/content/economy/energy/_index.md
vendored
Normal file
12
website/content/economy/energy/_index.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
```
|
||||
usage: energy [--export {csv,json,xlsx}] [-h]
|
||||
```
|
||||
|
||||
Energy future overview. [Source: Finviz]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
--export {csv,json,xlsx}
|
||||
Export dataframe data to csv,json,xlsx file (default: )
|
||||
-h, --help show this help message (default: False)
|
||||
```
|
||||
12
website/content/economy/grains/_index.md
vendored
Normal file
12
website/content/economy/grains/_index.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
```
|
||||
usage: grains [--export {csv,json,xlsx}] [-h]
|
||||
```
|
||||
|
||||
Grains future overview. [Source: Finviz]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
--export {csv,json,xlsx}
|
||||
Export dataframe data to csv,json,xlsx file (default: )
|
||||
-h, --help show this help message (default: False)
|
||||
```
|
||||
12
website/content/economy/meats/_index.md
vendored
Normal file
12
website/content/economy/meats/_index.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
```
|
||||
usage: meats [--export {csv,json,xlsx}] [-h]
|
||||
```
|
||||
|
||||
Meats future overview. [Source: Finviz]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
--export {csv,json,xlsx}
|
||||
Export dataframe data to csv,json,xlsx file (default: )
|
||||
-h, --help show this help message (default: False)
|
||||
```
|
||||
12
website/content/economy/metals/_index.md
vendored
Normal file
12
website/content/economy/metals/_index.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
```
|
||||
usage: metals [--export {csv,json,xlsx}] [-h]
|
||||
```
|
||||
|
||||
Metals future overview. [Source: Finviz]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
--export {csv,json,xlsx}
|
||||
Export dataframe data to csv,json,xlsx file (default: )
|
||||
-h, --help show this help message (default: False)
|
||||
```
|
||||
12
website/content/economy/softs/_index.md
vendored
Normal file
12
website/content/economy/softs/_index.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
```
|
||||
usage: softs [--export {csv,json,xlsx}] [-h]
|
||||
```
|
||||
|
||||
Softs future overview. [Source: Finviz]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
--export {csv,json,xlsx}
|
||||
Export dataframe data to csv,json,xlsx file (default: )
|
||||
-h, --help show this help message (default: False)
|
||||
```
|
||||
10
website/data/menu/main.yml
vendored
10
website/data/menu/main.yml
vendored
@@ -779,6 +779,16 @@ main:
|
||||
ref: "/economy/glbonds"
|
||||
- name: currencies
|
||||
ref: "/economy/currencies"
|
||||
- name: energy
|
||||
ref: "/economy/energy"
|
||||
- name: metals
|
||||
ref: "/economy/metals"
|
||||
- name: meats
|
||||
ref: "/economy/meats"
|
||||
- name: grains
|
||||
ref: "/economy/grains"
|
||||
- name: softs
|
||||
ref: "/economy/softs"
|
||||
- name: map
|
||||
ref: "/economy/map"
|
||||
- name: valuation
|
||||
|
||||
Reference in New Issue
Block a user