Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update functionality with FinanceDatabase v2, depreciate stocks/sia, fix exe --example and fix stocks/fa/dcf #4319

Merged
merged 38 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3b8d6a4
Add FinanceDatabase v2
JerBouma Feb 23, 2023
9cf0786
Updates
JerBouma Feb 23, 2023
2c3a7f1
Merge branch 'develop' into feature/finance-database-update
JerBouma Feb 23, 2023
9e480cf
Fixing all the tests I hope
JerBouma Feb 23, 2023
f4daa91
Depreciate the sia menu
JerBouma Feb 23, 2023
b704ca0
Fix routine script
JerBouma Feb 23, 2023
640df80
This needed fixing anyways
JerBouma Feb 23, 2023
1deffe3
deps
jmaslek Feb 23, 2023
fa6f66f
typos
hjoaquim Feb 23, 2023
eeb0743
Merge branch 'feature/finance-database-update' of github.com:OpenBB-f…
hjoaquim Feb 24, 2023
1264ea4
fix /economy/test_yfinance_view tests
hjoaquim Feb 24, 2023
da7fd0a
fix etf/test_stockanalysis_model.py
hjoaquim Feb 24, 2023
60b7bbf
fix etf/test_stockanalysis_view.py
hjoaquim Feb 24, 2023
3c52a52
fix test_stocks_controller
hjoaquim Feb 24, 2023
75099f1
deprecating non used function
hjoaquim Feb 24, 2023
9faad41
update financedatabase to 2.0.4
hjoaquim Feb 24, 2023
a9a27b6
Delete SIA from OpenBB Docs and SDK
JerBouma Feb 24, 2023
7375b93
Searching was not done properly for short name and index
JerBouma Feb 24, 2023
b3598dc
Fix tests I broke
JerBouma Feb 24, 2023
2d47ab2
Little fixy fix to remove duplicates
JerBouma Feb 24, 2023
523a65d
Fix tests
JerBouma Feb 24, 2023
7357c1c
Fix tests
JerBouma Feb 25, 2023
d2396a9
Update code to reflect new changes to FinanceDatabase
JerBouma Feb 25, 2023
bec294b
Merge branch 'develop' into feature/finance-database-update
JerBouma Feb 25, 2023
e1e2293
Small bugfix for DCF if you have no ticker loaded
JerBouma Feb 25, 2023
1ae9115
Delete rogue file and update test and add fixedincome to en.yml
jmaslek Feb 25, 2023
cdcacd1
reqs
jmaslek Feb 26, 2023
68d6970
Merge branch 'develop' into feature/finance-database-update
jmaslek Feb 27, 2023
cf30bda
Update package to v2.0.7
JerBouma Feb 27, 2023
34d7f6a
Remove etf/screener and tests
JerBouma Feb 27, 2023
e15d68e
Updated
JerBouma Feb 27, 2023
b0386ed
Merge branch 'develop' into feature/finance-database-update
jmaslek Feb 27, 2023
3f95656
Merge reqs
jmaslek Feb 27, 2023
01b665d
Little fixy fix
JerBouma Feb 27, 2023
5b3647d
Remove etf/scr from SDK
JerBouma Feb 27, 2023
522c282
Update tests
JerBouma Feb 27, 2023
bcd3421
Update sdk
jmaslek Feb 27, 2023
95fcd76
Etf
jmaslek Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion openbb_terminal/economy/economy_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ def call_index(self, other_args: List[str]):
"-q",
"--query",
type=str,
nargs="+",
dest="query",
help="Search for indices with given keyword",
)
Expand All @@ -862,7 +863,8 @@ def call_index(self, other_args: List[str]):
if ns_parser:
indices = list_from_str(ns_parser.indices)
if ns_parser.query and ns_parser.limit:
yfinance_view.search_indices(ns_parser.query, ns_parser.limit)
query = " ".join(ns_parser.query)
yfinance_view.search_indices(query, ns_parser.limit)
return self.queue

if ns_parser.show_indices:
Expand Down
13 changes: 9 additions & 4 deletions openbb_terminal/economy/yfinance_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,16 @@ def get_search_indices(keyword: list, limit: int = 10) -> pd.DataFrame:
keyword.replace(",", " ") if isinstance(keyword, str) else " ".join(keyword) # type: ignore
)

indices = fd.select_indices()

