Skip to content

Commit ca787a4

Browse files
authored
Merge pull request #2 from ChipaDevTeam/copilot/organize-files-and-create-library
[WIP] Organize files and create WinstonAI library for training and usage
2 parents e8badc2 + 021aa87 commit ca787a4

24 files changed

Lines changed: 2242 additions & 219 deletions

LIBRARY_ORGANIZATION.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# WinstonAI Library - Organization Summary
2+
3+
## What Was Done
4+
5+
This update reorganizes the WinstonAI project into a proper Python library structure with clear separation of concerns and easy-to-use APIs.
6+
7+
### Major Changes
8+
9+
1. **Created `winston_ai/` Package Structure**
10+
- Organized code into logical submodules
11+
- Added proper `__init__.py` files for each module
12+
- Implemented clean import system
13+
14+
2. **Modular Architecture**
15+
```
16+
winston_ai/
17+
├── models/ # Neural network architectures
18+
├── training/ # Training utilities and agents
19+
├── trading/ # Live trading interface
20+
├── indicators/ # Technical analysis
21+
└── utils/ # Helper functions
22+
```
23+
24+
3. **Example Scripts**
25+
- `examples/quickstart.py` - Quick start guide
26+
- `examples/train_model.py` - Full training example
27+
- `examples/use_model.py` - Inference example
28+
29+
4. **Reorganized Files**
30+
- Config files moved to `data/configs/`
31+
- Model checkpoints go to `models/` (gitignored)
32+
- Legacy scripts remain in `src/` for reference
33+
34+
## How to Use the Library
35+
36+
### Installation
37+
38+
```bash
39+
pip install -e .
40+
```
41+
42+
### Quick Start
43+
44+
```python
45+
from winston_ai import Trainer, Config
46+
import pandas as pd
47+
48+
# Load your data
49+
data = pd.read_csv('market_data.csv')
50+
51+
# Train model
52+
config = Config()
53+
trainer = Trainer(data=data, config=config)
54+
metrics = trainer.train(episodes=1000)
55+
```
56+
57+
### Using Trained Model
58+
59+
```python
60+
from winston_ai import LiveTrader
61+
62+
trader = LiveTrader('models/winston_ai_final.pth')
63+
prediction = trader.predict(recent_data)
64+
print(f"Action: {prediction['action_name']}")
65+
```
66+
67+
## Module Descriptions
68+
69+
### `winston_ai.models`
70+
- `WinstonAI` - Standard DQN model with LSTM
71+
- `AdvancedWinstonAI` - Large GPU-optimized model with attention
72+
- `MultiHeadAttention` - Transformer attention mechanism
73+
74+
### `winston_ai.training`
75+
- `Trainer` - High-level training orchestration
76+
- `DQNAgent` - Deep Q-Network agent with experience replay
77+
- `BinaryOptionsEnvironment` - Trading simulation environment
78+
79+
### `winston_ai.trading`
80+
- `LiveTrader` - Interface for using trained models in production
81+
82+
### `winston_ai.indicators`
83+
- `TechnicalIndicators` - 50+ technical indicators calculator
84+
85+
### `winston_ai.utils`
86+
- `Config` - Configuration management
87+
- `get_device()`, `setup_gpu()` - GPU utilities
88+
- `save_checkpoint()`, `load_checkpoint()` - Model persistence
89+
90+
## Benefits
91+
92+
1. **Better Organization** - Clear separation of concerns
93+
2. **Easy to Use** - Simple, intuitive API
94+
3. **Reusable** - Import only what you need
95+
4. **Maintainable** - Modular structure makes updates easier
96+
5. **Extensible** - Easy to add new features
97+
6. **Documented** - Examples and documentation included
98+
99+
## Backward Compatibility
100+
101+
- Original scripts in `src/` still work
102+
- Can be used alongside the new library
103+
- Gradual migration path available
104+
105+
## Testing
106+
107+
Library has been tested and verified:
108+
- ✅ All imports work correctly
109+
- ✅ Configuration system functional
110+
- ✅ Training pipeline operational
111+
- ✅ Model architectures validated
112+
113+
## Next Steps
114+
115+
1. Train models using the new API
116+
2. Integrate with your trading platform
117+
3. Extend with custom strategies
118+
4. Add more technical indicators
119+
5. Implement backtesting framework
120+
121+
## Support
122+
123+
- See `examples/README.md` for detailed usage
124+
- Check `README.md` for updated documentation
125+
- Original scripts remain in `src/` for reference

