Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
debpal committed Dec 7, 2024
1 parent 68390f4 commit 60b2f59
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.11"]
python-version: ["3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
37 changes: 4 additions & 33 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,18 @@ on:
- '**/*.py' # Trigger only for changes in Python files

jobs:
test-python-3-12:
name: Test with Python 3.12
test-python-3-13:
name: Test with Python 3.13
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4 # This checks out your code to the runner

- name: Set up Python 3.12
- name: Set up Python 3.13
uses: actions/setup-python@v3 # Sets up the specified Python version
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-gh-action.txt # Install dependencies
- name: Run tests with pytest
run: |
export PYTHONPATH=$(pwd)
pytest --cov=BharatFinTrack --cov-report=xml # Run tests and generate coverage report in XML format
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.2.0
with:
token: ${{ secrets.CODECOV_TOKEN }} # This secret token should be added in your repository settings

test-python-3-11:
name: Test with Python 3.11
runs-on: ubuntu-latest
needs: test-python-3-12 # Runs only after the Python 3.12 tests complete

steps:
- name: Checkout repository
uses: actions/checkout@v4 # This checks out your code to the runner

- name: Set up Python 3.11
uses: actions/setup-python@v3 # Sets up the specified Python version
with:
python-version: "3.11"
python-version: "3.13"

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.11"]
python-version: ["3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
Binary file modified BharatFinTrack/data/equity_indices.xlsx
Binary file not shown.
26 changes: 16 additions & 10 deletions BharatFinTrack/nse_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def download_daily_summary_report(
A DataFrame containing the daily summary for all NSE indices.
'''

# check folder path
if not os.path.isdir(folder_path):
raise Exception('The folder path does not exist.')
else:
pass

# web request headers
headers = Core().default_http_headers if http_headers is None else http_headers

Expand All @@ -59,20 +65,20 @@ def download_daily_summary_report(
features='html.parser'
)
for anchor in soup.find_all('a'):
if anchor['href'].endswith('.csv') and anchor['id'] == 'dailysnapOneDaybefore':
csv_link = main_url + anchor['href']
response = requests.get(
url=csv_link,
headers=headers
)
if os.path.isdir(folder_path):
try:
if anchor['href'].endswith('.csv') and anchor['id'] == 'dailysnapOneDaybefore':
csv_link = main_url + anchor['href']
response = requests.get(
url=csv_link,
headers=headers
)
download_file = os.path.join(folder_path, 'summary_index_price_closing_value.csv')
with open(download_file, 'wb') as download_data:
download_data.write(response.content)
output = pandas.read_csv(download_file)
else:
raise Exception('The folder path does not exist.')
else:
pass
except Exception:
pass

return output
Expand Down Expand Up @@ -124,7 +130,7 @@ def equity_cagr_from_launch(
base_df = base_df.drop(columns=['ID', 'API TRI'])
base_df['Base Date'] = base_df['Base Date'].apply(lambda x: x.date())

# fixing unmatched indices with base indinces in the download Dataframe
# fixing unmatched indices with base indices in the download Dataframe
download_unmatch = {
'NIFTY 50 FUTURES INDEX': 'NIFTY 50 FUTURES PR',
'NIFTY 50 FUTURES TR INDEX': 'NIFTY 50 FUTURES TR',
Expand Down
2 changes: 1 addition & 1 deletion BharatFinTrack/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def plot_sip_index_vs_gsec(
x=xticks + bar_width,
height=df['Value'] / monthly_invest,
width=bar_width,
label='Index',
label=index.upper(),
color='lightgreen'
)
for xt in xticks:
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ Using `BharatFinTrack`, you can quickly gain insights into the performance of NS

![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 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`.
In the above graph, the `NIFTY MIDCAP150 MOMENTUM 50` emerges as one of the best-performing NSE equity `TRI` indices in terms of long-term CAGR. The next graph illustrates a comparison of year-wise investments and returns for a monthly SIP of 1,000 Rupees between a government bond and a passive fund tracking the `TRI` data of `NIFTY MIDCAP150 MOMENTUM 50`.

![Year-wise SIP comparison between Government Bond and NIFTY_MIDCAP150_MOMENTUM_50](https://github.com/debpal/BharatFinTrack/raw/master/docs/_static/sip_yearwise_NIFTY_MIDCAP150_MOMENTUM_50.png)

![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 multiples (X) of a monthly SIP investment across `TRI` indices, including the popular index `NIFTY 50` and other top-performing NSE equity indices over the years.

Additionally, the following plot compares the growth multiples (X) of a monthly SIP investment across `TRI` indices, including popular indices such as `NIFTY 50` and `NIFTY 500`, as well as 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)
![Year-wise SIP growth comparison across multiple indices](https://github.com/debpal/BharatFinTrack/raw/master/docs/_static/sip_growth_multiple.png)

## Easy Installation

Expand Down
Binary file added docs/_static/sip_growth_multiple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/sip_gsec_vs_NIFTY_MIDCAP150_MOMENTUM_50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/_static/sip_invest_growth_across_indices.png
Binary file not shown.
Binary file not shown.
Binary file modified docs/_static/tri_top_cagr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/tri_top_cagr_by_category.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
Release Notes
===============


Version 0.1.10
---------------

* **Release date:** 07-Dec-2024

* **Feature Additions:** Added support for newly launched NSE equity indices.

* **Bug Fixes:** Issues with the API used to fetch data.


Version 0.1.9
---------------

Expand Down
5 changes: 1 addition & 4 deletions docs/functionality.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,9 @@ Comparing the growth multiples (X) of a monthly SIP investment across `TRI` indi
index_list = [
'NIFTY 50',
'NIFTY 500',
'NIFTY ALPHA 50',
'NIFTY MIDCAP150 MOMENTUM 50',
'NIFTY500 MOMENTUM 50',
'NIFTY MIDSMALLCAP400 MOMENTUM QUALITY 100',
'NIFTY SMALLCAP250 MOMENTUM QUALITY 100'
'NIFTY500 MOMENTUM 50'
]
nse_tri.sip_growth_comparison_across_indices(
Expand Down
48 changes: 6 additions & 42 deletions docs/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,10 @@ Equity Index Closing Values
-----------------------------

This section provides bar plots of NSE equity indices’ closing values, focusing on `Price` and `TRI` performance metrics sorted by CAGR (%). The data for these visualizations must be sourced from the Excel files generated in the :ref:`Equity Index Price CAGR <f_equity_index_price_cagr>`
and :ref:`Equity TRI CAGR <f_equity_tri_cagr>` sections.
and :ref:`Equity TRI CAGR <f_equity_tri_cagr>` sections.


A bar graph is generated, sorted in descending order by CAGR (≥ 15%) since inception and grouped by index category. Users can substitute `TRI` with `Price` to explore variations.

.. code-block:: python
visual.plot_cagr_filtered_indices_by_category(
excel_file=r"C:\Users\Username\Folder\tri_sort_cagr_by_category.xlsx",
close_type='TRI',
figure_file=r"C:\Users\Username\Folder\plot_tri_sort_cagr_filtered_by_category.png",
threshold_cagr=15
)
The next plot highlights the top five NSE equity indices by `TRI` CAGR (%) within each category since launch.
The following code plots the top five NSE equity indices by `TRI` CAGR (%) within each category since launch.

.. code-block:: python
Expand All @@ -58,39 +46,18 @@ A bar plot of the top 15 NSE equity indices by overall `TRI` CAGR (%) is generat
excel_file=r"C:\Users\Username\Folder\tri_sort_cagr.xlsx",
close_type='TRI',
figure_file=r"C:\Users\Username\Folder\tri_top_cagr.png",
top_cagr=20
top_cagr=15
)
The resulting plot will resemble the example shown below.

.. image:: _static/tri_top_cagr.png
:align: left



SIP Return
-------------
A bar plot displays investments and returns over the years for `TRI` data of the `NIFTY MIDCAP150 MOMENTUM 50` index. 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.


.. code-block:: python
visual.plot_yearwise_sip_returns(
index='NIFTY MIDCAP150 MOMENTUM 50'
excel_file=r"C:\Users\Username\Folder\index_data.xlsx",
figure_file=r"C:\Users\Username\Folder\SIP_Yearwise.png"
)
The resulting plot will look similar to the example below.

.. image:: _static/sip_yearwise_NIFTY_MIDCAP150_MOMENTUM_50.png
:align: left


SIP Comparison with Government Securities
-------------------------------------------
A bar plot displays the comparison of investments and returns over the years for the `TRI` data of the `NIFTY MIDCAP150 MOMENTUM 50` index and government secutity bond with an assumed coupon rate.
A bar plot displays the comparison of investments and returns over the years for the `TRI` data of the `NIFTY MIDCAP150 MOMENTUM 50` index and government secutity bond with an assumed coupon rate. 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.


.. code-block:: python
Expand Down Expand Up @@ -120,24 +87,21 @@ A plot comparing the growth multiples (X) of a monthly SIP investment across `TR
index_list = [
'NIFTY 50',
'NIFTY 500',
'NIFTY ALPHA 50',
'NIFTY MIDCAP150 MOMENTUM 50',
'NIFTY500 MOMENTUM 50',
'NIFTY MIDSMALLCAP400 MOMENTUM QUALITY 100',
'NIFTY SMALLCAP250 MOMENTUM QUALITY 100'
]
visual.plot_sip_growth_comparison_across_indices(
indices=index_list
folder_path=r"C:\Users\Username\Folder",
figure_file=r"C:\Users\Username\Folder\sip_invest_growth_across_indices.png"
figure_file=r"C:\Users\Username\Folder\sip_growth_multiple.png"
)
The produced plot will be comparable to the example depicted below.

.. image:: _static/sip_invest_growth_across_indices.png
.. image:: _static/sip_growth_multiple.png
:align: left


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Intended Audience :: Education",
Expand Down
8 changes: 4 additions & 4 deletions tests/test_bharatfintrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def test_download_historical_daily_data(
@pytest.mark.parametrize(
'index, expected_value',
[
('NIFTY INDIA NEW AGE CONSUMPTION', 14709.71),
('NIFTY INDIA SELECT 5 CORPORATE GROUPS (MAATR)', 47085.20),
('NIFTY INDIA SELECT 5 CORPORATE GROUPS (MAATR)', 45021.65),
('NIFTY INDIA RAILWAYS PSU', 4493.09),
]
)
def test_index_download_historical_daily_data(
Expand All @@ -221,8 +221,8 @@ def test_index_download_historical_daily_data(
df = nse_tri.download_historical_daily_data(
index=index,
excel_file=excel_file,
start_date='15-Oct-2024',
end_date='15-Oct-2024'
start_date='06-Dec-2024',
end_date='06-Dec-2024'
)
assert float(df.iloc[-1, -1]) == expected_value

Expand Down

0 comments on commit 60b2f59

Please sign in to comment.