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

Feature/mstarpy #4068

Merged
merged 62 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
f52eb9c
add mstarpy to new terminal version
Mael-J Dec 9, 2022
35b242c
add mstarpy to new terminal version
Mael-J Dec 9, 2022
c3bcc94
Merge branch 'mstarpy-funds' of https://github.com/Mael-J/OpenBBTermi…
Mael-J Dec 9, 2022
fe8cf2d
Merge branch 'OpenBB-finance:main' into mstarpy-funds
Mael-J Dec 9, 2022
fe8a8d1
Merge branch 'mstarpy-funds' of https://github.com/Mael-J/OpenBBTermi…
Mael-J Dec 9, 2022
9538a5a
add mstarpy with poetry
Mael-J Dec 9, 2022
cc5d337
Merge branch 'main' into mstarpy-funds
jmaslek Dec 9, 2022
1336d9e
Merge branch 'main' into mstarpy-funds
jmaslek Dec 9, 2022
dddcd93
mapping country openbb convention and mstarpy iso
Mael-J Dec 10, 2022
7ccedb1
empty dataframe if no assets
Mael-J Dec 10, 2022
794aa3b
remove investing command
Mael-J Dec 10, 2022
efc9c14
plot with parameters
Mael-J Dec 10, 2022
bf495ca
Merge branch 'mstarpy-funds' of https://github.com/Mael-J/OpenBBTermi…
Mael-J Dec 10, 2022
ccb996e
change source
Mael-J Dec 10, 2022
27785ab
mstarpy in pyproject
Mael-J Dec 10, 2022
5077633
chnage poetry
Mael-J Dec 10, 2022
debc630
change poetry
Mael-J Dec 10, 2022
8594c8b
Merge branch 'mstarpy-funds' of https://github.com/Mael-J/OpenBBTermi…
Mael-J Dec 10, 2022
d0ae671
mstarpy key
Mael-J Dec 11, 2022
cf49588
reformat with black
Mael-J Dec 11, 2022
7fea4e9
spelling instantiated
Mael-J Dec 11, 2022
fd1ad4d
correct instantiate
Mael-J Dec 11, 2022
3cfd947
delete fo to pass codespell test
Mael-J Dec 11, 2022
f049b9d
correction flake8 test
Mael-J Dec 12, 2022
8948b77
correction test mypy
Mael-J Dec 12, 2022
8a45d40
correction pylint
Mael-J Dec 12, 2022
d7aa74f
pass mypy test
Mael-J Dec 12, 2022
f6a8f03
correction test pylint
Mael-J Dec 12, 2022
d853f0e
remove mutable default value
Mael-J Dec 12, 2022
6a3bd11
Merge branch 'main' into mstarpy-funds
jmaslek Dec 15, 2022
e3f84f8
delete equity, comment, add sweden menu
Mael-J Dec 19, 2022
8360611
Merge branch 'OpenBB-finance:main' into mstarpy-funds
Mael-J Dec 19, 2022
6ae457f
delete not used EXPORT_ONLY_RAW_DATA_ALLOWED
Mael-J Dec 19, 2022
2839292
Merge branch 'mstarpy-funds' of https://github.com/Mael-J/OpenBBTermi…
Mael-J Dec 19, 2022
ff5c036
delete not used investpy and yfinance view
Mael-J Dec 19, 2022
72eb7af
Merge branch 'main'
Mael-J Jan 23, 2023
54e545b
Merge branch 'OpenBB-finance:main' into main
Mael-J Jan 26, 2023
50ebf05
Merge branch 'feature/mstarpy'
Mael-J Jan 29, 2023
fd3e177
mstarpy 0.0.2
Mael-J Jan 29, 2023
afaff09
Merge branch 'develop' into feature/mstarpy
hjoaquim Feb 2, 2023
1751245
minor changes to user msgs
hjoaquim Feb 2, 2023
2e62515
added countries to autocompletion
hjoaquim Feb 2, 2023
c0b6a1e
hinting
hjoaquim Feb 2, 2023
80c064f
small change on load
hjoaquim Feb 2, 2023
ec27e39
adjustments and deprecating investpy
hjoaquim Feb 2, 2023
bdafd8f
minor adjustment to also load country on reset
hjoaquim Feb 2, 2023
ab815de
removing forecasting as self.data is not popullated
hjoaquim Feb 2, 2023
f4411f0
adjustments on sector
hjoaquim Feb 2, 2023
f006fab
minor adjustments
hjoaquim Feb 2, 2023
6ed337d
fix tests
hjoaquim Feb 2, 2023
879bb6b
fix tests
hjoaquim Feb 2, 2023
8057fef
Merge branch 'develop' into feature/mstarpy
hjoaquim Feb 2, 2023
31292d7
improved swe functions
hjoaquim Feb 2, 2023
0fe3eaa
Merge branch 'develop' into feature/mstarpy
hjoaquim Feb 2, 2023
c40461c
Merge branch 'feature/mstarpy' of github.com:Mael-J/OpenBBTerminal in…
hjoaquim Feb 2, 2023
a9febc6
plot display Nav
Mael-J Feb 2, 2023
3e98a5b
united_states as default country
Mael-J Feb 2, 2023
8e9d2c5
mstarpy version 0.0.4
Mael-J Feb 2, 2023
f976cf5
Merge branch 'develop' into feature/mstarpy
hjoaquim Feb 3, 2023
f668832
adjustments
hjoaquim Feb 3, 2023
9ae59e1
dependencies
hjoaquim Feb 3, 2023
9fbc7d8
Merge branch 'develop' into feature/mstarpy
hjoaquim Feb 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions openbb_terminal/miscellaneous/data_sources_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,15 @@
"fwd": ["FXEmpire"]
},
"funds": {
"country": ["Investing"],
"overview": ["Investing"],
"search": ["Investing"],
"load": ["Investing"],
"info": ["Investing"],
"plot": ["Investing"],
"sector": ["YahooFinance"],
"equity": ["YahooFinance"],
"country": ["MorningStar"],
"search": ["MorningStar"],
"load": ["MorningStar"],
"info": ["MorningStar"],
"plot": ["MorningStar"],
"sector": ["MorningStar"],
"carbon" : ["MorningStar"],
"exclusion" : ["MorningStar"],
"holdings": ["MorningStar"],
"alswe": ["Avanza"],
"infoswe": ["Avanza"]
},
Expand Down
7 changes: 6 additions & 1 deletion openbb_terminal/miscellaneous/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ en:
forecast: timeseries forecasting with machine learning
portfolio: perform portfolio optimization and look at portfolio performance and attribution
dashboards: interactive dashboards using voila and jupyter notebooks
stocks/filings: the most-recent form submissions to the SEC
stocks/filings: the most-recent form submissions to the SEC
stocks/search: search a specific stock ticker for analysis
stocks/load: load a specific stock ticker and additional info for analysis
stocks/_ticker: Stock
Expand Down Expand Up @@ -861,6 +861,11 @@ en:
funds/alswe: display fund allocation (sector, country, holdings)
funds/infoswe: get fund information
funds/forecast: forecasting techniques
funds/country_ms: set a country for filtering
funds/holdings: holdings of the loaded funds
funds/carbon: carbon metrics
funds/exclusion: exclusion policy
funds/_country_ms: Current Country MorningStar
alternative/hn: Hacker News most popular stories
alternative/covid: COVID menu, cases, deaths, rates
alternative/oss: Open Source menu, star history, repos information
Expand Down
9 changes: 4 additions & 5 deletions openbb_terminal/mutual_funds/avanza_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@


