수정본
This commit is contained in:
6
backend/migrations/add_ml_ensemble_columns.sql
Normal file
6
backend/migrations/add_ml_ensemble_columns.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- ML 앙상블 스코어 컬럼 추가 (stock_analysis 테이블)
|
||||
-- 실행: psql -d autostock_db -f migrations/add_ml_ensemble_columns.sql
|
||||
|
||||
ALTER TABLE stock_analysis ADD COLUMN IF NOT EXISTS ml_score INTEGER;
|
||||
ALTER TABLE stock_analysis ADD COLUMN IF NOT EXISTS ml_confidence NUMERIC(5, 4);
|
||||
ALTER TABLE stock_analysis ADD COLUMN IF NOT EXISTS ml_signal VARCHAR(10);
|
||||
39
backend/migrations/add_risk_management.sql
Normal file
39
backend/migrations/add_risk_management.sql
Normal file
@@ -0,0 +1,39 @@
|
||||
-- 🔥 리스크 관리 기능 추가를 위한 DB 마이그레이션
|
||||
|
||||
-- 1. trading_sessions 테이블 생성 (일일 리스크 관리)
|
||||
CREATE TABLE IF NOT EXISTS trading_sessions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
session_date DATE NOT NULL UNIQUE,
|
||||
consecutive_losses INTEGER DEFAULT 0,
|
||||
consecutive_wins INTEGER DEFAULT 0,
|
||||
daily_profit_loss NUMERIC(15, 2) DEFAULT 0,
|
||||
daily_trades_count INTEGER DEFAULT 0,
|
||||
is_paused BOOLEAN DEFAULT FALSE,
|
||||
pause_reason VARCHAR(200),
|
||||
starting_balance NUMERIC(15, 2),
|
||||
ending_balance NUMERIC(15, 2),
|
||||
peak_balance NUMERIC(15, 2),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_trading_sessions_date ON trading_sessions(session_date);
|
||||
|
||||
-- 2. trade_history 테이블에 리스크 관리 필드 추가
|
||||
ALTER TABLE trade_history
|
||||
ADD COLUMN IF NOT EXISTS entry_trade_id INTEGER,
|
||||
ADD COLUMN IF NOT EXISTS slippage NUMERIC(15, 2),
|
||||
ADD COLUMN IF NOT EXISTS commission NUMERIC(15, 2),
|
||||
ADD COLUMN IF NOT EXISTS net_profit_loss NUMERIC(15, 2),
|
||||
ADD COLUMN IF NOT EXISTS profit_loss_rate NUMERIC(10, 4);
|
||||
|
||||
-- 3. 기존 데이터에 대한 기본값 설정 (선택적)
|
||||
-- 기존 매도 거래에 대해 profit_loss_rate 계산 (매수 거래와 페어링 필요)
|
||||
-- 이 부분은 실제 데이터에 맞게 커스터마이징 필요
|
||||
|
||||
COMMENT ON TABLE trading_sessions IS '일일 트레이딩 세션 관리 - 연속 손실 추적 및 리스크 제한';
|
||||
COMMENT ON COLUMN trade_history.entry_trade_id IS '매도 시 연결된 매수 거래 ID';
|
||||
COMMENT ON COLUMN trade_history.slippage IS '슬리피지 (체결가 - 주문가)';
|
||||
COMMENT ON COLUMN trade_history.commission IS '수수료';
|
||||
COMMENT ON COLUMN trade_history.net_profit_loss IS '수수료 차감 후 순손익';
|
||||
COMMENT ON COLUMN trade_history.profit_loss_rate IS '수익률 (%)';
|
||||
11
backend/migrations/add_trade_history_columns.sql
Normal file
11
backend/migrations/add_trade_history_columns.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- 거래 이력 테이블에 새로운 컬럼 추가
|
||||
ALTER TABLE trade_history
|
||||
ADD COLUMN IF NOT EXISTS total_amount NUMERIC(15, 2),
|
||||
ADD COLUMN IF NOT EXISTS entry_reason TEXT,
|
||||
ADD COLUMN IF NOT EXISTS exit_reason TEXT,
|
||||
ADD COLUMN IF NOT EXISTS signals JSONB;
|
||||
|
||||
-- 기존 데이터에 대한 total_amount 계산
|
||||
UPDATE trade_history
|
||||
SET total_amount = executed_price * executed_quantity
|
||||
WHERE total_amount IS NULL AND executed_price IS NOT NULL AND executed_quantity IS NOT NULL;
|
||||
Reference in New Issue
Block a user