deltafq 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl

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.

Potentially problematic release.


This version of deltafq might be problematic. Click here for more details.

Files changed (60) hide show
  1. deltafq/__init__.py +30 -31
  2. deltafq/backtest/__init__.py +17 -7
  3. deltafq/backtest/engine.py +99 -52
  4. deltafq/backtest/metrics.py +113 -0
  5. deltafq/backtest/performance.py +81 -0
  6. deltafq/backtest/reporter.py +91 -0
  7. deltafq/core/__init__.py +19 -0
  8. deltafq/core/base.py +37 -0
  9. deltafq/core/config.py +63 -0
  10. deltafq/core/exceptions.py +35 -0
  11. deltafq/core/logger.py +46 -0
  12. deltafq/data/__init__.py +17 -7
  13. deltafq/data/cleaner.py +41 -0
  14. deltafq/data/fetcher.py +52 -0
  15. deltafq/data/storage.py +56 -0
  16. deltafq/data/validator.py +52 -0
  17. deltafq/indicators/__init__.py +17 -8
  18. deltafq/indicators/momentum.py +56 -23
  19. deltafq/indicators/technical.py +59 -0
  20. deltafq/indicators/trend.py +129 -61
  21. deltafq/indicators/volatility.py +67 -27
  22. deltafq/live/__init__.py +17 -0
  23. deltafq/live/connection.py +235 -0
  24. deltafq/live/data_feed.py +159 -0
  25. deltafq/live/monitoring.py +192 -0
  26. deltafq/live/risk_control.py +193 -0
  27. deltafq/strategy/__init__.py +17 -6
  28. deltafq/strategy/base_strategy.py +53 -0
  29. deltafq/strategy/portfolio.py +82 -0
  30. deltafq/strategy/risk_manager.py +64 -0
  31. deltafq/strategy/signal_generator.py +52 -0
  32. deltafq/trading/__init__.py +19 -0
  33. deltafq/trading/broker.py +119 -0
  34. deltafq/trading/execution.py +176 -0
  35. deltafq/trading/order_manager.py +111 -0
  36. deltafq/trading/position_manager.py +157 -0
  37. deltafq/trading/simulator.py +150 -0
  38. deltafq-0.1.2.dist-info/METADATA +110 -0
  39. deltafq-0.1.2.dist-info/RECORD +43 -0
  40. deltafq-0.1.2.dist-info/entry_points.txt +2 -0
  41. {deltafq-0.1.1.dist-info → deltafq-0.1.2.dist-info}/licenses/LICENSE +21 -22
  42. deltafq/backtest/result.py +0 -45
  43. deltafq/data/base.py +0 -30
  44. deltafq/data/loader.py +0 -63
  45. deltafq/optimization/__init__.py +0 -6
  46. deltafq/optimization/grid_search.py +0 -41
  47. deltafq/performance/__init__.py +0 -6
  48. deltafq/performance/metrics.py +0 -37
  49. deltafq/risk/__init__.py +0 -7
  50. deltafq/risk/metrics.py +0 -33
  51. deltafq/risk/position.py +0 -39
  52. deltafq/strategy/base.py +0 -44
  53. deltafq/trade/__init__.py +0 -6
  54. deltafq/trade/broker.py +0 -40
  55. deltafq/utils/__init__.py +0 -6
  56. deltafq/utils/time.py +0 -32
  57. deltafq-0.1.1.dist-info/METADATA +0 -202
  58. deltafq-0.1.1.dist-info/RECORD +0 -29
  59. {deltafq-0.1.1.dist-info → deltafq-0.1.2.dist-info}/WHEEL +0 -0
  60. {deltafq-0.1.1.dist-info → deltafq-0.1.2.dist-info}/top_level.txt +0 -0