@log_start_end(log=logger)
def get_data(name: str):
def get_data(isin: str):
"""Gets the data from Avanza

Parameters
----------
name: str
Full name of the fund
isin: str
ISIN of the fund
"""
ava_fund = pd.read_csv(
os.path.join("openbb_terminal", "mutual_funds", "avanza_fund_ID.csv"),
index_col=0,
)
ava_fund.index = ava_fund.index.str.upper()
fund_id = ava_fund.loc[name, "ID"]
fund_id = ava_fund.loc[ava_fund["ISIN"] == isin]["ID"].tolist()[0]
url = f"https://www.avanza.se/_api/fund-guide/guide/{fund_id}"
response = request(url)
fund_data = response.json()
Expand Down
14 changes: 8 additions & 6 deletions openbb_terminal/mutual_funds/avanza_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@


@log_start_end(log=logger)
def display_allocation(name: str, focus: str):
def display_allocation(name: str, isin: str, focus: str):
"""Displays the allocation of the selected swedish fund

Parameters
----------
name: str
Full name of the fund
isin: str
ISIN of the fund
focus: str
The focus of the displayed allocation/exposure of the fund
"""
# Taken from: https://github.com/northern-64bit/Portfolio-Report-Generator/tree/main
fund_data = avanza_model.get_data(name.upper())
fund_data = avanza_model.get_data(isin)
if focus in ["holding", "all"]:
table_row = []
console.print("")
Expand Down Expand Up @@ -81,15 +83,15 @@ def display_allocation(name: str, focus: str):


