Skip to content

Commit

Permalink
version 0.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
debpal committed Nov 2, 2024
1 parent ca6fc2c commit 84f52a4
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 30 deletions.
38 changes: 22 additions & 16 deletions BharatFinTrack/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _mi_df_bar_closing_with_category(

# legend
subplot.legend(
title="Index Category",
title='Index Category',
loc='lower right',
fontsize=12,
title_fontsize=12
Expand Down Expand Up @@ -514,11 +514,12 @@ def plot_yearwise_sip_returns(
index: str,
excel_file: str,
figure_file: str,
ytick_gap: int = 250
ytick_gap: int = 500
) -> matplotlib.figure.Figure:

'''
Returns a bar plot of investment and returns over years for a specified index.
Generates and returns a bar plot of investments and returns for a
monthly SIP of 1,000 Rupees over the years for a specified index.
Parameters
----------
Expand All @@ -538,7 +539,8 @@ def plot_yearwise_sip_returns(
Returns
-------
Figure
A bar plot displaying invest and returns over years for a specified index.
A bar plot displaying the investment and returns of a
monthly SIP of 1,000 Rupees over years for the specified index.
'''

# check validity of input figure file path
Expand Down Expand Up @@ -632,16 +634,17 @@ def plot_yearwise_sip_returns(
axis='y', which='both',
direction='in', length=6, width=1,
left=True, right=True,
labelleft=True
labelleft=True, labelright=True
)
subplot.grid(
visible=True,
which='major', axis='y',
color='gray',
linestyle='--', linewidth=0.3
)
close_date = df['Close Date'].iloc[0].strftime('%d-%b-%Y')
subplot.set_ylabel(
ylabel=f'Amount (Date: {df['Close Date'].iloc[0].strftime("%d-%b-%Y")})',
ylabel=f'Amount (Date: {close_date})',
fontsize=15
)

Expand All @@ -653,7 +656,7 @@ def plot_yearwise_sip_returns(

# figure customization
figure_title = (
f'{index.upper()}: Invest and Return of monthly SIP {monthly_invest} Rupees Over Years'
f'{index.upper()}: Invest and Return with Multiples (X) and XIRR (%) of Monthly SIP {monthly_invest} Rupees Over Years'
)
figure.suptitle(
t=figure_title,
Expand All @@ -670,7 +673,7 @@ def plot_yearwise_sip_returns(

return figure

def plot_sip_index_vs_bank_returns(
def plot_sip_index_vs_gsec(
self,
index: str,
excel_file: str,
Expand All @@ -680,7 +683,8 @@ def plot_sip_index_vs_bank_returns(
) -> matplotlib.figure.Figure:

'''
Returns a bar plot of investment and returns over years for a specified index.
Generates a bar plot comparing the returns of a specified index
and government bonds for a monthly SIP of 1,000 Rupees over the years.'
Parameters
----------
Expand All @@ -703,7 +707,8 @@ def plot_sip_index_vs_bank_returns(
Returns
-------
Figure
A bar plot displaying invest and returns over years for a specified index.
A bar plot showing the return comparison between the specified index
and government bonds for a monthly SIP of 1,000 Rupees over the years.
'''

# check validity of input figure file path
Expand Down Expand Up @@ -814,8 +819,9 @@ def plot_sip_index_vs_bank_returns(
color='gray',
linestyle='--', linewidth=0.3
)
close_date = df['Close Date'].iloc[0].strftime('%d-%b-%Y')
subplot.set_ylabel(
ylabel=f'Amount (Date: {df['Close Date'].iloc[0].strftime("%d-%b-%Y")})',
ylabel=f'Amount (Date: {close_date})',
fontsize=15
)

Expand All @@ -827,7 +833,7 @@ def plot_sip_index_vs_bank_returns(

# figure customization
figure_title = (
f'{index.upper()}: Invest and Return of monthly SIP {monthly_invest} Rupees Over Years'
f'{index.upper()}: Comparison Return Between Index and Government Bond of Monthly SIP {monthly_invest} Rupees Over Years'
)
figure.suptitle(
t=figure_title,
Expand Down Expand Up @@ -901,8 +907,8 @@ def plot_sip_growth_comparison_across_indices(
dataframes.append(df)

# check equal close date for all DataFrames
end_date = dataframes[0]['Close Date'].iloc[0]
equal_closedate = all(map(lambda df: df['Close Date'].iloc[0] == end_date, dataframes))
close_date = dataframes[0]['Close Date'].iloc[0]
equal_closedate = all(map(lambda df: df['Close Date'].iloc[0] == close_date, dataframes))
if equal_closedate is True:
pass
else:
Expand Down Expand Up @@ -982,7 +988,7 @@ def plot_sip_growth_comparison_across_indices(
linestyle='--', linewidth=0.3
)
subplot.set_ylabel(
ylabel=f'Investment Multiple (X) (Date: {df['Close Date'].iloc[0].strftime("%d-%b-%Y")})',
ylabel=f'Multiples (X) of Investment (Date: {close_date.strftime("%d-%b-%Y")})',
fontsize=15
)

Expand All @@ -994,7 +1000,7 @@ def plot_sip_growth_comparison_across_indices(

# figure customization
figure_title = (
'Growth of monthly SIP investment Over Years'
'Growth of Monthly SIP Investment Over Years'
)
figure.suptitle(
t=figure_title,
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@
* Shows bar graphs of top-performing NSE equity indices by CAGR (%) since launch, with options to view a specified number of top indices, either overall or within each category.
* Compares the growth of a monthly SIP investment across multiple NSE equity `TRI` indices over the years.
* Depicts a bar graph of year-wise investments and returns for a monthly SIP of 1,000 Rupees in a specified NSE equity `TRI` index since its inception.
* Provides a return comparison between a specified index and government bonds for a monthly SIP of 1,000 Rupees over the years.


# Example Insights
Using `BharatFinTrack`, you can quickly gain insights into the performance of NSE equity indices. For instance, the following bar plot highlights the top five NSE equity indices by `TRI` CAGR (%) within each category since launch. This snapshot provides a powerful visual for understanding long-term performance trends across different index categories. Since performance data updates with each trading day, you can replicate and customize this analysis to generate up-to-date insights tailored to your research needs or investment strategies.
Using `BharatFinTrack`, you can quickly gain insights into the performance of NSE equity indices. For instance, the following bar plot highlights the top five NSE equity indices by `TRI` CAGR (%) within each category since their respective launches. This snapshot provides a powerful visual overview of long-term performance trends of investment multiples (X) across different index categories over the years. Because performance data updates daily with each trading session, you can replicate and customize this analysis to generate up-to-date insights tailored to your research needs or investment strategies.

![Category-wise Top Five TRI CAGR(%) of NSE Equity Indices](https://github.com/debpal/BharatFinTrack/raw/master/docs/_static/tri_top_cagr_by_category.png)

In this graph, the `NIFTY MIDCAP150 MOMENTUM 50` stands out as one of the best-performing NSE equity `TRI` indices in terms of long-term CAGR. The following graph displays the year-wise investments and returns for a monthly SIP of 1,000 Rupees into a passive fund tracking the `TRI` data of `NIFTY MIDCAP150 MOMENTUM 50`.
In this graph, the `NIFTY MIDCAP150 MOMENTUM 50` stands out as one of the best-performing NSE equity `TRI` indices in terms of long-term CAGR. The next graph illustrates the year-wise investments and returns, shown as investment multiples (X) and XIRR (%), for a monthly SIP of 1,000 Rupees in a passive fund tracking the `TRI` data of `NIFTY MIDCAP150 MOMENTUM 50`.


![Year-wise SIP analysis of NIFTY_MIDCAP150_MOMENTUM_50](https://github.com/debpal/BharatFinTrack/raw/master/docs/_static/sip_yearwise_NIFTY_MIDCAP150_MOMENTUM_50.png)

Additionally, the following plot compares the growth of a monthly SIP investment across `TRI` indices, including `NIFTY 50` and several other top-performing NSE equity indices over the years.

![Year-wise SIP growth comparison across multiple indices](https://github.com/debpal/BharatFinTrack/raw/master/docs/_static/sip_invest_growth_across_indices.png)

## Easy Installation

To install, use pip:
Expand Down
Binary file modified docs/_static/sip_invest_growth_across_indices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Release Notes
Version 0.1.8
---------------

* **Release date:** 01-Nov-2024
* **Release date:** 02-Nov-2024

* **Feature Additions:**

Expand Down
1 change: 1 addition & 0 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ Visualization
* Shows bar graphs of top-performing NSE equity indices by CAGR (%) since launch, with options to view a specified number of top indices, either overall or within each category.
* Compares the growth of a monthly SIP investment across multiple NSE equity `TRI` indices over the years.
* Depicts a bar graph of year-wise investments and returns for a monthly SIP of 1,000 Rupees in a specified NSE equity `TRI` index since its inception.
* Provides a return comparison between a specified index and government bonds for a monthly SIP of 1,000 Rupees over the years.

1 change: 1 addition & 0 deletions docs/requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ openpyxl
xlsxwriter
beautifulsoup4
matplotlib
pyxirr


9 changes: 4 additions & 5 deletions docs/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,20 @@ The resulting plot will look similar to the example below.
:align: left


SIP Comparison
-----------------
SIP Comparison Across Indices
-------------------------------

A line plot comparing monthly SIP investment growth across multiple NSE equity `TRI` indices over the years. Data required to compute the SIP must be sourced from the Excel file generated in the :ref:`Total Return Index (TRI) <f_download_tri>` section. All Excel files must be stored in a folder and each Excel file must be named as {index}.xlsx’ corresponding to the index names provided in the indices list.
A plot comparing the growth of a monthly SIP investment across `TRI` indices, including NIFTY 50 and several other top-performing NSE equity indices over the years. The data required for SIP calculations must be sourced from the Excel files generated in the :ref:`Total Return Index (TRI) <f_download_tri>` section. Ensure that all Excel files are stored in the designated input folder, with each file named as `{index}.xlsx` to correspond to the index names provided in the list of indices.


.. code-block:: python
index_list = [
'NIFTY 50',
'NIFTY ALPHA 50',
'NIFTY MIDCAP150 MOMENTUM 50',
'NIFTY500 MOMENTUM 50',
'NIFTY MIDSMALLCAP400 MOMENTUM QUALITY 100',
'NIFTY SMALLCAP250 MOMENTUM QUALITY 100',
'NIFTY500 MOMENTUM 50'
]
visual.plot_sip_growth_comparison_across_indices(
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ dependencies = [
"openpyxl",
"xlsxwriter",
"beautifulsoup4",
"matplotlib"
"matplotlib",
"pyxirr"
]
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -33,9 +34,9 @@ classifiers = [
dynamic = ["version"]
keywords = [
"NSE Index",
"NSE TRI",
"Download",
"Analysis",
"CAGR",
"SIP",
"Visualization"
]

Expand Down
1 change: 1 addition & 0 deletions requirements-gh-action.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ openpyxl
xlsxwriter
beautifulsoup4
matplotlib
pyxirr
6 changes: 3 additions & 3 deletions tests/test_bharatfintrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ def test_sip(
)
assert os.path.exists(figure_file) is True
# pass test for comparison plot of SIP for index and bank fixed depost
figure_file = os.path.join(tmp_dir, f'sip_index_vs_bank_{index}.png')
visual.plot_sip_index_vs_bank_returns(
figure_file = os.path.join(tmp_dir, f'sip_gsec_vs_{index}.png')
visual.plot_sip_index_vs_gsec(
index=index,
excel_file=input_excel,
figure_file=figure_file,
Expand Down Expand Up @@ -644,7 +644,7 @@ def test_error_figure(
assert exc_info.value.args[0] == message['error_figure']

with pytest.raises(Exception) as exc_info:
visual.plot_sip_index_vs_bank_returns(
visual.plot_sip_index_vs_gsec(
index='NIFTY 50',
excel_file='NIFTY 50.xlsx',
figure_file='figure_file.pn',
Expand Down

0 comments on commit 84f52a4

Please sign in to comment.