deltafq 0.1.0__tar.gz → 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.
Potentially problematic release.
This version of deltafq might be problematic. Click here for more details.
- deltafq-0.1.1/PKG-INFO +202 -0
- deltafq-0.1.1/README.md +163 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/__init__.py +1 -1
- deltafq-0.1.1/deltafq.egg-info/PKG-INFO +202 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/pyproject.toml +3 -3
- deltafq-0.1.0/PKG-INFO +0 -195
- deltafq-0.1.0/README.md +0 -156
- deltafq-0.1.0/deltafq.egg-info/PKG-INFO +0 -195
- {deltafq-0.1.0 → deltafq-0.1.1}/LICENSE +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/MANIFEST.in +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/backtest/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/backtest/engine.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/backtest/result.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/data/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/data/base.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/data/loader.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/indicators/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/indicators/momentum.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/indicators/trend.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/indicators/volatility.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/optimization/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/optimization/grid_search.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/performance/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/performance/metrics.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/risk/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/risk/metrics.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/risk/position.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/strategy/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/strategy/base.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/trade/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/trade/broker.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/utils/__init__.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq/utils/time.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq.egg-info/SOURCES.txt +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq.egg-info/dependency_links.txt +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq.egg-info/requires.txt +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/deltafq.egg-info/top_level.txt +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/setup.cfg +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/setup.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/tests/test_backtest.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/tests/test_data.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/tests/test_full_workflow.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/tests/test_indicators.py +0 -0
- {deltafq-0.1.0 → deltafq-0.1.1}/tests/test_strategy.py +0 -0
deltafq-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
[](https://badge.fury.io/py/deltafq)
|
|
43
|
+
[](https://www.python.org/downloads/)
|
|
44
|
+
[](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)
|
deltafq-0.1.1/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# DeltaFQ
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/deltafq)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A professional Python quantitative trading library providing a complete toolkit for quantitative strategy development and research.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 📊 **Multi-source Data Support** - Unified data interface supporting multiple data sources
|
|
12
|
+
- 📈 **Rich Technical Indicators** - Built-in common technical indicators with custom extension support
|
|
13
|
+
- 🎯 **Flexible Strategy Framework** - Clean API for rapid trading strategy development
|
|
14
|
+
- ⚡ **Efficient Backtest Engine** - Vectorized computation for fast strategy validation
|
|
15
|
+
- 📉 **Comprehensive Risk Management** - Position management, risk control, and performance analysis
|
|
16
|
+
- 🔧 **Parameter Optimization Tools** - Multiple optimization algorithms for finding optimal parameters
|
|
17
|
+
- 📱 **Live Trading Interface** - Unified trading interface for seamless simulation and live trading
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install deltafq
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install from source:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/Delta-F/deltafq.git
|
|
29
|
+
cd deltafq
|
|
30
|
+
pip install -e .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### Get Data
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import deltafq as dfq
|
|
39
|
+
|
|
40
|
+
# Get stock data
|
|
41
|
+
data = dfq.data.get_stock_daily('000001.SZ', start='2020-01-01', end='2023-12-31')
|
|
42
|
+
print(data.head())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Calculate Technical Indicators
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
# Calculate moving averages
|
|
49
|
+
data['ma5'] = dfq.indicators.SMA(data['close'], 5)
|
|
50
|
+
data['ma20'] = dfq.indicators.SMA(data['close'], 20)
|
|
51
|
+
|
|
52
|
+
# Calculate MACD
|
|
53
|
+
macd = dfq.indicators.MACD(data['close'])
|
|
54
|
+
data = data.join(macd)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Build Trading Strategy
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
class MAStrategy(dfq.strategy.Strategy):
|
|
61
|
+
"""Dual Moving Average Strategy"""
|
|
62
|
+
|
|
63
|
+
def on_bar(self, bar):
|
|
64
|
+
if bar.ma5 > bar.ma20:
|
|
65
|
+
self.buy()
|
|
66
|
+
elif bar.ma5 < bar.ma20:
|
|
67
|
+
self.sell()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Run Backtest
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# Create backtest engine
|
|
74
|
+
engine = dfq.backtest.BacktestEngine(
|
|
75
|
+
initial_cash=100000,
|
|
76
|
+
commission=0.0003
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Run backtest
|
|
80
|
+
result = engine.run(data, MAStrategy())
|
|
81
|
+
|
|
82
|
+
# View results
|
|
83
|
+
print(result.summary())
|
|
84
|
+
result.plot()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Module Overview
|
|
88
|
+
|
|
89
|
+
- **data** - Data acquisition and management
|
|
90
|
+
- **indicators** - Technical indicator calculations
|
|
91
|
+
- **strategy** - Strategy development framework
|
|
92
|
+
- **backtest** - Backtest engine
|
|
93
|
+
- **risk** - Risk management
|
|
94
|
+
- **performance** - Performance analysis
|
|
95
|
+
- **optimization** - Parameter optimization
|
|
96
|
+
- **trade** - Live trading interface
|
|
97
|
+
- **utils** - Utility functions
|
|
98
|
+
|
|
99
|
+
## Examples
|
|
100
|
+
|
|
101
|
+
Check the `examples/` directory for more example code:
|
|
102
|
+
|
|
103
|
+
- `ma_strategy.py` - Dual Moving Average Strategy
|
|
104
|
+
- `macd_strategy.py` - MACD Strategy
|
|
105
|
+
- `optimization_example.py` - Parameter Optimization Example
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
- **User Guide**: [docs/GUIDE.md](docs/GUIDE.md) | [中文指南](docs/GUIDE_zh.md)
|
|
110
|
+
- **API Reference**: [docs/API.md](docs/API.md)
|
|
111
|
+
- **Development Guide**: [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md)
|
|
112
|
+
- **Changelog**: [docs/CHANGELOG.md](docs/CHANGELOG.md)
|
|
113
|
+
|
|
114
|
+
## Dependencies
|
|
115
|
+
|
|
116
|
+
- Python >= 3.8
|
|
117
|
+
- pandas >= 1.3.0
|
|
118
|
+
- numpy >= 1.21.0
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Clone repository
|
|
124
|
+
git clone https://github.com/Delta-F/deltafq.git
|
|
125
|
+
cd deltafq
|
|
126
|
+
|
|
127
|
+
# Install development dependencies
|
|
128
|
+
pip install -e ".[dev]"
|
|
129
|
+
|
|
130
|
+
# Run tests
|
|
131
|
+
pytest
|
|
132
|
+
|
|
133
|
+
# Code formatting
|
|
134
|
+
black deltafq/
|
|
135
|
+
|
|
136
|
+
# Type checking
|
|
137
|
+
mypy deltafq/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
Issues and Pull Requests are welcome!
|
|
147
|
+
|
|
148
|
+
## Contact
|
|
149
|
+
|
|
150
|
+
- Project Homepage: [https://github.com/Delta-F/deltafq](https://github.com/Delta-F/deltafq)
|
|
151
|
+
- PyPI Homepage: [https://pypi.org/project/deltafq/](https://pypi.org/project/deltafq/)
|
|
152
|
+
- Issue Tracker: [https://github.com/Delta-F/deltafq/issues](https://github.com/Delta-F/deltafq/issues)
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
⚠️ **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.
|
|
157
|
+
|
|
158
|
+
## Language Support
|
|
159
|
+
|
|
160
|
+
This project supports both English and Chinese documentation:
|
|
161
|
+
|
|
162
|
+
- **English**: [README.md](README.md) (current)
|
|
163
|
+
- **中文**: [README_zh.md](README_zh.md)
|
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
[](https://badge.fury.io/py/deltafq)
|
|
43
|
+
[](https://www.python.org/downloads/)
|
|
44
|
+
[](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)
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "deltafq"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "A professional Python quantitative trading library"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
11
11
|
license = {text = "MIT"}
|
|
@@ -48,7 +48,7 @@ all = [
|
|
|
48
48
|
|
|
49
49
|
[project.urls]
|
|
50
50
|
Homepage = "https://github.com/Delta-F/deltafq"
|
|
51
|
-
Documentation = "https://deltafq
|
|
51
|
+
Documentation = "https://github.com/Delta-F/deltafq/tree/main/docs"
|
|
52
52
|
Repository = "https://github.com/Delta-F/deltafq"
|
|
53
53
|
PyPI = "https://pypi.org/project/deltafq/"
|
|
54
54
|
"Bug Tracker" = "https://github.com/Delta-F/deltafq/issues"
|
deltafq-0.1.0/PKG-INFO
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: deltafq
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: 专业的Python量化交易库
|
|
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://deltafq.readthedocs.io
|
|
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
|
-
[](https://badge.fury.io/py/deltafq)
|
|
43
|
-
[](https://www.python.org/downloads/)
|
|
44
|
-
[](https://opensource.org/licenses/MIT)
|
|
45
|
-
|
|
46
|
-
专业的Python量化交易库,为量化策略开发者和研究人员提供从数据获取到策略回测的完整工具链。
|
|
47
|
-
|
|
48
|
-
## 特性
|
|
49
|
-
|
|
50
|
-
- 📊 **多源数据支持** - 统一的数据接口,支持多种数据源
|
|
51
|
-
- 📈 **丰富的技术指标** - 内置常用技术指标,支持自定义扩展
|
|
52
|
-
- 🎯 **灵活的策略框架** - 简洁的API,快速构建交易策略
|
|
53
|
-
- ⚡ **高效的回测引擎** - 向量化计算,快速验证策略效果
|
|
54
|
-
- 📉 **全面的风险管理** - 仓位管理、风险控制、绩效分析
|
|
55
|
-
- 🔧 **参数优化工具** - 多种优化算法,寻找最佳参数
|
|
56
|
-
- 📱 **实盘交易接口** - 统一的交易接口,无缝切换模拟与实盘
|
|
57
|
-
|
|
58
|
-
## 安装
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pip install deltafq
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
或者安装开发版本:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
git clone https://github.com/Delta-F/deltafq.git
|
|
68
|
-
cd deltafq
|
|
69
|
-
pip install -e .
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## 快速开始
|
|
73
|
-
|
|
74
|
-
### 获取数据
|
|
75
|
-
|
|
76
|
-
```python
|
|
77
|
-
import deltafq as dfq
|
|
78
|
-
|
|
79
|
-
# 获取股票数据
|
|
80
|
-
data = dfq.data.get_stock_daily('000001.SZ', start='2020-01-01', end='2023-12-31')
|
|
81
|
-
print(data.head())
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### 计算技术指标
|
|
85
|
-
|
|
86
|
-
```python
|
|
87
|
-
# 计算移动平均线
|
|
88
|
-
data['ma5'] = dfq.indicators.SMA(data['close'], 5)
|
|
89
|
-
data['ma20'] = dfq.indicators.SMA(data['close'], 20)
|
|
90
|
-
|
|
91
|
-
# 计算MACD
|
|
92
|
-
macd = dfq.indicators.MACD(data['close'])
|
|
93
|
-
data = data.join(macd)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### 构建交易策略
|
|
97
|
-
|
|
98
|
-
```python
|
|
99
|
-
class MAStrategy(dfq.strategy.Strategy):
|
|
100
|
-
"""双均线策略"""
|
|
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
|
-
### 运行回测
|
|
110
|
-
|
|
111
|
-
```python
|
|
112
|
-
# 创建回测引擎
|
|
113
|
-
engine = dfq.backtest.BacktestEngine(
|
|
114
|
-
initial_cash=100000,
|
|
115
|
-
commission=0.0003
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
# 运行回测
|
|
119
|
-
result = engine.run(data, MAStrategy())
|
|
120
|
-
|
|
121
|
-
# 查看结果
|
|
122
|
-
print(result.summary())
|
|
123
|
-
result.plot()
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## 模块说明
|
|
127
|
-
|
|
128
|
-
- **data** - 数据获取和管理
|
|
129
|
-
- **indicators** - 技术指标计算
|
|
130
|
-
- **strategy** - 策略开发框架
|
|
131
|
-
- **backtest** - 回测引擎
|
|
132
|
-
- **risk** - 风险管理
|
|
133
|
-
- **performance** - 绩效分析
|
|
134
|
-
- **optimization** - 参数优化
|
|
135
|
-
- **trade** - 实盘交易接口
|
|
136
|
-
- **utils** - 工具函数
|
|
137
|
-
|
|
138
|
-
## 示例
|
|
139
|
-
|
|
140
|
-
查看 `examples/` 目录获取更多示例代码:
|
|
141
|
-
|
|
142
|
-
- `ma_strategy.py` - 双均线策略
|
|
143
|
-
- `macd_strategy.py` - MACD策略
|
|
144
|
-
- `optimization_example.py` - 参数优化示例
|
|
145
|
-
|
|
146
|
-
## 文档
|
|
147
|
-
|
|
148
|
-
- **使用指南**: [docs/GUIDE.md](docs/GUIDE.md)
|
|
149
|
-
- **API参考**: [docs/API.md](docs/API.md)
|
|
150
|
-
- **开发指南**: [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md)
|
|
151
|
-
- **更新日志**: [docs/CHANGELOG.md](docs/CHANGELOG.md)
|
|
152
|
-
|
|
153
|
-
## 依赖
|
|
154
|
-
|
|
155
|
-
- Python >= 3.8
|
|
156
|
-
- pandas >= 1.3.0
|
|
157
|
-
- numpy >= 1.21.0
|
|
158
|
-
|
|
159
|
-
## 开发
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
# 克隆仓库
|
|
163
|
-
git clone https://github.com/Delta-F/deltafq.git
|
|
164
|
-
cd deltafq
|
|
165
|
-
|
|
166
|
-
# 安装开发依赖
|
|
167
|
-
pip install -e ".[dev]"
|
|
168
|
-
|
|
169
|
-
# 运行测试
|
|
170
|
-
pytest
|
|
171
|
-
|
|
172
|
-
# 代码格式化
|
|
173
|
-
black deltafq/
|
|
174
|
-
|
|
175
|
-
# 类型检查
|
|
176
|
-
mypy deltafq/
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## 许可证
|
|
180
|
-
|
|
181
|
-
本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件
|
|
182
|
-
|
|
183
|
-
## 贡献
|
|
184
|
-
|
|
185
|
-
欢迎提交 Issue 和 Pull Request!
|
|
186
|
-
|
|
187
|
-
## 联系方式
|
|
188
|
-
|
|
189
|
-
- 项目主页:[https://github.com/Delta-F/deltafq](https://github.com/Delta-F/deltafq)
|
|
190
|
-
- PyPI 主页:[https://pypi.org/project/deltafq/](https://pypi.org/project/deltafq/)
|
|
191
|
-
- 问题反馈:[https://github.com/Delta-F/deltafq/issues](https://github.com/Delta-F/deltafq/issues)
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
⚠️ **风险提示**:量化交易存在风险,本库仅供学习研究使用,不构成投资建议。实盘交易需谨慎,风险自担。
|
deltafq-0.1.0/README.md
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
# DeltaFQ
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/py/deltafq)
|
|
4
|
-
[](https://www.python.org/downloads/)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
|
|
7
|
-
专业的Python量化交易库,为量化策略开发者和研究人员提供从数据获取到策略回测的完整工具链。
|
|
8
|
-
|
|
9
|
-
## 特性
|
|
10
|
-
|
|
11
|
-
- 📊 **多源数据支持** - 统一的数据接口,支持多种数据源
|
|
12
|
-
- 📈 **丰富的技术指标** - 内置常用技术指标,支持自定义扩展
|
|
13
|
-
- 🎯 **灵活的策略框架** - 简洁的API,快速构建交易策略
|
|
14
|
-
- ⚡ **高效的回测引擎** - 向量化计算,快速验证策略效果
|
|
15
|
-
- 📉 **全面的风险管理** - 仓位管理、风险控制、绩效分析
|
|
16
|
-
- 🔧 **参数优化工具** - 多种优化算法,寻找最佳参数
|
|
17
|
-
- 📱 **实盘交易接口** - 统一的交易接口,无缝切换模拟与实盘
|
|
18
|
-
|
|
19
|
-
## 安装
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
pip install deltafq
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
或者安装开发版本:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
git clone https://github.com/Delta-F/deltafq.git
|
|
29
|
-
cd deltafq
|
|
30
|
-
pip install -e .
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 快速开始
|
|
34
|
-
|
|
35
|
-
### 获取数据
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
import deltafq as dfq
|
|
39
|
-
|
|
40
|
-
# 获取股票数据
|
|
41
|
-
data = dfq.data.get_stock_daily('000001.SZ', start='2020-01-01', end='2023-12-31')
|
|
42
|
-
print(data.head())
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 计算技术指标
|
|
46
|
-
|
|
47
|
-
```python
|
|
48
|
-
# 计算移动平均线
|
|
49
|
-
data['ma5'] = dfq.indicators.SMA(data['close'], 5)
|
|
50
|
-
data['ma20'] = dfq.indicators.SMA(data['close'], 20)
|
|
51
|
-
|
|
52
|
-
# 计算MACD
|
|
53
|
-
macd = dfq.indicators.MACD(data['close'])
|
|
54
|
-
data = data.join(macd)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 构建交易策略
|
|
58
|
-
|
|
59
|
-
```python
|
|
60
|
-
class MAStrategy(dfq.strategy.Strategy):
|
|
61
|
-
"""双均线策略"""
|
|
62
|
-
|
|
63
|
-
def on_bar(self, bar):
|
|
64
|
-
if bar.ma5 > bar.ma20:
|
|
65
|
-
self.buy()
|
|
66
|
-
elif bar.ma5 < bar.ma20:
|
|
67
|
-
self.sell()
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### 运行回测
|
|
71
|
-
|
|
72
|
-
```python
|
|
73
|
-
# 创建回测引擎
|
|
74
|
-
engine = dfq.backtest.BacktestEngine(
|
|
75
|
-
initial_cash=100000,
|
|
76
|
-
commission=0.0003
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
# 运行回测
|
|
80
|
-
result = engine.run(data, MAStrategy())
|
|
81
|
-
|
|
82
|
-
# 查看结果
|
|
83
|
-
print(result.summary())
|
|
84
|
-
result.plot()
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## 模块说明
|
|
88
|
-
|
|
89
|
-
- **data** - 数据获取和管理
|
|
90
|
-
- **indicators** - 技术指标计算
|
|
91
|
-
- **strategy** - 策略开发框架
|
|
92
|
-
- **backtest** - 回测引擎
|
|
93
|
-
- **risk** - 风险管理
|
|
94
|
-
- **performance** - 绩效分析
|
|
95
|
-
- **optimization** - 参数优化
|
|
96
|
-
- **trade** - 实盘交易接口
|
|
97
|
-
- **utils** - 工具函数
|
|
98
|
-
|
|
99
|
-
## 示例
|
|
100
|
-
|
|
101
|
-
查看 `examples/` 目录获取更多示例代码:
|
|
102
|
-
|
|
103
|
-
- `ma_strategy.py` - 双均线策略
|
|
104
|
-
- `macd_strategy.py` - MACD策略
|
|
105
|
-
- `optimization_example.py` - 参数优化示例
|
|
106
|
-
|
|
107
|
-
## 文档
|
|
108
|
-
|
|
109
|
-
- **使用指南**: [docs/GUIDE.md](docs/GUIDE.md)
|
|
110
|
-
- **API参考**: [docs/API.md](docs/API.md)
|
|
111
|
-
- **开发指南**: [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md)
|
|
112
|
-
- **更新日志**: [docs/CHANGELOG.md](docs/CHANGELOG.md)
|
|
113
|
-
|
|
114
|
-
## 依赖
|
|
115
|
-
|
|
116
|
-
- Python >= 3.8
|
|
117
|
-
- pandas >= 1.3.0
|
|
118
|
-
- numpy >= 1.21.0
|
|
119
|
-
|
|
120
|
-
## 开发
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
# 克隆仓库
|
|
124
|
-
git clone https://github.com/Delta-F/deltafq.git
|
|
125
|
-
cd deltafq
|
|
126
|
-
|
|
127
|
-
# 安装开发依赖
|
|
128
|
-
pip install -e ".[dev]"
|
|
129
|
-
|
|
130
|
-
# 运行测试
|
|
131
|
-
pytest
|
|
132
|
-
|
|
133
|
-
# 代码格式化
|
|
134
|
-
black deltafq/
|
|
135
|
-
|
|
136
|
-
# 类型检查
|
|
137
|
-
mypy deltafq/
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## 许可证
|
|
141
|
-
|
|
142
|
-
本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件
|
|
143
|
-
|
|
144
|
-
## 贡献
|
|
145
|
-
|
|
146
|
-
欢迎提交 Issue 和 Pull Request!
|
|
147
|
-
|
|
148
|
-
## 联系方式
|
|
149
|
-
|
|
150
|
-
- 项目主页:[https://github.com/Delta-F/deltafq](https://github.com/Delta-F/deltafq)
|
|
151
|
-
- PyPI 主页:[https://pypi.org/project/deltafq/](https://pypi.org/project/deltafq/)
|
|
152
|
-
- 问题反馈:[https://github.com/Delta-F/deltafq/issues](https://github.com/Delta-F/deltafq/issues)
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
⚠️ **风险提示**:量化交易存在风险,本库仅供学习研究使用,不构成投资建议。实盘交易需谨慎,风险自担。
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: deltafq
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: 专业的Python量化交易库
|
|
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://deltafq.readthedocs.io
|
|
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
|
-
[](https://badge.fury.io/py/deltafq)
|
|
43
|
-
[](https://www.python.org/downloads/)
|
|
44
|
-
[](https://opensource.org/licenses/MIT)
|
|
45
|
-
|
|
46
|
-
专业的Python量化交易库,为量化策略开发者和研究人员提供从数据获取到策略回测的完整工具链。
|
|
47
|
-
|
|
48
|
-
## 特性
|
|
49
|
-
|
|
50
|
-
- 📊 **多源数据支持** - 统一的数据接口,支持多种数据源
|
|
51
|
-
- 📈 **丰富的技术指标** - 内置常用技术指标,支持自定义扩展
|
|
52
|
-
- 🎯 **灵活的策略框架** - 简洁的API,快速构建交易策略
|
|
53
|
-
- ⚡ **高效的回测引擎** - 向量化计算,快速验证策略效果
|
|
54
|
-
- 📉 **全面的风险管理** - 仓位管理、风险控制、绩效分析
|
|
55
|
-
- 🔧 **参数优化工具** - 多种优化算法,寻找最佳参数
|
|
56
|
-
- 📱 **实盘交易接口** - 统一的交易接口,无缝切换模拟与实盘
|
|
57
|
-
|
|
58
|
-
## 安装
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pip install deltafq
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
或者安装开发版本:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
git clone https://github.com/Delta-F/deltafq.git
|
|
68
|
-
cd deltafq
|
|
69
|
-
pip install -e .
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## 快速开始
|
|
73
|
-
|
|
74
|
-
### 获取数据
|
|
75
|
-
|
|
76
|
-
```python
|
|
77
|
-
import deltafq as dfq
|
|
78
|
-
|
|
79
|
-
# 获取股票数据
|
|
80
|
-
data = dfq.data.get_stock_daily('000001.SZ', start='2020-01-01', end='2023-12-31')
|
|
81
|
-
print(data.head())
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### 计算技术指标
|
|
85
|
-
|
|
86
|
-
```python
|
|
87
|
-
# 计算移动平均线
|
|
88
|
-
data['ma5'] = dfq.indicators.SMA(data['close'], 5)
|
|
89
|
-
data['ma20'] = dfq.indicators.SMA(data['close'], 20)
|
|
90
|
-
|
|
91
|
-
# 计算MACD
|
|
92
|
-
macd = dfq.indicators.MACD(data['close'])
|
|
93
|
-
data = data.join(macd)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### 构建交易策略
|
|
97
|
-
|
|
98
|
-
```python
|
|
99
|
-
class MAStrategy(dfq.strategy.Strategy):
|
|
100
|
-
"""双均线策略"""
|
|
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
|
-
### 运行回测
|
|
110
|
-
|
|
111
|
-
```python
|
|
112
|
-
# 创建回测引擎
|
|
113
|
-
engine = dfq.backtest.BacktestEngine(
|
|
114
|
-
initial_cash=100000,
|
|
115
|
-
commission=0.0003
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
# 运行回测
|
|
119
|
-
result = engine.run(data, MAStrategy())
|
|
120
|
-
|
|
121
|
-
# 查看结果
|
|
122
|
-
print(result.summary())
|
|
123
|
-
result.plot()
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## 模块说明
|
|
127
|
-
|
|
128
|
-
- **data** - 数据获取和管理
|
|
129
|
-
- **indicators** - 技术指标计算
|
|
130
|
-
- **strategy** - 策略开发框架
|
|
131
|
-
- **backtest** - 回测引擎
|
|
132
|
-
- **risk** - 风险管理
|
|
133
|
-
- **performance** - 绩效分析
|
|
134
|
-
- **optimization** - 参数优化
|
|
135
|
-
- **trade** - 实盘交易接口
|
|
136
|
-
- **utils** - 工具函数
|
|
137
|
-
|
|
138
|
-
## 示例
|
|
139
|
-
|
|
140
|
-
查看 `examples/` 目录获取更多示例代码:
|
|
141
|
-
|
|
142
|
-
- `ma_strategy.py` - 双均线策略
|
|
143
|
-
- `macd_strategy.py` - MACD策略
|
|
144
|
-
- `optimization_example.py` - 参数优化示例
|
|
145
|
-
|
|
146
|
-
## 文档
|
|
147
|
-
|
|
148
|
-
- **使用指南**: [docs/GUIDE.md](docs/GUIDE.md)
|
|
149
|
-
- **API参考**: [docs/API.md](docs/API.md)
|
|
150
|
-
- **开发指南**: [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md)
|
|
151
|
-
- **更新日志**: [docs/CHANGELOG.md](docs/CHANGELOG.md)
|
|
152
|
-
|
|
153
|
-
## 依赖
|
|
154
|
-
|
|
155
|
-
- Python >= 3.8
|
|
156
|
-
- pandas >= 1.3.0
|
|
157
|
-
- numpy >= 1.21.0
|
|
158
|
-
|
|
159
|
-
## 开发
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
# 克隆仓库
|
|
163
|
-
git clone https://github.com/Delta-F/deltafq.git
|
|
164
|
-
cd deltafq
|
|
165
|
-
|
|
166
|
-
# 安装开发依赖
|
|
167
|
-
pip install -e ".[dev]"
|
|
168
|
-
|
|
169
|
-
# 运行测试
|
|
170
|
-
pytest
|
|
171
|
-
|
|
172
|
-
# 代码格式化
|
|
173
|
-
black deltafq/
|
|
174
|
-
|
|
175
|
-
# 类型检查
|
|
176
|
-
mypy deltafq/
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## 许可证
|
|
180
|
-
|
|
181
|
-
本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件
|
|
182
|
-
|
|
183
|
-
## 贡献
|
|
184
|
-
|
|
185
|
-
欢迎提交 Issue 和 Pull Request!
|
|
186
|
-
|
|
187
|
-
## 联系方式
|
|
188
|
-
|
|
189
|
-
- 项目主页:[https://github.com/Delta-F/deltafq](https://github.com/Delta-F/deltafq)
|
|
190
|
-
- PyPI 主页:[https://pypi.org/project/deltafq/](https://pypi.org/project/deltafq/)
|
|
191
|
-
- 问题反馈:[https://github.com/Delta-F/deltafq/issues](https://github.com/Delta-F/deltafq/issues)
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
⚠️ **风险提示**:量化交易存在风险,本库仅供学习研究使用,不构成投资建议。实盘交易需谨慎,风险自担。
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|