Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/streamlit-1.37.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JerBouma authored Oct 30, 2024
2 parents 0586c49 + 0b61495 commit 0e96424
Show file tree
Hide file tree
Showing 134 changed files with 5,591 additions and 5,054 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -10,16 +10,16 @@ repos:
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.1"
rev: "v0.6.7"
hooks:
- id: ruff
entry: ruff --ignore PLR0915,S301
entry: ruff check --ignore PLR0915,S301
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.3.0
hooks:
- id: codespell
entry: codespell
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ___

Through the link you are able to subscribe for the free plan and also premium plans at a **15% discount**. This is an affiliate link and thus supports the project at the same time. I have chosen FinancialModelingPrep as a source as I find it to be the most transparent, reliable and at an affordable price. I have yet to find a platform offering such low prices for the amount of data offered. When you notice that the data is inaccurate or have any other issue related to the data, note that I simply provide the means to access this data and I am not responsible for the accuracy of the data itself. For this, use [their contact form](https://site.financialmodelingprep.com/contact) or provide the data yourself.

The dependencies of the package are on purpose *very slim* so that it will work well with any combination of packages and not result in conflicts.
The dependencies of the package are on purpose *very slim* so that it will work well with any combination of packages and not result in conflicts. In case you wish to use the Finance Toolkit in combination with Yahoo Finance, you can do so by installing the optional dependency with `pip install "financetoolkit[yfinance]"`.

# Basic Usage

Expand Down
32 changes: 20 additions & 12 deletions app/initalization_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,16 @@ def create_configurations_section(session_state: st.session_state):
with col1:
session_state["start_date"] = st.date_input(
"Start Date",
value=datetime.now() - timedelta(days=365 * 10)
if session_state["premium_plan"]
else datetime.now() - timedelta(days=365 * 5),
min_value=datetime(1980, 1, 1)
if session_state["premium_plan"]
else datetime.now() - timedelta(days=365 * 5),
value=(
datetime.now() - timedelta(days=365 * 10)
if session_state["premium_plan"]
else datetime.now() - timedelta(days=365 * 5)
),
min_value=(
datetime(1980, 1, 1)
if session_state["premium_plan"]
else datetime.now() - timedelta(days=365 * 5)
),
max_value=datetime.now(),
)
with col2:
Expand Down Expand Up @@ -274,12 +278,16 @@ def initalize_financetoolkit(session_state: st.session_state):
tickers=session_state["tickers"],
api_key=session_state["api_key_value"],
quarterly=session_state["quarterly_data"],
start_date=session_state["start_date"].strftime("%Y-%m-%d")
if session_state["start_date"]
else None,
end_date=session_state["end_date"].strftime("%Y-%m-%d")
if session_state["end_date"]
else None,
start_date=(
session_state["start_date"].strftime("%Y-%m-%d")
if session_state["start_date"]
else None
),
end_date=(
session_state["end_date"].strftime("%Y-%m-%d")
if session_state["end_date"]
else None
),
progress_bar=False,
)

Expand Down
12 changes: 7 additions & 5 deletions app/metrics_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from financetoolkit import Toolkit

# pylint: disable=R0914,W0212,R1735