README.md

Lines changed: 118 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -67,107 +67,165 @@ source venv/bin/activate # On Windows: venv\Scripts\activate
6767
pip install -r requirements.txt
6868
```
6969

70-
4. Configure your settings:
70+
4. Install WinstonAI as a package:
7171
```bash
72-
# Edit the configuration files in src/
73-
cp src/training_config.json src/training_config.local.json
74-
cp src/trading_config.json src/trading_config.local.json
75-
# Update with your API keys and preferences
72+
pip install -e .
7673
```
7774

78-
### Training the Model
75+
### Quick Start
7976

80-
**Quick Start (GPU):**
77+
Run the quick start example:
8178
```bash
82-
cd src
83-
python quick_start_gpu.py
79+
python examples/quickstart.py
8480
```
8581

86-
**Full Training:**
82+
Or train with more control:
8783
```bash
88-
cd src
89-
python train_gpu_optimized.py
84+
python examples/train_model.py
9085
```
9186

92-
**Reinforcement Learning Training (5-second timeframe):**
93-
```bash
94-
cd src
95-
python train_rl_5s.py
96-
```
87+
### Using the Library
9788

98-
### Live Trading
89+
After installation, you can import WinstonAI in your Python scripts:
9990

100-
⚠️ **Warning:** Live trading involves real financial risk. Always test thoroughly with a demo account first.
101-
102-
```bash
103-
cd src
104-
python ultra_live_trading_bot.py
91+
```python
92+
from winston_ai import Trainer, Config, LiveTrader
93+
from winston_ai import WinstonAI, AdvancedWinstonAI
94+
from winston_ai.indicators import TechnicalIndicators
10595
```
10696

97+
See `examples/` directory for complete usage examples.
98+
10799
## 📁 Project Structure
108100

109101
```
110102
WinstonAI/
111-
├── src/
103+
├── winston_ai/ # Main library package
104+
│ ├── __init__.py # Package initialization
105+
│ ├── models/ # Neural network models
106+
│ │ ├── winston_model.py # WinstonAI & AdvancedWinstonAI models
107+
│ │ └── attention.py # Multi-head attention mechanism
108+
│ ├── training/ # Training utilities
109+
│ │ ├── trainer.py # High-level training orchestration
110+
│ │ ├── agent.py # DQN agent implementation
111+
│ │ └── environment.py # Trading environment simulation
112+
│ ├── trading/ # Live trading functionality
113+
│ │ └── live_trader.py # Live trading interface
114+
│ ├── indicators/ # Technical analysis
115+
│ │ └── technical.py # Technical indicators calculator
116+
│ └── utils/ # Utility functions
117+
│ ├── config.py # Configuration management
118+
│ ├── device.py # GPU/device management
119+
│ └── checkpoints.py # Model checkpoint utilities
120+
├── examples/ # Example scripts
121+
│ ├── quickstart.py # Quick start example
122+
│ ├── train_model.py # Full training example
123+
│ ├── use_model.py # Inference example
124+
│ └── README.md # Examples documentation
125+
├── src/ # Legacy scripts (for reference)
112126
│ ├── train_gpu_optimized.py # GPU-optimized training script
113-
│ ├── train_rl_5s.py # Reinforcement learning trainer (5s)
114-
│ ├── ultra_live_trading_bot.py # High-performance live trading bot
127+
│ ├── train_rl_5s.py # RL trainer (5s timeframe)
128+
│ ├── ultra_live_trading_bot.py # High-performance trading bot
115129
│ ├── live_trading_bot.py # Standard live trading bot
116-
│ ├── gpu_monitor.py # GPU monitoring utilities
117-
│ ├── gpu_benchmark.py # GPU performance benchmarking
118-
│ ├── quick_start_gpu.py # Quick start script for GPU training
119-
│ ├── download.py # Historical data downloader
120-
│ ├── gethistory.py # Historical data fetcher
121-
│ ├── training_config.json # Training configuration
122-
│ ├── gpu_config.json # GPU settings
123-
│ ├── trading_config.json # Trading bot configuration
124-
│ ├── ultra_trading_config.json # Ultra bot configuration
125-
│ └── README_GPU_OPTIMIZATION.md # Detailed GPU optimization guide
130+
│ └── gpu_monitor.py # GPU monitoring utilities
131+
├── data/ # Data directory
132+
│ └── configs/ # Configuration files
133+
│ ├── training_config.json # Training configuration
134+
│ ├── trading_config.json # Trading configuration
135+
│ └── gpu_config.json # GPU settings
136+
├── models/ # Saved models (gitignored)
137+
├── docs/ # Documentation
138+
├── tests/ # Unit tests
126139
├── requirements.txt # Python dependencies
127-
├── setup.py # Package setup
128-
├── LICENSE # MIT License
129-
├── CONTRIBUTING.md # Contribution guidelines
130-
├── CODE_OF_CONDUCT.md # Code of conduct
131-
├── CHANGELOG.md # Version history
140+
├── setup.py # Package installation
132141
└── README.md # This file
133142
```
134143