@log_start_end(log=logger)
def display_info(name: str):
def display_info(isin: str):
"""Displays info of swedish funds

Parameters
----------
name: str
Full name of the fund
isin: str
ISIN of the fund
"""
fund_data = avanza_model.get_data(name.upper())
fund_data = avanza_model.get_data(isin)
text = f"\nSwedish Description:\n\n{fund_data['description']}\n\nThe fund is managed by:\n"
for manager in fund_data["fundManagers"]:
text = text + f"\t- {manager['name']} since {manager['startDate']}\n"
Expand Down
125 changes: 125 additions & 0 deletions openbb_terminal/mutual_funds/mstarpy_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import logging

import mstarpy
import pandas as pd

from openbb_terminal.decorators import log_start_end

logger = logging.getLogger(__name__)


@log_start_end(log=logger)
def load_carbon_metrics(loaded_funds: mstarpy.Funds) -> pd.DataFrame:
"""Search mstarpy for carbon metrics

Parameters
----------
loaded_funds: mstarpy.Funds
class mstarpy.Funds instantiated with selected funds

Returns
-------
pd.DataFrame of carbon metrics
"""
carbonMetrics = loaded_funds.carbonMetrics()
return pd.Series(carbonMetrics, name="carbonMetrics").reset_index()


@log_start_end(log=logger)
def load_exclusion_policy(loaded_funds: mstarpy.Funds) -> pd.DataFrame:
"""Search mstarpy exclusion policy in esgData

Parameters
----------
loaded_funds: mstarpy.Funds
class mstarpy.Funds instantiated with selected funds

Returns
-------
pd.DataFrame of exclusion policy
"""
esgData = loaded_funds.esgData()
if "sustainabilityIntentionality" in esgData:
return pd.Series(
esgData["sustainabilityIntentionality"], name="exclusionPolicy"
).reset_index()
return pd.DataFrame()


@log_start_end(log=logger)
def load_funds(
term: str = "",
country: str = "",
) -> mstarpy.Funds:
"""Search mstarpy for matching funds

Parameters
----------
term : str
String that will be searched for. Can be name or isin
country : str
country where the funds is hosted

Returns
-------
mstarpy.Funds
"""
return mstarpy.Funds(term, country)


@log_start_end(log=logger)
def load_holdings(
loaded_funds: mstarpy.Funds, holding_type: str = "all"
) -> pd.DataFrame:
"""Search mstarpy for holdings

Parameters
----------
loaded_funds: mstarpy.Funds
class mstarpy.Funds instantiated with selected funds

holding_type : str
type of holdings, can be all, equity, bond, other

Returns
-------
pd.DataFrame of funds holdings
"""
holdings = loaded_funds.holdings(holding_type)
if holdings.empty:
return pd.DataFrame()
return holdings[["isin", "securityName", "weighting", "country"]]


@log_start_end(log=logger)
def search_funds(
term: str = "",
country: str = "",
pageSize=10,
) -> pd.DataFrame:
"""Search mstarpy for matching funds

Parameters
----------
term : str
String that will be searched for. Can be name or isin
field : list
list of field who will be displayed
country : str
country where the funds is hosted
pageSize : int
length of results to display

Returns
-------
pd.DataFrame
Dataframe containing matches
"""
field = ["SecId", "TenforeId", "LegalName"]
try:
return pd.DataFrame(
mstarpy.search_funds(term, field, country=country, pageSize=pageSize)
)
except RuntimeError as e:
logger.exception(str(e))
return pd.DataFrame()
Loading