deltafq/strategy/base.py DELETED
@@ -1,44 +0,0 @@
1
- """策略基类"""
2
-
3
- from abc import ABC, abstractmethod
4
- from typing import Dict, Any
5
- import pandas as pd
6
-
7
-
8
- class Strategy(ABC):
9
- """策略抽象基类"""
10
-
11
- def __init__(self):
12
- self.position = 0 # 当前持仓
13
- self.cash = 100000 # 初始资金
14
- self.signals = [] # 信号记录
15
-
16
- @abstractmethod
17
- def on_bar(self, bar: pd.Series) -> None:
18
- """处理每根K线
19
-
20
- Args:
21
- bar: 包含OHLCV数据的Series
22
- """
23
- pass
24
-
25
- def buy(self, size: float = 1.0) -> None:
26
- """买入信号
27
-
28
- Args:
29
- size: 交易数量
30
- """
31
- self.signals.append({'action': 'buy', 'size': size})
32
-
33
- def sell(self, size: float = 1.0) -> None:
34
- """卖出信号
35
-
36
- Args:
37
- size: 交易数量
38
- """
39
- self.signals.append({'action': 'sell', 'size': size})
40
-
41
- def get_signals(self) -> list:
42
- """获取所有交易信号"""
43
- return self.signals
44
-
deltafq/trade/__init__.py DELETED
@@ -1,6 +0,0 @@
1
- """实盘交易接口模块"""
2
-
3
- from deltafq.trade.broker import Broker
4
-
5
- __all__ = ["Broker"]
6
-
deltafq/trade/broker.py DELETED
@@ -1,40 +0,0 @@
1
- """交易接口抽象"""
2
-
3
- from abc import ABC, abstractmethod
4
- from typing import Dict, Any, List
5
-
6
-
7
- class Broker(ABC):
8
- """券商接口抽象基类"""
9
-
10
- @abstractmethod
11
- def submit_order(
12
- self,
13
- symbol: str,
14
- action: str,
15
- quantity: float,
16
- order_type: str = "market"
17
- ) -> str:
18
- """提交订单
19
-
20
- Args:
21
- symbol: 证券代码
22
- action: 动作 'buy' or 'sell'
23
- quantity: 数量
24
- order_type: 订单类型
25
-
26
- Returns:
27
- 订单ID
28
- """
29
- pass
30
-
31
- @abstractmethod
32
- def get_position(self) -> List[Dict[str, Any]]:
33
- """获取持仓信息"""
34
- pass
35
-
36
- @abstractmethod
37
- def get_account(self) -> Dict[str, Any]:
38
- """获取账户信息"""
39
- pass
40
-
deltafq/utils/__init__.py DELETED
@@ -1,6 +0,0 @@
1
- """工具函数模块"""
2
-
3
- from deltafq.utils.time import is_trading_day, get_trading_dates
4
-
5
- __all__ = ["is_trading_day", "get_trading_dates"]
6
-
deltafq/utils/time.py DELETED
@@ -1,32 +0,0 @@
1
- """时间相关工具函数"""
2
-
3
- import pandas as pd
4
- from datetime import datetime
5
- from typing import List
6
-
7
-
8
- def is_trading_day(date: datetime) -> bool:
9
- """判断是否为交易日
10
-
11
- Args:
12
- date: 日期
13
-
14
- Returns:
15
- 是否为交易日
16
- """
17
- return date.weekday() < 5
18
-
19
-
20
- def get_trading_dates(start: str, end: str) -> List[datetime]:
21
- """获取交易日列表
22
-
23
- Args:
24
- start: 开始日期
25
- end: 结束日期
26
-
27
- Returns:
28
- 交易日列表
29
- """
30
- dates = pd.date_range(start=start, end=end, freq='B')
31
- return dates.tolist()
32
-
@@ -1,202 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: deltafq
3
- Version: 0.1.1
4
- Summary: A professional Python quantitative trading library
5
- Author-email: DeltaFQ Team <your.email@example.com>
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/Delta-F/deltafq
8
- Project-URL: Documentation, https://github.com/Delta-F/deltafq/tree/main/docs
9
- Project-URL: Repository, https://github.com/Delta-F/deltafq
10
- Project-URL: PyPI, https://pypi.org/project/deltafq/
11
- Project-URL: Bug Tracker, https://github.com/Delta-F/deltafq/issues
12
- Keywords: quantitative,trading,finance,backtest,strategy
13
- Classifier: Development Status :: 3 - Alpha
14
- Classifier: Intended Audience :: Financial and Insurance Industry
15
- Classifier: Intended Audience :: Developers
16
- Classifier: License :: OSI Approved :: MIT License
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3.8
19
- Classifier: Programming Language :: Python :: 3.9
20
- Classifier: Programming Language :: Python :: 3.10
21
- Classifier: Programming Language :: Python :: 3.11
22
- Classifier: Topic :: Office/Business :: Financial :: Investment
23
- Requires-Python: >=3.8
24
- Description-Content-Type: text/markdown
25
- License-File: LICENSE
26
- Requires-Dist: pandas>=1.3.0
27
- Requires-Dist: numpy>=1.21.0
28
- Provides-Extra: dev
29
- Requires-Dist: pytest>=7.0.0; extra == "dev"
30
- Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
31
- Requires-Dist: black>=22.0.0; extra == "dev"
32
- Requires-Dist: flake8>=5.0.0; extra == "dev"
33
- Requires-Dist: mypy>=0.990; extra == "dev"
34
- Provides-Extra: plot
35
- Requires-Dist: matplotlib>=3.5.0; extra == "plot"
36
- Provides-Extra: all
37
- Requires-Dist: matplotlib>=3.5.0; extra == "all"
38
- Dynamic: license-file
39
-
40
- # DeltaFQ
41
-
42
- [![PyPI version](https://badge.fury.io/py/deltafq.svg)](https://badge.fury.io/py/deltafq)
43
- [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
44
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
45
-
46
- A professional Python quantitative trading library providing a complete toolkit for quantitative strategy development and research.
47
-
48
- ## Features
49
-
50
- - 📊 **Multi-source Data Support** - Unified data interface supporting multiple data sources
51
- - 📈 **Rich Technical Indicators** - Built-in common technical indicators with custom extension support
52
- - 🎯 **Flexible Strategy Framework** - Clean API for rapid trading strategy development
53
- - ⚡ **Efficient Backtest Engine** - Vectorized computation for fast strategy validation
54
- - 📉 **Comprehensive Risk Management** - Position management, risk control, and performance analysis
55
- - 🔧 **Parameter Optimization Tools** - Multiple optimization algorithms for finding optimal parameters
56
- - 📱 **Live Trading Interface** - Unified trading interface for seamless simulation and live trading
57
-
58
- ## Installation
59
-
60
- ```bash
61
- pip install deltafq
62
- ```
63
-
64
- Or install from source:
65
-
66
- ```bash
67
- git clone https://github.com/Delta-F/deltafq.git
68
- cd deltafq
69
- pip install -e .
70
- ```
71
-
72
- ## Quick Start
73
-
74
- ### Get Data
75
-
76
- ```python
77
- import deltafq as dfq
78
-
79
- # Get stock data
80
- data = dfq.data.get_stock_daily('000001.SZ', start='2020-01-01', end='2023-12-31')
81
- print(data.head())
82
- ```
83
-
84
- ### Calculate Technical Indicators
85
-
86
- ```python
87
- # Calculate moving averages
88
- data['ma5'] = dfq.indicators.SMA(data['close'], 5)
89
- data['ma20'] = dfq.indicators.SMA(data['close'], 20)
90
-
91
- # Calculate MACD
92
- macd = dfq.indicators.MACD(data['close'])
93
- data = data.join(macd)
94
- ```
95
-
96
- ### Build Trading Strategy
97
-
98
- ```python
99
- class MAStrategy(dfq.strategy.Strategy):
100
- """Dual Moving Average Strategy"""
101
-
102
- def on_bar(self, bar):
103
- if bar.ma5 > bar.ma20:
104
- self.buy()
105
- elif bar.ma5 < bar.ma20:
106
- self.sell()
107
- ```
108
-
109
- ### Run Backtest
110
-
111
- ```python
112
- # Create backtest engine
113
- engine = dfq.backtest.BacktestEngine(
114
- initial_cash=100000,
115
- commission=0.0003
116
- )
117
-
118
- # Run backtest
119
- result = engine.run(data, MAStrategy())
120
-
121
- # View results
122
- print(result.summary())
123
- result.plot()
124
- ```
125
-
126
- ## Module Overview
127
-
128
- - **data** - Data acquisition and management
129
- - **indicators** - Technical indicator calculations
130
- - **strategy** - Strategy development framework
131
- - **backtest** - Backtest engine
132
- - **risk** - Risk management
133
- - **performance** - Performance analysis
134
- - **optimization** - Parameter optimization
135
- - **trade** - Live trading interface
136
- - **utils** - Utility functions
137
-
138
- ## Examples
139
-
140
- Check the `examples/` directory for more example code:
141
-
142
- - `ma_strategy.py` - Dual Moving Average Strategy
143
- - `macd_strategy.py` - MACD Strategy
144
- - `optimization_example.py` - Parameter Optimization Example
145
-
146
- ## Documentation
147
-
148
- - **User Guide**: [docs/GUIDE.md](docs/GUIDE.md) | [中文指南](docs/GUIDE_zh.md)
149
- - **API Reference**: [docs/API.md](docs/API.md)
150
- - **Development Guide**: [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md)
151
- - **Changelog**: [docs/CHANGELOG.md](docs/CHANGELOG.md)
152
-
153
- ## Dependencies
154
-
155
- - Python >= 3.8
156
- - pandas >= 1.3.0
157
- - numpy >= 1.21.0
158
-
159
- ## Development
160
-
161
- ```bash
162
- # Clone repository
163
- git clone https://github.com/Delta-F/deltafq.git
164
- cd deltafq
165
-
166
- # Install development dependencies
167
- pip install -e ".[dev]"
168
-
169
- # Run tests
170
- pytest
171
-
172
- # Code formatting
173
- black deltafq/
174
-
175
- # Type checking
176
- mypy deltafq/
177
- ```
178
-
179
- ## License
180
-
181
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
182
-
183
- ## Contributing
184
-
185
- Issues and Pull Requests are welcome!
186
-
187
- ## Contact
188
-
189
- - Project Homepage: [https://github.com/Delta-F/deltafq](https://github.com/Delta-F/deltafq)
190
- - PyPI Homepage: [https://pypi.org/project/deltafq/](https://pypi.org/project/deltafq/)
191
- - Issue Tracker: [https://github.com/Delta-F/deltafq/issues](https://github.com/Delta-F/deltafq/issues)
192
-
193
- ---
194
-
195
- ⚠️ **Risk Warning**: Quantitative trading involves risk. This library is for educational and research purposes only and does not constitute investment advice. Please exercise caution when trading live, as you bear the risk yourself.
196
-
197
- ## Language Support
198
-
199
- This project supports both English and Chinese documentation:
200
-
201
- - **English**: [README.md](README.md) (current)
202
- - **中文**: [README_zh.md](README_zh.md)
@@ -1,29 +0,0 @@
1
- deltafq/__init__.py,sha256=j_xRF3hL3oBvHyovTHvMvS31Rppvtg-eSFPnvjU5N1s,640
2
- deltafq/backtest/__init__.py,sha256=nH_lnnpx-XPs2FY8j4DdeptX5Rwumbgn9l82kyiu5Ds,184
3
- deltafq/backtest/engine.py,sha256=YefCepHM9_Y4EJi5y4eDhjwLILu5iaj1Z7soaXjZLy4,1248
4
- deltafq/backtest/result.py,sha256=2DS1b9c5iJb8BCeQt9p7p_hrqc805P8mWoqyu-pa3Zs,1164
5
- deltafq/data/__init__.py,sha256=LCjI7BY2SE4JY_AyWoFd66Pb-9uPRvmuZYlsF6lZAF8,215
6
- deltafq/data/base.py,sha256=nwwKlLD70jq7bv51F9umWygPKbN-vP_7GpxUdyI0K6g,610
7
- deltafq/data/loader.py,sha256=wi6aYVUZ4c7u0LV-lHIKX40NnZ7twYga60oq0Pdex3s,1614
8
- deltafq/indicators/__init__.py,sha256=kNg84vs20ShQYYxKL6j5p5aJWjpdyS2pivRPuHzpRA0,233
9
- deltafq/indicators/momentum.py,sha256=CRGGjrs-kGpuuV7srTGy2jr9hvvnYF2AIlzOn9grBXI,502
10
- deltafq/indicators/trend.py,sha256=kaC9tAQq-fR5bfVdHAMgiMgscfcKQCwTz2yG2ZN_N2c,1287
11
- deltafq/indicators/volatility.py,sha256=jhCHrvdJa_nvPbjEFa1ktH-gDY3wT7Z2vPjQ7DRtjk0,626
12
- deltafq/optimization/__init__.py,sha256=5uPJiOunFcRWupI2Nn37Jq2VShFASmM_UI7nZx93cCc,133
13
- deltafq/optimization/grid_search.py,sha256=G_8xVBOr2Vac2RaI9B-WI3mYyzl0zVHuvNrmEdFXUiE,1100
14
- deltafq/performance/__init__.py,sha256=JDxi_hTmbPSGafvtYjLM5r_r2pVz2L_njM4bUOpvpfw,186
15
- deltafq/performance/metrics.py,sha256=r0akhbkVVN6g_vuJPb9V7k2-zx7i-tAPmLf7ejRT72c,843
16
- deltafq/risk/__init__.py,sha256=ckuV7Mg5ijGCUDH9fbEbgxWyaLdcpSG92JYXwh_qUUg,229
17
- deltafq/risk/metrics.py,sha256=cAUi3bWL4KDOOizgDfe8uKuOEuTWIhXEhG0mkuRFeo0,732
18
- deltafq/risk/position.py,sha256=h11b7obMpriavPVXzgTiPXDAsjsXAkNy6SVEyoSItqA,911
19
- deltafq/strategy/__init__.py,sha256=MtT73CleKjhlUPoauAqD2oVFi2sgNdfIB2ZFQhXNkVU,100
20
- deltafq/strategy/base.py,sha256=chzi59RQUy1hIGZ8r4QPYcdpeVrC1VqtXPyTnGVFkAE,1066
21
- deltafq/trade/__init__.py,sha256=9MLD7LlybjP0uATMbAqDPYkuwFIP1PPE9PG5WduUZBs,101
22
- deltafq/trade/broker.py,sha256=IMW3e38mv8XkYF279tqQxKUIjcZ79N82cb52uFhEAWY,875
23
- deltafq/utils/__init__.py,sha256=AMUJnZSlvojkgOWXROglzXXwqslHrp25YH_9GBbOA0s,149
24
- deltafq/utils/time.py,sha256=0XGMR8xxX39HS-h7xg0gN6pTuOK-SOlRsWeQq9XLW5Y,641
25
- deltafq-0.1.1.dist-info/licenses/LICENSE,sha256=5_jN6PqRGcdXKxxg6PCYHU7A2u29fcTdA-8laOCdsZU,1092
26
- deltafq-0.1.1.dist-info/METADATA,sha256=2OqdSeGSE80XVsRQYFOyj7v73cxBQ-z35rhhHP9tCLE,6195
27
- deltafq-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
- deltafq-0.1.1.dist-info/top_level.txt,sha256=j1Q3ce7BEqdXVZd-mlHiJBDHq3iJGiKRKEXPW8xHLHo,8
29
- deltafq-0.1.1.dist-info/RECORD,,