chameli 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
chameli-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: chameli
3
+ Version: 0.1.1
4
+ Summary: A lightweight Python library for python utilities for holidays, dates, options and other tools
5
+ Author-email: Pankaj Sharma <sharma.pankaj.kumar@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://bitbucket.org/incurrency/chameli
8
+ Project-URL: repository, https://bitbucket.org/incurrency/chameli
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: numpy==1.26.4
11
+ Requires-Dist: pandas==2.2.3
12
+ Requires-Dist: scikit-learn==1.5.0
13
+ Requires-Dist: scipy==1.11.4
14
+ Requires-Dist: pyyaml==6.0
15
+ Requires-Dist: pyreadr==0.5.0
16
+ Requires-Dist: rpy2==3.5.16
17
+ Requires-Dist: pytz==2024.1
18
+ Requires-Dist: selenium==4.0.0
19
+ Requires-Dist: requests==2.32.3
20
+ Requires-Dist: psutil==7.0.0
21
+ Requires-Dist: scp==0.15.0
22
+ Requires-Dist: paramiko==3.5.1
23
+
24
+ # coreutils
25
+
26
+ coreutils is a lightweight Python library providing utilities for working with holidays, dates, options, and other trading-related tools. It is designed to simplify common tasks in quantitative finance and trading workflows.
27
+
28
+ ---
29
+
30
+ ## Features
31
+
32
+ - **Date Utilities**: Simplify date and time operations.
33
+ - **Options Pricing**: Tools for European options calculations.
34
+ - **External Interactions**: Functions for assisting web scraping, reading and writing R files.
35
+ - **Config Management**: Centralized configuration management using YAML files.
36
+
37
+ ---
38
+
39
+ ## Installation
40
+
41
+ Install the package using pip:
42
+
43
+ ```bash
44
+ pip install coreutils
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Functions Overview
50
+
51
+ Below is a list of available functions in each module. For detailed usage, use the `help(function_name)` command in Python.
52
+
53
+ ### `dateutils` Module
54
+ - `load_holidays_by_exchange()`
55
+ - `valid_datetime(sdatetime, out_pattern=None)`
56
+ - `is_business_day(date, exchange="NSE")`
57
+ - `business_days_between(start_date, end_date, include_first=False, include_last=False, exchange="NSE")`
58
+ - `calc_fractional_business_days(start_datetime, end_datetime, exchange="NSE")`
59
+ - `advance_by_biz_days(datetime_, days, adjustment="fbd", exchange="NSE")`
60
+ - `get_last_day_of_month(year, month)`
61
+ - `get_expiry(date, weekly=0, day_of_week=4, exchange="NSE")`
62
+ - `is_aware(datetime_)`
63
+ - `get_aware_dt(datetime_, tz="Asia/Kolkata")`
64
+ - `get_naive_dt(datetime_)`
65
+ - `is_time_between(begin_time, end_time, check_time)`
66
+
67
+ ### `europeanoptions` Module
68
+ - `BlackScholesPrice(S, X, r, sigma, T, OptionType)`
69
+ - `BlackScholesDelta(S, X, r, sigma, T, OptionType)`
70
+ - `BlackScholesGamma(S, X, r, sigma, T)`
71
+ - `BlackScholesVega(S, X, r, sigma, T)`
72
+ - `BlackScholesTheta(S, X, r, sigma, T, OptionType, daysInYear=252)`
73
+ - `BlackScholesIV(S, X, r, T, OptionType, OptionPrice, seed=0.2)`
74
+ - `calc_delta(long_symbol, opt_price, underlying, time, days_in_year=252, risk_free_rate=0, exchange="NSE")`
75
+ - `get_option_price(long_symbol, S, sigma, calc_time, r=0, days_in_year=252, exchange="NSE")`
76
+ - `calc_greeks(long_symbol, opt_price, underlying, calc_time, greeks, days_in_year=252, risk_free_rate=0, exchange="NSE")`
77
+ - `generate_opt_simulation(symbols, quantities, target_date, vol_shift, start_range, end_range, increment, market_data, exchange="NSE")`
78
+ - `find_x_intercepts(price, value)`
79
+
80
+ ### `interactions` Module
81
+ - `readRDS(filename)`
82
+ - `saveRDS(pd_file, path)`
83
+ - `send_mail(send_from, send_to, password, subject, text, files=None, is_html=False)`
84
+ - `get_session_or_driver(url_to_test, get_session=True, headless=False, desktop_session=4, proxy_source=None, api_key=None, proxy_user=None, proxy_password=None, country_code=None, webdriver_path=None)`
85
+
86
+ ### `miscutils` Module
87
+ - `convert_to_dot_dict(dictionary)`
88
+ - `np_ffill(arr, axis=0)`
89
+
90
+ ---
@@ -0,0 +1,67 @@
1
+ # coreutils
2
+
3
+ coreutils is a lightweight Python library providing utilities for working with holidays, dates, options, and other trading-related tools. It is designed to simplify common tasks in quantitative finance and trading workflows.
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ - **Date Utilities**: Simplify date and time operations.
10
+ - **Options Pricing**: Tools for European options calculations.
11
+ - **External Interactions**: Functions for assisting web scraping, reading and writing R files.
12
+ - **Config Management**: Centralized configuration management using YAML files.
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ Install the package using pip:
19
+
20
+ ```bash
21
+ pip install coreutils
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Functions Overview
27
+
28
+ Below is a list of available functions in each module. For detailed usage, use the `help(function_name)` command in Python.
29
+
30
+ ### `dateutils` Module
31
+ - `load_holidays_by_exchange()`
32
+ - `valid_datetime(sdatetime, out_pattern=None)`
33
+ - `is_business_day(date, exchange="NSE")`
34
+ - `business_days_between(start_date, end_date, include_first=False, include_last=False, exchange="NSE")`
35
+ - `calc_fractional_business_days(start_datetime, end_datetime, exchange="NSE")`
36
+ - `advance_by_biz_days(datetime_, days, adjustment="fbd", exchange="NSE")`
37
+ - `get_last_day_of_month(year, month)`
38
+ - `get_expiry(date, weekly=0, day_of_week=4, exchange="NSE")`
39
+ - `is_aware(datetime_)`
40
+ - `get_aware_dt(datetime_, tz="Asia/Kolkata")`
41
+ - `get_naive_dt(datetime_)`
42
+ - `is_time_between(begin_time, end_time, check_time)`
43
+
44
+ ### `europeanoptions` Module
45
+ - `BlackScholesPrice(S, X, r, sigma, T, OptionType)`
46
+ - `BlackScholesDelta(S, X, r, sigma, T, OptionType)`
47
+ - `BlackScholesGamma(S, X, r, sigma, T)`
48
+ - `BlackScholesVega(S, X, r, sigma, T)`
49
+ - `BlackScholesTheta(S, X, r, sigma, T, OptionType, daysInYear=252)`
50
+ - `BlackScholesIV(S, X, r, T, OptionType, OptionPrice, seed=0.2)`
51
+ - `calc_delta(long_symbol, opt_price, underlying, time, days_in_year=252, risk_free_rate=0, exchange="NSE")`
52
+ - `get_option_price(long_symbol, S, sigma, calc_time, r=0, days_in_year=252, exchange="NSE")`
53
+ - `calc_greeks(long_symbol, opt_price, underlying, calc_time, greeks, days_in_year=252, risk_free_rate=0, exchange="NSE")`
54
+ - `generate_opt_simulation(symbols, quantities, target_date, vol_shift, start_range, end_range, increment, market_data, exchange="NSE")`
55
+ - `find_x_intercepts(price, value)`
56
+
57
+ ### `interactions` Module
58
+ - `readRDS(filename)`
59
+ - `saveRDS(pd_file, path)`
60
+ - `send_mail(send_from, send_to, password, subject, text, files=None, is_html=False)`
61
+ - `get_session_or_driver(url_to_test, get_session=True, headless=False, desktop_session=4, proxy_source=None, api_key=None, proxy_user=None, proxy_password=None, country_code=None, webdriver_path=None)`
62
+
63
+ ### `miscutils` Module
64
+ - `convert_to_dot_dict(dictionary)`
65
+ - `np_ffill(arr, axis=0)`
66
+
67
+ ---
@@ -0,0 +1,145 @@
1
+ import logging
2
+ import os
3
+ import sys
4
+ from importlib.resources import files
5
+ from logging.handlers import TimedRotatingFileHandler
6
+
7
+ __version__ = "0.1.9dev3"
8
+
9
+ from .config import is_config_loaded, load_config
10
+
11
+ # Ensure the module's directory is in the system path
12
+ sys.path.append(os.path.dirname(os.path.realpath(__file__)))
13
+
14
+
15
+ def get_default_config_path():
16
+ """Returns the path to the default config file included in the package."""
17
+ try:
18
+ return files("chameli").joinpath("config/config_sample.yaml")
19
+ except FileNotFoundError:
20
+ # Fallback to relative path in the source directory
21
+ return os.path.join(os.path.dirname(__file__), "config/config_sample.yaml")
22
+
23
+
24
+ def configure_logging(
25
+ module_names=None,
26
+ level=logging.WARNING,
27
+ log_file=None,
28
+ clear_existing_handlers=False,
29
+ enable_console=True,
30
+ backup_count=7,
31
+ ):
32
+ """
33
+ Configure logging for specific or all modules in the pyTrade package.
34
+
35
+ Args:
36
+ module_names (list of str): List of module names to enable logging for.
37
+ level (int): Logging level (e.g., logging.DEBUG, logging.INFO).
38
+ log_file (str): Path to the log file. If None, logs will go to console.
39
+ clear_existing_handlers (bool): Whether to clear existing handlers.
40
+ enable_console (bool): Whether console logging is enabled.
41
+ backup_count (int): Number of log files to keep.
42
+ """
43
+ if clear_existing_handlers:
44
+ for handler in logging.root.handlers[:]:
45
+ logging.root.removeHandler(handler)
46
+
47
+ # Create handlers
48
+ handlers = []
49
+ formatter = logging.Formatter("%(asctime)s:%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s")
50
+ if log_file:
51
+ file_handler = TimedRotatingFileHandler(log_file, when="midnight", backupCount=backup_count)
52
+ file_handler.suffix = "%Y%m%d"
53
+ file_handler.setLevel(level)
54
+ file_handler.setFormatter(formatter)
55
+ handlers.append(file_handler)
56
+
57
+ if enable_console:
58
+ console_handler = logging.StreamHandler()
59
+ console_handler.setLevel(level)
60
+ console_handler.setFormatter(formatter)
61
+ handlers.append(console_handler)
62
+
63
+ # Configure logging for specific modules or globally
64
+ if module_names:
65
+ for module_name in module_names:
66
+ logger = logging.getLogger(module_name)
67
+ logger.setLevel(level)
68
+ for handler in handlers:
69
+ logger.addHandler(handler)
70
+ else:
71
+ # Configure root logger if no specific modules are mentioned
72
+ root_logger = logging.getLogger()
73
+ root_logger.setLevel(level)
74
+ for handler in handlers:
75
+ root_logger.addHandler(handler)
76
+
77
+
78
+ # Set default logging level to WARNING and log to console by default
79
+ configure_logging()
80
+
81
+
82
+ def initialize_config(config_file_path: str, force_reload=True):
83
+ """
84
+ Initializes the configuration from the specified file.
85
+
86
+ Args:
87
+ config_file_path (str): Path to the configuration file.
88
+ force_reload (bool): Whether to force reload the configuration.
89
+
90
+ Raises:
91
+ RuntimeError: If the configuration is already loaded
92
+ and force_reload is False.
93
+ """
94
+ if is_config_loaded() and not force_reload:
95
+ raise RuntimeError("Configuration is already loaded.")
96
+ else:
97
+ load_config(config_file_path)
98
+
99
+
100
+ # Initialize configuration with the default config path
101
+ initialize_config(get_default_config_path())
102
+
103
+
104
+ class LazyModule:
105
+ """
106
+ Lazily loads a module when an attribute is accessed.
107
+
108
+ Args:
109
+ module_name (str): The name of the module to load.
110
+ """
111
+
112
+ def __init__(self, module_name):
113
+ self.module_name = module_name
114
+ self.module = None
115
+
116
+ def _load_module(self):
117
+ allowed_modules = [
118
+ "chameli.dateutils",
119
+ "chameli.europeanoptions",
120
+ "chameli.interactions",
121
+ ]
122
+ if self.module_name not in allowed_modules:
123
+ raise ImportError(f"Module {self.module_name} is not allowed.")
124
+ if not self.module:
125
+ if not is_config_loaded():
126
+ raise RuntimeError("Configuration not loaded. Call `initialize_config` first.")
127
+ self.module = __import__(self.module_name, fromlist=[""])
128
+
129
+ def __getattr__(self, name):
130
+ self._load_module()
131
+ return getattr(self.module, name)
132
+
133
+
134
+ # Lazy loading for modules
135
+ dateutils = LazyModule("chameli.dateutils")
136
+ europeanoptions = LazyModule("chameli.europeanoptions")
137
+ interactions = LazyModule("chameli.interactions")
138
+
139
+ __all__ = [
140
+ "dateutils",
141
+ "europeanoptions",
142
+ "interactions",
143
+ "initialize_config",
144
+ "configure_logging",
145
+ ]