-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,086 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 创建项目根目录 | ||
mkdir quant-trading-backend | ||
|
||
# 进入项目根目录 | ||
cd quant-trading-backend | ||
|
||
# 创建应用目录和子目录 | ||
mkdir -p app/routes app/services app/utils | ||
|
||
# 创建测试目录和测试文件 | ||
mkdir tests | ||
touch tests/__init__.py | ||
touch tests/test_config.py | ||
touch tests/test_data.py | ||
touch tests/test_evaluation.py | ||
touch tests/test_model.py | ||
|
||
# 创建应用的 __init__.py 文件 | ||
touch app/__init__.py | ||
|
||
# 创建路由文件 | ||
touch app/routes/__init__.py | ||
touch app/routes/config_routes.py | ||
touch app/routes/data_routes.py | ||
touch app/routes/evaluation_routes.py | ||
touch app/routes/model_routes.py | ||
|
||
# 创建服务文件 | ||
touch app/services/__init__.py | ||
touch app/services/config_service.py | ||
touch app/services/data_service.py | ||
touch app/services/evaluation_service.py | ||
touch app/services/model_service.py | ||
|
||
# 创建工具文件 | ||
touch app/utils/__init__.py | ||
touch app/utils/db_utils.py | ||
|
||
# 创建 requirements.txt 文件用于指定依赖 | ||
touch requirements.txt | ||
|
||
# 创建环境变量文件 | ||
touch .env | ||
touch .flaskenv | ||
|
||
# 创建 Flask 配置文件 | ||
touch config.py | ||
|
||
# 创建 Flask 启动文件 | ||
touch run.py | ||
|
||
# 输出目录结构 | ||
tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# 创建项目目录 | ||
mkdir quant-trading-platform | ||
|
||
# 进入项目目录 | ||
cd quant-trading-platform | ||
|
||
# 创建组件目录和子目录 | ||
mkdir -p components/ConfigEditor components/DataManagement components/ModelManagement components/Evaluation | ||
|
||
# 创建页面目录 | ||
mkdir pages | ||
|
||
# 创建公共资源目录 | ||
mkdir public | ||
|
||
# 创建样式目录 | ||
mkdir styles | ||
|
||
# 创建工具函数目录 | ||
mkdir utils | ||
|
||
# 创建配置Schema目录 | ||
mkdir schemas | ||
|
||
# 创建组件文件 | ||
touch components/ConfigEditor/ConfigEditor.js | ||
touch components/ConfigEditor/ConfigForm.js | ||
touch components/DataManagement/DataInitiator.js | ||
touch components/DataManagement/DataStatus.js | ||
touch components/ModelManagement/ModelTraining.js | ||
touch components/ModelManagement/TrainingStatus.js | ||
touch components/Evaluation/EvaluationResults.js | ||
touch components/Evaluation/PerformanceCharts.js | ||
|
||
# 创建页面文件 | ||
touch pages/index.js | ||
touch pages/config.js | ||
touch pages/data.js | ||
touch pages/model.js | ||
touch pages/evaluation.js | ||
|
||
# 创建样式文件 | ||
touch styles/globals.css | ||
|
||
# 创建工具函数文件 | ||
touch utils/api.js | ||
|
||
# 创建配置Schema文件 | ||
touch schemas/config-schema.json | ||
|
||
# 创建环境变量文件和配置文件 | ||
touch .env | ||
touch next.config.js | ||
|
||
# 创建 package.json 和 README.md | ||
touch package.json | ||
touch README.md | ||
|
||
# 输出目录结构 | ||
tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URI=mysql+pymysql://user:password@localhost/dbname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FLASK_APP=run.py | ||
FLASK_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# app/__init__.py | ||
from flask import Flask | ||
from .routes import config_routes, data_routes, evaluation_routes, model_routes | ||
|
||
def create_app(): | ||
app = Flask(__name__) | ||
app.config.from_pyfile('config.py') | ||
|
||
app.register_blueprint(config_routes.bp) | ||
app.register_blueprint(data_routes.bp) | ||
app.register_blueprint(evaluation_routes.bp) | ||
app.register_blueprint(model_routes.bp) | ||
|
||
return app |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# app/routes/config_routes.py | ||
from flask import Blueprint, request, jsonify | ||
from ..services.config_service import get_config, save_config | ||
|
||
bp = Blueprint('config', __name__, url_prefix='/api/config') | ||
|
||
@bp.route('/', methods=['GET']) | ||
def get_configuration(): | ||
# 获取配置信息 | ||
config = get_config() | ||
return jsonify(config), 200 | ||
|
||
@bp.route('/', methods=['POST']) | ||
def update_configuration(): | ||
# 更新配置信息 | ||
config_data = request.get_json() | ||
save_config(config_data) | ||
return jsonify({"message": "Configuration updated successfully"}), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# app/routes/data_routes.py | ||
from flask import Blueprint, jsonify | ||
from ..services.data_service import initiate_data_process, get_data_history | ||
|
||
bp = Blueprint('data', __name__, url_prefix='/api/data') | ||
|
||
@bp.route('/initiate', methods=['POST']) | ||
def initiate_data(): | ||
# 启动数据处理流程 | ||
initiate_data_process() | ||
return jsonify({"message": "Data process initiated"}), 200 | ||
|
||
@bp.route('/history', methods=['GET']) | ||
def data_history(): | ||
# 获取数据处理历史 | ||
history = get_data_history() | ||
return jsonify(history), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# app/routes/evaluation_routes.py | ||
from flask import Blueprint, jsonify | ||
from ..services.evaluation_service import get_evaluation_results | ||
|
||
bp = Blueprint('evaluation', __name__, url_prefix='/api/evaluation') | ||
|
||
@bp.route('/results', methods=['GET']) | ||
def evaluation_results(): | ||
# 获取评估结果 | ||
results = get_evaluation_results() | ||
return jsonify(results), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# app/routes/model_routes.py | ||
from flask import Blueprint, jsonify | ||
from ..services.model_service import start_model_training, get_training_status | ||
|
||
bp = Blueprint('model', __name__, url_prefix='/api/model') | ||
|
||
@bp.route('/train', methods=['POST']) | ||
def train_model(): | ||
# 启动模型训练 | ||
start_model_training() | ||
return jsonify({"message": "Model training started"}), 200 | ||
|
||
@bp.route('/status', methods=['GET']) | ||
def training_status(): | ||
# 获取模型训练状态 | ||
status = get_training_status() | ||
return jsonify(status), 200 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# app/services/config_service.py | ||
|
||
def get_config(): | ||
# 这里应该是获取配置的逻辑 | ||
return {"tradingStrategy": "meanReversion"} | ||
|
||
def save_config(config_data): | ||
# 这里应该是保存配置的逻辑 | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# app/services/data_service.py | ||
|
||
def initiate_data_process(): | ||
# 这里应该是启动数据处理流程的逻辑 | ||
pass | ||
|
||
def get_data_history(): | ||
# 这里应该是获取数据处理历史的逻辑 | ||
return [{"timestamp": "2021-01-01T00:00:00", "status": "Completed"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# app/services/evaluation_service.py | ||
|
||
def get_evaluation_results(): | ||
# 这里应该是获取评估结果的逻辑 | ||
return [{"metric": "Accuracy", "value": 0.95}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# app/services/model_service.py | ||
|
||
def start_model_training(): | ||
# 这里应该是启动模型训练的逻辑 | ||
pass | ||
|
||
def get_training_status(): | ||
# 这里应该是获取模型训练状态的逻辑 | ||
return {"status": "Training", "progress": 50} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# app/utils/db_utils.py | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask import current_app | ||
|
||
# 初始化 SQLAlchemy,可以在 app/__init__.py 中完成 | ||
db = SQLAlchemy() | ||
|
||
def get_db(): | ||
"""获取当前应用的数据库对象""" | ||
return db | ||
|
||
def init_db(app): | ||
"""初始化数据库""" | ||
app.config['SQLALCHEMY_DATABASE_URI'] = current_app.config['DATABASE_URI'] | ||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
db.init_app(app) | ||
|
||
# 示例模型 | ||
class Config(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
trading_strategy = db.Column(db.String(50), nullable=False) | ||
max_drawdown = db.Column(db.Float, nullable=False) | ||
stop_loss = db.Column(db.Float, nullable=False) | ||
|
||
# 添加更多字段和方法根据需要 | ||
|
||
def create_tables(): | ||
"""创建数据库表""" | ||
with current_app.app_context(): | ||
db.create_all() | ||
|
||
def drop_tables(): | ||
"""删除数据库表""" | ||
with current_app.app_context(): | ||
db.drop_all() | ||
|
||
# 数据库操作示例 | ||
def get_config_by_id(config_id): | ||
return Config.query.get(config_id) | ||
|
||
def add_new_config(trading_strategy, max_drawdown, stop_loss): | ||
new_config = Config(trading_strategy=trading_strategy, max_drawdown=max_drawdown, stop_loss=stop_loss) | ||
db.session.add(new_config) | ||
db.session.commit() | ||
return new_config | ||
|
||
def update_config(config_id, **kwargs): | ||
config = get_config_by_id(config_id) | ||
if config: | ||
for key, value in kwargs.items(): | ||
setattr(config, key, value) | ||
db.session.commit() | ||
return config | ||
|
||
def delete_config(config_id): | ||
config = get_config_by_id(config_id) | ||
if config: | ||
db.session.delete(config) | ||
db.session.commit() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask==2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# run.py | ||
from app import create_app | ||
|
||
app = create_app() | ||
|
||
if __name__ == "__main__": | ||
app.run() |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NEXT_PUBLIC_API_BASE_URL=https://api.example.com | ||
ANOTHER_ENV_VARIABLE=theValue |
Empty file.
44 changes: 44 additions & 0 deletions
44
mem/quant-trading-platform/components/ConfigEditor/ConfigEditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// components/ConfigEditor/ConfigEditor.js | ||
import React, { useState, useEffect } from 'react'; | ||
import { fetchConfig, saveConfig } from '../../utils/api'; | ||
import ConfigForm from './ConfigForm'; | ||
|
||
const ConfigEditor = () => { | ||
const [configData, setConfigData] = useState(null); | ||
|
||
useEffect(() => { | ||
const loadConfig = async () => { | ||
try { | ||
const data = await fetchConfig(); | ||
setConfigData(data); | ||
} catch (error) { | ||
console.error('Error loading config:', error); | ||
// Handle error appropriately | ||
} | ||
}; | ||
|
||
loadConfig(); | ||
}, []); | ||
|
||
const handleSave = async (updatedConfig) => { | ||
try { | ||
await saveConfig(updatedConfig); | ||
alert('Config saved successfully!'); | ||
} catch (error) { | ||
console.error('Error saving config:', error); | ||
// Handle error appropriately | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
{configData ? ( | ||
<ConfigForm configData={configData} onSave={handleSave} /> | ||
) : ( | ||
<p>Loading configuration...</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConfigEditor; |
Oops, something went wrong.