Skip to content

Commit

Permalink
update package, docs, .toml and add setup.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
debpal committed Sep 10, 2024
1 parent 5ae6d28 commit ce22e91
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 122 deletions.
2 changes: 1 addition & 1 deletion BharatFinTrack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
]


__version__ = '0.0.2'
__version__ = '0.0.2'
130 changes: 71 additions & 59 deletions BharatFinTrack/nse_track.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
class NSETrack:

'''
Represents characteristics of NSE finance products.
'''



@property
def indices_category(self):

def indices_category(
self
) -> list[str]:

'''
Returns a list categories for NSE indices.
'''

output = [
'broad',
'sectoral',
'thematic',
'broad',
'sectoral',
'thematic',
'strategy'
]

return output


def get_indices_by_category(self, category):


def get_indices_by_category(
self,
category: str
) -> list[str]:

'''
Returns NSE indices for a specified category.
Expand All @@ -37,57 +40,60 @@ def get_indices_by_category(self, category):
list
A list containing the names of indices for the specified category.
'''

indices = {}

# broad index
indices['broad'] = [
'NIFTY 500',
'NIFTY 50'
]

# sectoral index
indices['sectoral'] = [
'NIFTY IT',
'NIFTY BANK'
]

# thematic index
indices['thematic'] = [
'NIFTY EV & NEW AGE AUTOMOTIVE',
'NIFTY INDIA DEFENCE'
]

# strategy index
indices['strategy'] = [
'NIFTY ALPHA 50',
'NIFTY MIDCAP150 MOMENTUM 50'
]

if category in self.indices_category:
pass
else:
raise Exception(f'Invadid category: {category}')

return indices[category]



@property
def downloadable_indices(self):

def downloadable_indices(
self
) -> list[str]:

'''
Returns a list of all indices names.
'''

output = [
index for category in self.indices_category for index in self.get_indices_by_category(category)
i for c in self.indices_category for i in self.get_indices_by_category(c)
]

return output


def is_downloadable_index(self, index):

def is_downloadable_index(
self,
index: str
) -> bool:

'''
Checks whether a specified NSE index name is downloadable.
Expand All @@ -101,22 +107,23 @@ def is_downloadable_index(self, index):
bool
True if the index name is valid, False.
'''

return index in self.downloadable_indices



@property
def indices_base_date(self):

def indices_base_date(
self
) -> dict[str, str]:

'''
Returns a dictionary where keys are indices
Returns a dictionary where keys are indices
and values are their corresponding base dates.
'''

default_date = '01-Apr-2005'

start_date = {}

start_date['01-Jan-1995'] = ['NIFTY 500']
start_date['03-Nov-1995'] = ['NIFTY 50']
start_date['01-Jan-1996'] = ['NIFTY IT']
Expand All @@ -128,16 +135,19 @@ def indices_base_date(self):
]

date_dict = {v: key for key, value in start_date.items() for v in value}

output = dict(
map(lambda x: (x, date_dict.get(x, default_date)), self.downloadable_indices)
)


output = {
index: date_dict.get(index, default_date)
for index in self.downloadable_indices
}

return output


def get_index_base_date(self, index):


def get_index_base_date(
self,
index: str
) -> str:

'''
Returns the base date for a specified NSE index.
Expand All @@ -151,17 +161,19 @@ def get_index_base_date(self, index):
str
The base date of the index in 'DD-MMM-YYYY' format.
'''

if self.is_downloadable_index(index):
pass
else:
raise Exception(f'Invalid index: {index}')

return self.indices_base_date[index]


def get_index_base_value(self, index):


def get_index_base_value(
self,
index: str
) -> float:

'''
Returns the base value for a specified NSE index.
Expand All @@ -175,12 +187,12 @@ def get_index_base_value(self, index):
float
The base value of the index.
'''

if self.is_downloadable_index(index):
pass
else:
raise Exception(f'Invalid index: {index}')

base_value = {'NIFTY IT': 100.0}
return base_value.get(index, 1000.0)

return base_value.get(index, 1000.0)
58 changes: 22 additions & 36 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import sphinx_rtd_theme
sys.path.insert(0, os.path.abspath('..'))

if os.path.abspath('..') in sys.path:
pass
else:
sys.path.append(os.path.abspath('..'))
from BharatFinTrack import __version__

# -- Project information -----------------------------------------------------

Expand All @@ -23,39 +14,34 @@
author = 'Debasish Pal'

# The full version, including alpha/beta/rc tags
from BharatFinTrack import __version__
release = __version__


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
templates_path = [
'_templates'
]

exclude_patterns = [
'_build',
'Thumbs.db',
'.DS_Store'
]

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_theme_path = [
sphinx_rtd_theme.get_html_theme_path()
]

html_static_path = [
'_static'
]
43 changes: 39 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
{ name="Debasish Pal", email="[email protected]" },
]
readme = "README.md"
requires-python = ">=3.12"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 1 - Planning",
"Programming Language :: Python :: 3",
Expand All @@ -21,10 +21,9 @@ classifiers = [
"Topic :: Scientific/Engineering :: Information Analysis"
]
dynamic = ["version"]

keywords = [
"nse index",
"nse total return index",
"total return index(TRI)",
"data download",
"data analysis"
]
Expand All @@ -36,4 +35,40 @@ keywords = [


[tool.setuptools.dynamic]
version = {attr = "BharatFinTrack.__version__"}
version = {attr = "BharatFinTrack.__version__"}


[tool.pytest.ini_options]
addopts = "-rA -Werror --cov=BharatFinTrack"
testpaths = [
"tests"
]


[tool.mypy]
files = [
"BharatFinTrack",
"docs"
]
ignore_missing_imports = true
strict = true


[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py310, py311
[testenv]
deps =
pytest
pytest-cov
commands =
pytest --cov=BharatFinTrack
[testenv:py310]
basepython = C:\\Users\\dpal22\\AppData\\Local\\anaconda3\\envs\\py310\\python.exe
[testenv:py311]
basepython = C:\\Users\\dpal22\\AppData\\Local\\anaconda3\\envs\\py311\\python.exe
"""
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
exclude =
.ipynb_checkpoints
__pycache__
.tox
ignore = E501
Loading

0 comments on commit ce22e91

Please sign in to comment.