eetc-utils 1.0.2__tar.gz → 1.2.0__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.
Files changed (27) hide show
  1. eetc_utils-1.2.0/PKG-INFO +403 -0
  2. eetc_utils-1.2.0/README.md +374 -0
  3. eetc_utils-1.2.0/pyproject.toml +46 -0
  4. eetc_utils-1.2.0/src/eetc_utils/clients/__init__.py +0 -0
  5. eetc_utils-1.2.0/src/eetc_utils/clients/eetc_data.py +376 -0
  6. eetc_utils-1.2.0/src/eetc_utils/clients/eetc_notifications.py +49 -0
  7. eetc_utils-1.2.0/src/eetc_utils/finance.py +360 -0
  8. eetc_utils-1.2.0/src/eetc_utils/options.py +153 -0
  9. eetc_utils-1.2.0/src/eetc_utils/strategy/__init__.py +0 -0
  10. eetc_utils-1.2.0/src/eetc_utils/strategy/backtesting/__init__.py +0 -0
  11. eetc_utils-1.2.0/src/eetc_utils/strategy/backtesting/broker_sim.py +73 -0
  12. eetc_utils-1.2.0/src/eetc_utils/strategy/backtesting/engine.py +68 -0
  13. eetc_utils-1.2.0/src/eetc_utils/strategy/backtesting/metrics.py +41 -0
  14. eetc_utils-1.2.0/src/eetc_utils/strategy/backtesting/strategy.py +19 -0
  15. eetc_utils-1.2.0/src/eetc_utils/strategy/engine.py +68 -0
  16. eetc_utils-1.2.0/src/eetc_utils/strategy/strategy.py +59 -0
  17. eetc-utils-1.0.2/PKG-INFO +0 -81
  18. eetc-utils-1.0.2/README.md +0 -46
  19. eetc-utils-1.0.2/pyproject.toml +0 -30
  20. eetc-utils-1.0.2/setup.cfg +0 -4
  21. eetc-utils-1.0.2/src/eetc_utils/finance.py +0 -250
  22. eetc-utils-1.0.2/src/eetc_utils.egg-info/PKG-INFO +0 -81
  23. eetc-utils-1.0.2/src/eetc_utils.egg-info/SOURCES.txt +0 -9
  24. eetc-utils-1.0.2/src/eetc_utils.egg-info/dependency_links.txt +0 -1
  25. eetc-utils-1.0.2/src/eetc_utils.egg-info/top_level.txt +0 -1
  26. {eetc-utils-1.0.2 → eetc_utils-1.2.0}/LICENSE +0 -0
  27. {eetc-utils-1.0.2 → eetc_utils-1.2.0}/src/eetc_utils/__init__.py +0 -0