135144
## 🎮 Usage Examples
136145

137-
### Training a New Model
146+
### Quick Start
138147

139-
```python
140-
from train_gpu_optimized import AdvancedWinstonAI
148+
```bash
149+
# Install the package
150+
pip install -e .
141151

142-
# Create model
143-
model = AdvancedWinstonAI(
144-
state_size=100,
145-
action_size=3, # CALL, PUT, HOLD
146-
device='cuda'
152+
# Run quick start example
153+
python examples/quickstart.py
154+
```
155+
156+
### Training a New Model (Library API)
157+
158+
```python
159+
from winston_ai import Trainer, Config
160+
import pandas as pd
161+
162+
# Load your market data
163+
data = pd.read_csv('your_market_data.csv')
164+
# Ensure data has columns: open, high, low, close, volume
165+
166+
# Configure training
167+
config = Config()
168+
config.update('training',
169+
episodes=1000,
170+
batch_size=512,
171+
learning_rate=0.0001
147172
)
148173

149-
# Train
150-
model.train(episodes=5000)
174+
# Create trainer and train
175+
trainer = Trainer(data=data, config=config)
176+
metrics = trainer.train(episodes=1000)
177+
178+
# Plot results
179+
trainer.plot_results('training_results.png')
151180
```
152181

153-
### Making Predictions
182+
### Using a Trained Model
154183

155184
```python
156-
import torch
157-
from train_gpu_optimized import AdvancedWinstonAI
185+
from winston_ai import LiveTrader
186+
import pandas as pd
158187

159188
# Load trained model
160-
model = torch.load('winston_ai_final.pth')
161-
model.eval()
189+
trader = LiveTrader(
190+
model_path='models/winston_ai_final.pth',
191+
lookback_window=100
192+
)
193+
194+
# Get recent market data
195+
data = get_recent_market_data() # Your data source
196+
197+
# Make prediction
198+
prediction = trader.predict(data)
199+
print(f"Action: {prediction['action_name']}")
200+
print(f"Confidence: {prediction['confidence']:.2%}")
162201

163-
# Prepare state (your market data)
164-
state = prepare_market_data() # Your function to get market data
202+
# Check if should trade
203+
if trader.should_trade(data, min_confidence=0.7):
204+
execute_trade(prediction['action_name'])
205+
```
206+
207+
### Importing Models Directly
165208

166-
# Get action
209+
```python
210+
from winston_ai import WinstonAI, AdvancedWinstonAI
211+
import torch
212+
213+
# Create model
214+
model = AdvancedWinstonAI(
215+
state_size=10000,
216+
action_size=3, # HOLD, CALL, PUT
217+
hidden_size=4096
218+
)
219+
220+
# Use for training or inference
221+
model.eval()
167222
with torch.no_grad():
168-
action = model.act(state)
223+
q_values = model(state_tensor)
224+
action = q_values.argmax().item()
169225
```
170226

227+
For more examples, see the `examples/` directory.
228+
171229
## 📊 Model Architecture
172230

173231
WinstonAI uses a sophisticated deep learning architecture:

0 commit comments

Comments
 (0)