financial¶
duallens_analytics.financial
¶
Fetch financial data from Yahoo Finance and build Plotly visualisations.
This module provides two groups of functionality:
- Data fetching – :func:
fetch_stock_historyand :func:fetch_metricspull real-time stock prices and fundamental metrics from Yahoo Finance using theyfinancelibrary. - Charting – :func:
plot_stock_trends, :func:plot_metric_comparison, and :func:plot_metrics_radarreturn interactive Plotly figures ready to be rendered by Streamlit.
fetch_metrics(symbols)
¶
Fetch key financial metrics and return a tidy DataFrame.
The following metrics are retrieved per company:
- Market Cap – scaled to billions (USD).
- P/E Ratio – trailing price-to-earnings.
- Dividend Yield – scaled to percentage.
- Beta – volatility relative to the market.
- Total Revenue – scaled to billions (USD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
list[str]
|
List of Yahoo-Finance ticker symbols. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame
|
class: |
DataFrame
|
per metric. Values are human-readable (billions / percentages). |
Source code in src/duallens_analytics/financial.py
fetch_stock_history(symbols, period=STOCK_PERIOD)
¶
Download OHLCV price history for each ticker symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
list[str]
|
List of Yahoo-Finance ticker symbols
(e.g. |
required |
period
|
str
|
Look-back period accepted by :meth: |
STOCK_PERIOD
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
A dictionary mapping each symbol to a :class: |
dict[str, DataFrame]
|
with columns |
dict[str, DataFrame]
|
and a |
Source code in src/duallens_analytics/financial.py
plot_metric_comparison(df, metric)
¶
Create a bar chart comparing a single metric across companies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Financial-metrics DataFrame as returned by
:func: |
required |
metric
|
str
|
Column name to plot (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |
Source code in src/duallens_analytics/financial.py
plot_metrics_radar(df)
¶
Build a radar (spider) chart overlaying normalised metrics.
Each metric column is min–max normalised to the 0–1 range so that all axes share a common scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Financial-metrics DataFrame as returned by
:func: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |
Figure
|
company. |
Source code in src/duallens_analytics/financial.py
plot_stock_trends(histories)
¶
Build a Plotly line chart of closing prices for all companies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
histories
|
dict[str, DataFrame]
|
Mapping returned by :func: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
Figure
|
class: |