@@ -0,0 +1,403 @@
1
+ Metadata-Version: 2.4
2
+ Name: eetc-utils
3
+ Version: 1.2.0
4
+ Summary: EETC Utils Library
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: East Empire Trading Company
8
+ Author-email: eastempiretradingcompany2019@gmail.com
9
+ Maintainer: East Empire Trading Company
10
+ Maintainer-email: eastempiretradingcompany2019@gmail.com
11
+ Requires-Python: >=3.12,<4.0
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Dist: arch (>=8.0.0,<9.0.0)
19
+ Requires-Dist: numpy (>=2.3.4,<3.0.0)
20
+ Requires-Dist: pandas (>=2.3.3,<3.0.0)
21
+ Requires-Dist: pytest (>=9.0.1,<10.0.0)
22
+ Requires-Dist: requests (>=2.28.0,<3.0.0)
23
+ Requires-Dist: setuptools (>=80.9.0,<81.0.0)
24
+ Requires-Dist: wheel (>=0.45.1,<0.46.0)
25
+ Project-URL: Bug Tracker, https://github.com/east-empire-trading-company/eetc-utils/issues
26
+ Project-URL: Homepage, https://github.com/east-empire-trading-company/eetc-utils
27
+ Project-URL: Repository, https://github.com/east-empire-trading-company/eetc-utils
28
+ Description-Content-Type: text/markdown
29
+
30
+ # EETC Utils
31
+
32
+ [![PyPI version](https://badge.fury.io/py/eetc-utils.svg)](https://badge.fury.io/py/eetc-utils)
33
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
35
+
36
+ A Python library providing reusable utilities for financial analysis and algorithmic trading. Built by [East Empire Trading Company](https://github.com/east-empire-trading-company) for quantitative finance and trading strategy development.
37
+
38
+ ## Features
39
+
40
+ ### Finance Utilities
41
+ - **Quantitative Finance Functions**: Kelly Criterion position sizing, DCF valuation, compound interest
42
+ - **GARCH Models**: Advanced volatility forecasting using ARCH library integration
43
+ - **OHLC Data Manipulation**: Convert daily data to weekly timeframes, performance calculations
44
+
45
+ ### Options Trading
46
+ - **Black-Scholes Pricing**: Calculate option prices for calls and puts
47
+ - **Greeks Calculations**: Gamma exposure (GEX) and other option Greeks
48
+ - **Volatility Analysis**: Convert option IV to underlying IV, standard distribution functions
49
+ - **Strike Range Tools**: Find strike prices within percentage ranges
50
+
51
+ ### API Clients
52
+ - **EETC Data Hub Client**: Fetch price data, fundamentals, macroeconomic indicators, and order history
53
+ - **EETC Notifications Client**: Send trade updates and notifications to Telegram channels
54
+
55
+ ### Strategy Framework
56
+ - **Live Trading**: Abstract base classes for implementing live/paper trading strategies
57
+ - **Execution Engine**: Production-ready engine for running trading strategies
58
+ - **Backtesting Framework**: Complete backtesting suite with broker simulation, performance metrics, and result persistence
59
+
60
+ ## Installation
61
+
62
+ ```bash
63
+ pip install eetc-utils
64
+ ```
65
+
66
+ ## Quick Start
67
+
68
+ ### Finance Utilities
69
+
70
+ ```python
71
+ from eetc_utils.finance import (
72
+ calculate_optimal_leverage_kelly,
73
+ intrinsic_value_using_dcf,
74
+ garch_annualized_volatility,
75
+ convert_daily_ohlc_data_to_weekly
76
+ )
77
+ import pandas as pd
78
+
79
+ # Calculate optimal leverage using Kelly Criterion
80
+ price_df = pd.DataFrame({
81
+ 'date': pd.date_range('2020-01-01', periods=200),
82
+ 'close': [100 + i * 0.5 for i in range(200)]
83
+ })
84
+
85
+ leverage = calculate_optimal_leverage_kelly(
86
+ df=price_df,
87
+ position_type="LONG",
88
+ regime_start_date="2020-01-01",
89
+ fractional_kelly_multiplier=0.5,
90
+ use_garch=False
91
+ )
92
+
93
+ # DCF valuation
94
+ intrinsic_value = intrinsic_value_using_dcf(
95
+ cash_flow=1000000000,
96
+ growth_years=10,
97
+ shares=100000000,
98
+ growth_rate=1.15,
99
+ beta=1.2
100
+ )
101
+
102
+ # Forecast volatility using GARCH
103
+ volatility = garch_annualized_volatility(price_df)
104
+
105
+ # Convert daily OHLC to weekly
106
+ weekly_df = convert_daily_ohlc_data_to_weekly(price_df)
107
+ ```
108
+
109
+ ### Options Trading
110
+
111
+ ```python
112
+ from eetc_utils.options import (
113
+ calculate_option_price_black_scholes,
114
+ find_strikes_in_range,
115
+ GEX,
116
+ calculate_underlying_iv_from_option_iv
117
+ )
118
+
119
+ # Calculate Black-Scholes option price
120
+ call_price = calculate_option_price_black_scholes(
121
+ right="C",
122
+ und_price=100.0,
123
+ strike=105.0,
124
+ rate=0.05,
125
+ tte=0.5,
126
+ implied_vol=0.25,
127
+ pv_dividend=0.0
128
+ )
129
+
130
+ # Find strike prices within a range
131
+ strikes = find_strikes_in_range(
132
+ range_length_perc=0.1,
133
+ price=100.0
134
+ )
135
+
136
+ # Calculate Gamma Exposure
137
+ gex = GEX(oi=1000, gamma=0.05)
138
+
139
+ # Convert option IV to underlying IV
140
+ underlying_iv = calculate_underlying_iv_from_option_iv(
141
+ option_implied_vol=0.20,
142
+ t=30/365
143
+ )
144
+ ```
145
+
146
+ ### EETC Data Hub Client
147
+
148
+ ```python
149
+ from eetc_utils.clients.eetc_data import EETCDataClient
150
+ import os
151
+
152
+ # Initialize client (requires EETC_API_KEY environment variable)
153
+ client = EETCDataClient(api_key=os.getenv("EETC_API_KEY"))
154
+
155
+ # Fetch price data
156
+ price_data = client.get_price_data(symbol="AAPL", start_date="2024-01-01")
157
+
158
+ # Get fundamentals
159
+ fundamentals = client.get_fundamentals(symbol="AAPL")
160
+
161
+ # Fetch macroeconomic indicators
162
+ macro_data = client.get_macro_indicators(indicator="GDP", country="US")
163
+ ```
164
+
165
+ ### EETC Notifications Manager Client
166
+
167
+ ```python
168
+ from eetc_utils.clients.eetc_notifications import EETCNotificationsClient
169
+ import os
170
+
171
+ # Initialize client (requires EETC_API_KEY environment variable)
172
+ client = EETCNotificationsClient(api_key=os.getenv("EETC_API_KEY"))
173
+
174
+ # Send trade update via Telegram
175
+ client.send_trade_update_to_telegram(msg="Shorted TSLA x100 at 1312.69.")
176
+ ```
177
+
178
+
179
+ ### Backtesting Framework
180
+
181
+ ```python
182
+ from eetc_utils.strategy.backtesting.strategy import Strategy
183
+ from eetc_utils.strategy.backtesting.engine import BacktestEngine
184
+ import pandas as pd
185
+
186
+ class MyStrategy(Strategy):
187
+ def on_start(self, context):
188
+ self.position = 0
189
+
190
+ def on_data(self, bar, context):
191
+ # Simple moving average crossover
192
+ if len(self.data) < 20:
193
+ return
194
+
195
+ sma_short = self.data['close'].tail(5).mean()
196
+ sma_long = self.data['close'].tail(20).mean()
197
+
198
+ if sma_short > sma_long and self.position == 0:
199
+ context['place_order']('buy', quantity=100)
200
+ self.position = 100
201
+ elif sma_short < sma_long and self.position > 0:
202
+ context['place_order']('sell', quantity=100)
203
+ self.position = 0
204
+
205
+ def on_stop(self, context):
206
+ pass
207
+
208
+ # Load historical data
209
+ data = pd.read_csv("AAPL_historical.csv")
210
+
211
+ # Run backtest
212
+ engine = BacktestEngine(
213
+ strategy=MyStrategy(),
214
+ data=data,
215
+ symbol="AAPL",
216
+ initial_capital=100000,
217
+ commission=0.001
218
+ )
219
+
220
+ results = engine.run()
221
+ print(f"Total Return: {results['total_return']:.2%}")
222
+ print(f"Sharpe Ratio: {results['sharpe_ratio']:.2f}")
223
+ print(f"Max Drawdown: {results['max_drawdown']:.2%}")
224
+ ```
225
+
226
+ ## Documentation
227
+
228
+ ### Module Structure
229
+
230
+ ```
231
+ src/eetc_utils/
232
+ ├── finance.py # Quantitative finance utilities
233
+ ├── options.py # Options pricing and Greeks
234
+ ├── clients/
235
+ │ ├── eetc_data.py # EETC Data Hub API client
236
+ │ └── eetc_notifications.py # Notifications client
237
+ └── strategy/
238
+ ├── strategy.py # Live trading strategy base class
239
+ ├── engine.py # Live trading execution engine
240
+ └── backtesting/
241
+ ├── strategy.py # Backtesting strategy base class
242
+ ├── engine.py # Backtesting engine
243
+ ├── broker_sim.py # Broker simulator
244
+ └── metrics.py # Performance metrics
245
+ ```
246
+
247
+ ### Key Functions & Classes
248
+
249
+ #### Finance Module (`finance.py`)
250
+ - `calculate_optimal_leverage_kelly()`: Calculate optimal leverage using Kelly Criterion
251
+ - `calculate_position_size_kelly()`: Calculate position size based on Kelly Criterion
252
+ - `intrinsic_value_using_dcf()`: Discounted cash flow valuation
253
+ - `garch_annualized_volatility()`: GARCH-based volatility forecasting
254
+ - `convert_daily_ohlc_data_to_weekly()`: Convert daily OHLC data to weekly timeframes
255
+ - `performance_over_time()`: Calculate percentage performance between dates
256
+ - `compound_interest()`: Calculate compound interest
257
+ - `beta_to_discount_rate()`: Map beta to discount rate for DCF
258
+
259
+ #### Options Module (`options.py`)
260
+ - `calculate_option_price_black_scholes()`: Black-Scholes option pricing for calls and puts
261
+ - `find_strikes_in_range()`: Find strike prices within a percentage range
262
+ - `GEX()`: Calculate Gamma Exposure for option contracts
263
+ - `calculate_underlying_iv_from_option_iv()`: Convert option IV to underlying IV
264
+ - `PDF()`: Standard normal probability density function
265
+ - `CND()`: Cumulative normal distribution
266
+ - `D1()`, `D2()`: Black-Scholes d1 and d2 calculations
267
+
268
+ #### API Clients
269
+ - **EETCDataClient**: HTTP client for fetching market data and fundamentals
270
+ - `get_price_data()`: Fetch historical price data
271
+ - `get_fundamentals()`: Get company fundamentals
272
+ - `get_macro_indicators()`: Fetch macroeconomic indicators
273
+ - `get_order_history()`: Retrieve order history
274
+ - **EETCNotificationsClient**: Send trading notifications via Telegram
275
+ - `send_trade_update_to_telegram()`: Send trade notifications
276
+
277
+ #### Strategy Framework
278
+ - **Live Trading**: `Strategy` (ABC) for implementing live strategies
279
+ - **Backtesting**: Simplified `Strategy` class with `on_start()`, `on_data()`, `on_stop()` lifecycle
280
+ - **Engines**: Orchestrate strategy execution (live or backtest)
281
+ - **BrokerSim**: Simulate order execution with configurable slippage and commission
282
+ - **Metrics**: Calculate Sharpe ratio, max drawdown, and other performance statistics
283
+
284
+ ## Development
285
+
286
+ ### Prerequisites
287
+ - Python 3.12+
288
+ - Poetry (for dependency management)
289
+
290
+ ### Setup
291
+
292
+ ```bash
293
+ # Install system dependencies
294
+ sudo apt-get install build-essential
295
+
296
+ # Install Python dependencies
297
+ make update_and_install_python_requirements
298
+ ```
299
+
300
+ ### Code Formatting
301
+
302
+ ```bash
303
+ make reformat_code # Uses black for consistent code style
304
+ ```
305
+
306
+ ### Testing
307
+
308
+ ```bash
309
+ # Run all tests
310
+ python -m pytest tests/
311
+
312
+ # Run specific test file
313
+ python -m pytest tests/test_financials.py
314
+
315
+ # Run with coverage
316
+ python -m pytest tests/ --cov=src/eetc_utils
317
+ ```
318
+
319
+ ### Publishing to PyPI
320
+
321
+ #### Prerequisites
322
+
323
+ Create a `.pypirc` file in the project root with your PyPI API tokens:
324
+
325
+ ```ini
326
+ [distutils]
327
+ index-servers =
328
+ pypi
329
+ testpypi
330
+
331
+ [testpypi]
332
+ repository = https://test.pypi.org/legacy/
333
+ username = __token__
334
+ password = pypi-YOUR_TEST_PYPI_TOKEN_HERE
335
+
336
+ [pypi]
337
+ repository = https://upload.pypi.org/legacy/
338
+ username = __token__
339
+ password = pypi-YOUR_PRODUCTION_PYPI_TOKEN_HERE
340
+ ```
341
+
342
+ **Note**: The `.pypirc` file is already in `.gitignore` and will not be committed to version control.
343
+
344
+ To generate API tokens:
345
+ - **TestPyPI**: https://test.pypi.org/manage/account/token/
346
+ - **Production PyPI**: https://pypi.org/manage/account/token/
347
+
348
+ #### Publishing Steps
349
+
350
+ 1. Update version in `pyproject.toml`:
351
+ - Increment `version` field in `[tool.poetry]` section
352
+ - Update dependencies in `[tool.poetry.dependencies]` if needed
353
+
354
+ 2. Build the package:
355
+ ```bash
356
+ python -m build
357
+ ```
358
+
359
+ 3. Test on PyPI Test:
360
+ ```bash
361
+ make publish_package_on_pypi_test
362
+ ```
363
+
364
+ 4. Publish to production PyPI:
365
+ ```bash
366
+ make publish_package_on_pypi
367
+ ```
368
+
369
+ The Makefile commands automatically read credentials from `.pypirc` and configure Poetry before publishing.
370
+
371
+ ## Configuration
372
+
373
+ ### Environment Variables
374
+
375
+ - `EETC_API_KEY`: API key for EETC Data Hub client (required for data access)
376
+
377
+ ## Contributing
378
+
379
+ Contributions are welcome! Please ensure:
380
+ - Code follows the project's style guide (enforced by `black`)
381
+ - All tests pass before submitting PR
382
+ - New features include appropriate tests
383
+ - Documentation is updated for API changes
384
+
385
+ ## License
386
+
387
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
388
+
389
+ ## Authors
390
+
391
+ - **East Empire Trading Company** - [eastempiretradingcompany2019@gmail.com](mailto:eastempiretradingcompany2019@gmail.com)
392
+ - **Stefan Delic** - [einfach.jung1@gmail.com](mailto:einfach.jung1@gmail.com)
393
+ - **Milos Dovedan** - [dovedanmilosh@gmail.com](mailto:dovedanmilosh@gmail.com)
394
+
395
+ ## Links
396
+
397
+ - **Homepage**: [https://github.com/east-empire-trading-company/eetc-utils](https://github.com/east-empire-trading-company/eetc-utils)
398
+ - **PyPI**: [https://pypi.org/project/eetc-utils/](https://pypi.org/project/eetc-utils/)
399
+ - **Bug Tracker**: [https://github.com/east-empire-trading-company/eetc-utils/issues](https://github.com/east-empire-trading-company/eetc-utils/issues)
400
+
401
+ ## Support
402
+
403
+ For questions, issues, or feature requests, please [open an issue](https://github.com/east-empire-trading-company/eetc-utils/issues) on GitHub.