def plot_data(
variables: list[str],
Expand Down Expand Up @@ -176,11 +178,11 @@ def plot_data(
freq = (
"D"
if "MD" in variable
else "D"
if "TI" in variable
else "Q"
if finance_toolkit._quarterly
else "Y"
else (
"D"
if "TI" in variable
else "Q" if finance_toolkit._quarterly else "Y"
)
)

if column_one:
Expand Down
4 changes: 1 addition & 3 deletions dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from app import helpers, initalization_model, metrics_view, socials_model

st.set_page_config(
page_title="Finance Toolkit Dashboard", page_icon="🛠️", layout="wide"
)
st.set_page_config(page_title="Finance Toolkit Dashboard", page_icon="🛠️", layout="wide")


st.session_state = initalization_model.initalize_session_state(st.session_state)
Expand Down
11 changes: 5 additions & 6 deletions examples/Finance Toolkit - 0. README Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4092,7 +4092,6 @@
],
"source": [
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"\n",
"# Display corporate bond yields\n",
"display(corporate_bond_yields)\n",
Expand Down Expand Up @@ -4433,23 +4432,23 @@
"source": [
"display(unemployment_rates)\n",
"\n",
"df = unemployment_rates[[\"Colombia\", \"United States\", \"Sweden\", \"Japan\", \"Germany\"]]\n",
"unemployment_rates_df = unemployment_rates[[\"Colombia\", \"United States\", \"Sweden\", \"Japan\", \"Germany\"]]\n",
"\n",
"# Copy to clipboard (this is just to paste the data in the README)\n",
"pd.io.clipboards.to_clipboard(df.to_markdown(), excel=False)\n",
"pd.io.clipboards.to_clipboard(unemployment_rates_df.to_markdown(), excel=False)\n",
"\n",
"index = pd.period_range(\"2017\", \"2022\", freq=\"Y\")\n",
"\n",
"# Convert PeriodIndex to string\n",
"df.index = df.index.astype(str)\n",
"unemployment_rates_df.index = unemployment_rates_df.index.astype(str)\n",
"\n",
"# Plotting with Seaborn for better aesthetics\n",
"plt.figure(figsize=(12, 8))\n",
"sns.set_style(\"whitegrid\")\n",
"palette = sns.color_palette(\"husl\", len(df.columns))\n",
"palette = sns.color_palette(\"husl\", len(unemployment_rates_df.columns))\n",
"\n",
"# Plotting a bar plot\n",
"(df * 100).plot(kind=\"bar\", width=0.8, color=palette, edgecolor=\"black\")\n",
"(unemployment_rates_df * 100).plot(kind=\"bar\", width=0.8, color=palette, edgecolor=\"black\")\n",
"\n",
"plt.title(\"Unemployment Rates Over Time\", fontsize=16)\n",
"plt.xlabel(\"Year\", fontsize=12)\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/Finance Toolkit - 5. Options Module.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"from financetoolkit import Toolkit\n",
"\n",
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/discovery/discovery_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Discovery Module"""

__docformat__ = "google"

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/discovery/discovery_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Discovery Model"""

__docformat__ = "google"

import pandas as pd
Expand Down
21 changes: 6 additions & 15 deletions financetoolkit/economics/economics_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Economics Module"""

__docformat__ = "google"


Expand Down Expand Up @@ -651,9 +652,7 @@ def get_share_prices(
period = (
period
if period is not None
else "quarterly"
if self._quarterly
else "yearly"
else "quarterly" if self._quarterly else "yearly"
)

share_prices = oecd_model.get_share_prices(period=period)
Expand Down Expand Up @@ -728,9 +727,7 @@ def get_long_term_interest_rate(
period = (
period
if period is not None
else "quarterly"
if self._quarterly
else "yearly"
else "quarterly" if self._quarterly else "yearly"
)

long_term_interest_rate = oecd_model.get_long_term_interest_rate(
Expand Down Expand Up @@ -809,9 +806,7 @@ def get_short_term_interest_rate(
period = (
period
if period is not None
else "quarterly"
if self._quarterly
else "yearly"
else "quarterly" if self._quarterly else "yearly"
)

short_term_interest_rate = oecd_model.get_short_term_interest_rate(
Expand Down Expand Up @@ -884,9 +879,7 @@ def get_exchange_rates(
period = (
period
if period is not None
else "quarterly"
if self._quarterly
else "yearly"
else "quarterly" if self._quarterly else "yearly"
)

exchange_rates = oecd_model.get_exchange_rates(period=period)
Expand Down Expand Up @@ -1184,9 +1177,7 @@ def get_unemployment_rate(
period = (
period
if period is not None
else "quarterly"
if self._quarterly
else "yearly"
else "quarterly" if self._quarterly else "yearly"
)

unemployment_rate = oecd_model.get_unemployment_rate(period=period)
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/economics/oecd_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""OECD Model"""

__docformat__ = "google"

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/fixedincome/bond_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bond Model Module"""

import numpy as np


Expand Down
1 change: 1 addition & 0 deletions financetoolkit/fixedincome/ecb_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ECB Model"""

__docformat__ = "google"

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/fixedincome/euribor_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ECB Model"""

__docformat__ = "google"

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/fixedincome/fed_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""FED Model"""

__docformat__ = "google"

import pandas as pd
Expand Down
35 changes: 18 additions & 17 deletions financetoolkit/fixedincome/fixedincome_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fixed Income Module"""

__docformat__ = "google"


Expand Down Expand Up @@ -546,17 +547,17 @@ def get_yield_to_maturity(
for price in bond_price:
yield_to_maturities[price] = {}
for maturity in years_to_maturity:
(
yield_to_maturities[price][maturity]
) = bond_model.get_yield_to_maturity(
par_value=par_value,
coupon_rate=coupon_rate,
years_to_maturity=maturity,
bond_price=price,
frequency=frequency,
guess=guess,
tolerance=tolerance,
max_iterations=max_iterations,
(yield_to_maturities[price][maturity]) = (
bond_model.get_yield_to_maturity(
par_value=par_value,
coupon_rate=coupon_rate,
years_to_maturity=maturity,
bond_price=price,
frequency=frequency,
guess=guess,
tolerance=tolerance,
max_iterations=max_iterations,
)
)

yield_to_maturities_df = pd.DataFrame.from_dict(
Expand Down Expand Up @@ -672,9 +673,11 @@ def get_derivative_price(
strike_rate = (
np.arange(
max(
forward_rate - 0.005 * 20
if not is_receiver
else forward_rate - 0.005 * 5,
(
forward_rate - 0.005 * 20
if not is_receiver
else forward_rate - 0.005 * 5
),
0.005,
),
forward_rate + 0.005 * 20 if is_receiver else forward_rate + 0.005 * 5,
Expand Down Expand Up @@ -837,9 +840,7 @@ def get_government_bond_yield(
period = (
period
if period is not None
else "quarterly"
if self._quarterly
else "yearly"
else "quarterly" if self._quarterly else "yearly"
)

if short_term:
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/fixedincome/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helpers"""

__docformat__ = "google"

import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions financetoolkit/fundamentals_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fundamentals Module"""

__docformat__ = "google"


Expand Down
1 change: 1 addition & 0 deletions financetoolkit/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helpers Module"""

__docformat__ = "google"

import inspect
Expand Down
Loading

0 comments on commit 0e96424

Please sign in to comment.