queried_indices = pd.DataFrame.from_dict(
fd.search_products(indices, keyword_adjusted, "short_name"), orient="index"
indices = fd.Indices()

queried_indices = indices.search(name=keyword_adjusted, exclude_exchanges=True)
queried_indices = pd.concat(
[
queried_indices,
indices.search(index=keyword_adjusted),
]
)
queried_indices = queried_indices.drop_duplicates()

queried_indices = queried_indices.iloc[:limit]

Expand Down
29 changes: 23 additions & 6 deletions openbb_terminal/etf/financedatabase_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Dict, List

import financedatabase as fd
import numpy as np
import pandas as pd

from openbb_terminal.decorators import log_start_end

Expand All @@ -25,8 +27,13 @@ def get_etfs_by_name(name: str) -> Dict:
data : Dict[str, Any]
Dictionary with ETFs that match a certain name
"""
data = fd.select_etfs()
data = fd.search_products(data, query=name, search="long_name")
etfs = fd.ETFs()

data = etfs.search(name=name, exclude_exchanges=True)
data = pd.concat([data, etfs.search(index=name, exclude_exchanges=True)])

# Ensures that data that's missing values is at the bottom of the DataFrame
data = data.iloc[np.argsort(-data.isnull().mul(-1).sum(axis=1))]

return data

Expand All @@ -46,8 +53,12 @@ def get_etfs_by_description(description: str) -> Dict:
data: Dict[str, Any]
Dictionary with ETFs that match a certain description
"""
data = fd.select_etfs()
data = fd.search_products(data, query=description, search="summary")
etfs = fd.ETFs()

data = etfs.search(summary=description, exclude_exchanges=True)

# Ensures that data that's missing values is at the bottom of the DataFrame
data = data.iloc[np.argsort(-data.isnull().mul(-1).sum(axis=1))]

return data

Expand All @@ -67,7 +78,12 @@ def get_etfs_by_category(category: str) -> Dict:
data: Dict[str, Any]
Dictionary with ETFs that match a certain description
"""
data = fd.select_etfs(category=category)
etfs = fd.ETFs()

data = etfs.select(category=category, exclude_exchanges=True)

# Ensures that data that's missing values is at the bottom of the DataFrame
data = data.iloc[np.argsort(-data.isnull().mul(-1).sum(axis=1))]

return data

Expand All @@ -81,5 +97,6 @@ def get_etfs_categories() -> List[str]:
List[str]
ETF categories
"""
etfs = fd.ETFs()

return fd.show_options("etfs")
return etfs.options("category")
71 changes: 27 additions & 44 deletions openbb_terminal/etf/financedatabase_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
from typing import Optional

import pandas as pd

from openbb_terminal.decorators import log_start_end
from openbb_terminal.etf import financedatabase_model
from openbb_terminal.helper_funcs import export_data, print_rich_table
Expand All @@ -22,7 +20,7 @@ def display_etf_by_name(
export: str = "",
sheet_name: Optional[str] = None,
):
"""Display a selection of ETFs based on name filtered by total assets. [Source: Finance Database]
"""Display a selection of ETFs based on name. [Source: Finance Database]
Parameters
----------
Expand All @@ -36,30 +34,25 @@ def display_etf_by_name(
Type of format to export data
"""
data = financedatabase_model.get_etfs_by_name(name)
if not data:
console.print("No data was found with that name\n")
return

table_data = pd.DataFrame(data).T[
["long_name", "family", "category", "total_assets"]
]
if data.empty:
console.print("No data was found with that name.")
return

# Sort by total assets but it is then dropped due to not being completely up to date
table_data_sorted = table_data.sort_values(by="total_assets", ascending=False)
table_data_sorted = table_data_sorted.drop("total_assets", axis=1)
table_data = data[["name", "family", "category_group", "category"]]

print_rich_table(
table_data_sorted.iloc[:limit],
table_data.iloc[:limit],
show_index=True,
headers=["Name", "Family", "Category"],
title="ETFs by Total Assets",
headers=["Name", "Family", "Category Group", "Category"],
title="ETFs",
)

export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"ln_fd",
table_data_sorted,
table_data,
sheet_name,
)

Expand All @@ -71,8 +64,7 @@ def display_etf_by_description(
export: str = "",
sheet_name: Optional[str] = None,
):
"""Display a selection of ETFs based on description filtered by total assets.
[Source: Finance Database]
"""Display a selection of ETFs based on description. [Source: Finance Database]
Parameters
----------
Expand All @@ -86,29 +78,25 @@ def display_etf_by_description(
Type of format to export data
"""
data = financedatabase_model.get_etfs_by_description(description)
if not data:
console.print("No data was found with that description\n")

if data.empty:
console.print("No data was found with that description.")
return

table_data = pd.DataFrame(data).T[
["long_name", "family", "category", "total_assets"]
]
# Sort by total assets but it is then dropped due to not being completely up to date
table_data_sorted = table_data.sort_values(by="total_assets", ascending=False)
table_data_sorted = table_data_sorted.drop("total_assets", axis=1)
table_data = data[["name", "family", "category_group", "category"]]

print_rich_table(
table_data_sorted.iloc[:limit],
table_data.iloc[:limit],
show_index=True,
headers=["Name", "Family", "Category"],
title="ETFs by Total Assets",
headers=["Name", "Family", "Category Group", "Category"],
title="ETFs",
)

export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"ld",
data,
table_data,
sheet_name,
)

Expand All @@ -120,8 +108,7 @@ def display_etf_by_category(
export: str = "",
sheet_name: Optional[str] = None,
):
"""Display a selection of ETFs based on a category filtered by total assets.
[Source: Finance Database]
"""Display a selection of ETFs based on a category. [Source: Finance Database]
Parameters
----------
Expand All @@ -135,28 +122,24 @@ def display_etf_by_category(
Type of format to export data
"""
data = financedatabase_model.get_etfs_by_category(category)
if not data:
console.print("No data was found on that category\n")

if data.empty:
console.print("No data was found on that category.")
return

table_data = pd.DataFrame(data).T[
["long_name", "family", "category", "total_assets"]
]
# Sort by total assets but it is then dropped due to not being completely up to date
table_data_sorted = table_data.sort_values(by="total_assets", ascending=False)
table_data_sorted = table_data_sorted.drop("total_assets", axis=1)
table_data = data[["name", "family", "category_group", "category"]]

print_rich_table(
table_data_sorted.iloc[:limit],
table_data.iloc[:limit],
show_index=True,
headers=["Name", "Family", "Category"],
title="ETFs by Category and Total Assets",
headers=["Name", "Family", "Category Group", "Category"],
title="ETFs by Category",
)

export_data(
export,
os.path.join(os.path.dirname(os.path.abspath(__file__)), "screener"),
"sbc",
data,
table_data,
sheet_name,
)
54 changes: 0 additions & 54 deletions openbb_terminal/etf/screener/presets/etf_config.ini

This file was deleted.

Loading