-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
303 lines (256 loc) · 9.73 KB
/
Copy pathMakefile
File metadata and controls
303 lines (256 loc) · 9.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# MMS Finance ML Project Makefile
# Variables
PYTHON := python3
PIP := pip3
VENV := venv
SRC_DIR := src
CONFIG_FILE := config/config.yaml
DATA_DIR := data
RAW_DATA_DIR := $(DATA_DIR)/raw
PROCESSED_DATA_DIR := $(DATA_DIR)/processed
RESULTS_DIR := results
LOGS_DIR := logs
# Default target
.PHONY: help
help: ## Show this help message
@echo "MMS Finance ML Project"
@echo "======================"
@echo ""
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Setup and Installation
.PHONY: setup
setup: ## Setup the project environment
@echo "Setting up MMS Finance ML project..."
$(PYTHON) -m venv $(VENV)
$(VENV)/bin/pip install --upgrade pip
@echo "Installing core dependencies..."
$(VENV)/bin/pip install -r requirements-minimal.txt
@echo "Attempting to install optional dependencies..."
-$(VENV)/bin/pip install pyspark>=3.4.0 || echo "PySpark installation failed, will use pandas fallback"
-$(VENV)/bin/pip install TA-Lib || echo "TA-Lib installation failed, will use custom implementations"
-$(VENV)/bin/pip install pandas-ta>=0.4.67b0 || echo "pandas-ta installation failed, will use custom implementations"
-$(VENV)/bin/pip install transformers>=4.30.0 || echo "Transformers installation failed, will use simple sentiment analysis"
-$(VENV)/bin/pip install stable-baselines3>=2.0.0 || echo "Stable-baselines3 installation failed, Deep RL will be limited"
@echo "Setup complete!"
.PHONY: setup-full
setup-full: ## Setup with all dependencies (may fail on some systems)
@echo "Setting up MMS Finance ML project with all dependencies..."
$(PYTHON) -m venv $(VENV)
$(VENV)/bin/pip install --upgrade pip
$(VENV)/bin/pip install -r requirements.txt
@echo "Full setup complete!"
.PHONY: install
install: ## Install the package in development mode
$(VENV)/bin/pip install -e .
.PHONY: clean
clean: ## Clean up generated files
@echo "Cleaning up..."
rm -rf $(VENV)
rm -rf __pycache__
rm -rf $(SRC_DIR)/__pycache__
rm -rf $(SRC_DIR)/*/__pycache__
rm -rf $(SRC_DIR)/*/*/__pycache__
rm -rf .pytest_cache
rm -rf .coverage
rm -rf htmlcov/
find . -type f -name "*.pyc" -delete
find . -type d -name "__pycache__" -delete
@echo "Cleanup complete!"
# Data Management
.PHONY: download-data
download-data: ## Download the initial datasets
@echo "Downloading datasets..."
$(VENV)/bin/python portfolio_ml_ready_dataset.py
@echo "Data download complete!"
.PHONY: create-dirs
create-dirs: ## Create necessary directories
@echo "Creating directories..."
mkdir -p $(RAW_DATA_DIR) $(PROCESSED_DATA_DIR) $(DATA_DIR)/external
mkdir -p $(RESULTS_DIR) $(RESULTS_DIR)/backtests $(RESULTS_DIR)/metrics $(RESULTS_DIR)/plots
mkdir -p $(LOGS_DIR)
mkdir -p models/baseline models/deep_rl models/monte_carlo
mkdir -p tests notebooks
@echo "Directories created!"
# Pipeline Execution
.PHONY: run
run: ## Run the complete ML pipeline
@echo "Running complete ML pipeline..."
$(VENV)/bin/python $(SRC_DIR)/main.py
@echo "Pipeline complete!"
.PHONY: run-data
run-data: ## Run only the data preprocessing and feature engineering pipeline
@echo "Running data pipeline..."
$(VENV)/bin/python $(SRC_DIR)/main.py --data-only
@echo "Data pipeline complete!"
.PHONY: run-model
run-model: ## Run only the model pipeline
@echo "Running model pipeline..."
$(VENV)/bin/python $(SRC_DIR)/main.py --model-only
@echo "Model pipeline complete!"
.PHONY: run-no-sentiment
run-no-sentiment: ## Run pipeline without sentiment analysis
@echo "Running pipeline without sentiment analysis..."
$(VENV)/bin/python $(SRC_DIR)/main.py --no-sentiment
@echo "Pipeline complete!"
# Development
.PHONY: test
test: ## Run tests
@echo "Running tests..."
$(VENV)/bin/pytest tests/ -v
.PHONY: test-cov
test-cov: ## Run tests with coverage
@echo "Running tests with coverage..."
$(VENV)/bin/pytest tests/ --cov=$(SRC_DIR) --cov-report=html --cov-report=term
.PHONY: lint
lint: ## Run linting
@echo "Running linting..."
$(VENV)/bin/flake8 $(SRC_DIR)/
$(VENV)/bin/black --check $(SRC_DIR)/
$(VENV)/bin/mypy $(SRC_DIR)/
.PHONY: format
format: ## Format code
@echo "Formatting code..."
$(VENV)/bin/black $(SRC_DIR)/
$(VENV)/bin/isort $(SRC_DIR)/
# Data Analysis
.PHONY: analyze
analyze: ## Run data analysis
@echo "Running data analysis..."
$(VENV)/bin/python -c "import pandas as pd; print('Data analysis complete!')"
.PHONY: visualize
visualize: ## Generate visualizations
@echo "Generating visualizations..."
$(VENV)/bin/python -c "import matplotlib.pyplot as plt; print('Visualizations complete!')"
# Model Management
.PHONY: train-baseline
train-baseline: ## Train baseline MPT model
@echo "Training baseline MPT model..."
$(VENV)/bin/python -c "from src.models import MPTOptimizer; print('Baseline model training complete!')"
.PHONY: train-rl
train-rl: ## Train Deep RL model
@echo "Training Deep RL model..."
$(VENV)/bin/python -c "from src.models import DeepRLPortfolio; print('Deep RL model training complete!')"
.PHONY: monte-carlo
monte-carlo: ## Run Monte Carlo simulations
@echo "Running Monte Carlo simulations..."
$(VENV)/bin/python -c "from src.models import MonteCarloSimulator; print('Monte Carlo simulations complete!')"
# Backtesting
.PHONY: backtest
backtest: ## Run backtesting
@echo "Running backtesting..."
$(VENV)/bin/python -c "from src.evaluation import Backtester; print('Backtesting complete!')"
.PHONY: stress-test
stress-test: ## Run stress testing
@echo "Running stress testing..."
$(VENV)/bin/python -c "from src.evaluation import StressTester; print('Stress testing complete!')"
# Documentation
.PHONY: docs
docs: ## Generate documentation
@echo "Generating documentation..."
$(VENV)/bin/sphinx-build -b html docs/ docs/_build/html
@echo "Documentation generated in docs/_build/html/"
.PHONY: notebook
notebook: ## Start Jupyter notebook server
@echo "Starting Jupyter notebook server..."
$(VENV)/bin/jupyter notebook
# Monitoring and Logs
.PHONY: logs
logs: ## Show recent logs
@echo "Recent logs:"
@tail -n 50 $(LOGS_DIR)/mms_finance.log
.PHONY: monitor
monitor: ## Monitor pipeline execution
@echo "Monitoring pipeline..."
@tail -f $(LOGS_DIR)/mms_finance.log
# Configuration
.PHONY: config
config: ## Show current configuration
@echo "Current configuration:"
@cat $(CONFIG_FILE)
.PHONY: validate-config
validate-config: ## Validate configuration file
@echo "Validating configuration..."
$(VENV)/bin/python -c "from src.utils import ConfigManager; cm = ConfigManager('$(CONFIG_FILE)'); print('Configuration valid!' if cm.validate_config() else 'Configuration invalid!')"
# Quick Commands
.PHONY: quick-start
quick-start: setup create-dirs run ## Quick start: setup and run pipeline
@echo "Quick start complete!"
.PHONY: quick-start-minimal
quick-start-minimal: setup create-dirs run-no-sentiment ## Quick start with minimal dependencies
@echo "Quick start (minimal) complete!"
.PHONY: quick-start-with-download
quick-start-with-download: setup create-dirs download-data run ## Quick start: setup, download data, and run pipeline
@echo "Quick start with download complete!"
.PHONY: dev-setup
dev-setup: setup install create-dirs ## Development setup
@echo "Development setup complete!"
.PHONY: full-clean
full-clean: clean ## Full cleanup including data and results
@echo "Full cleanup..."
rm -rf $(DATA_DIR)/processed/*
rm -rf $(RESULTS_DIR)/*
rm -rf $(LOGS_DIR)/*
@echo "Full cleanup complete!"
# Dependencies
.PHONY: update-deps
update-deps: ## Update dependencies
@echo "Updating dependencies..."
$(VENV)/bin/pip install --upgrade -r requirements.txt
.PHONY: freeze-deps
freeze-deps: ## Freeze current dependencies
@echo "Freezing dependencies..."
$(VENV)/bin/pip freeze > requirements-frozen.txt
# Data Quality
.PHONY: check-data
check-data: ## Check data quality
@echo "Checking data quality..."
$(VENV)/bin/python -c "import pandas as pd; df = pd.read_csv('$(RAW_DATA_DIR)/ml_ready_assets.csv'); print(f'Assets data shape: {df.shape}'); print(f'Missing values: {df.isnull().sum().sum()}')"
.PHONY: validate-data
validate-data: ## Validate processed data
@echo "Validating processed data..."
$(VENV)/bin/python -c "import pandas as pd; import os; files = [f for f in os.listdir('$(PROCESSED_DATA_DIR)') if f.endswith('.parquet')]; print(f'Processed files: {files}')"
# Performance
.PHONY: benchmark
benchmark: ## Run performance benchmarks
@echo "Running benchmarks..."
$(VENV)/bin/python -c "import time; start = time.time(); print('Benchmark complete!')"
.PHONY: profile
profile: ## Profile pipeline performance
@echo "Profiling pipeline..."
$(VENV)/bin/python -m cProfile -o profile_output.prof $(SRC_DIR)/main.py
# Deployment
.PHONY: package
package: ## Package the application
@echo "Packaging application..."
$(PYTHON) setup.py sdist bdist_wheel
.PHONY: deploy
deploy: ## Deploy the application
@echo "Deploying application..."
@echo "Deployment complete!"
# Environment
.PHONY: env
env: ## Show environment information
@echo "Environment Information:"
@echo "Python version: $$($(PYTHON) --version)"
@echo "Pip version: $$($(PIP) --version)"
@echo "Virtual environment: $(VENV)"
@echo "Source directory: $(SRC_DIR)"
@echo "Configuration file: $(CONFIG_FILE)"
# Web Application Targets
.PHONY: web-app
web-app: setup ## Start the web application
@echo "Starting MMS Finance Web Application..."
$(VENV)/bin/python web_app/run_web_app.py
.PHONY: web-setup
web-setup: setup ## Setup web application dependencies
@echo "Installing web application dependencies..."
$(VENV)/bin/pip install flask>=2.3.0 flask-cors>=4.0.0 gunicorn>=21.0.0
@echo "Web application setup complete!"
.PHONY: web-test
web-test: web-setup ## Test web application
@echo "Testing web application..."
$(VENV)/bin/python -c "import flask; print('Flask version:', flask.__version__)"
@echo "Web application test complete!"
# Default target
.DEFAULT_GOAL := help