47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
|
|
"""
|
||
|
|
Position sizing Pydantic schemas.
|
||
|
|
"""
|
||
|
|
from enum import Enum
|
||
|
|
from typing import Optional
|
||
|
|
|
||
|
|
from pydantic import BaseModel, Field
|
||
|
|
|
||
|
|
|
||
|
|
class SizingMethod(str, Enum):
|
||
|
|
FIXED = "fixed"
|
||
|
|
KELLY = "kelly"
|
||
|
|
ATR = "atr"
|
||
|
|
|
||
|
|
|
||
|
|
class PositionSizeRequest(BaseModel):
|
||
|
|
capital: float = Field(..., gt=0, description="Total capital (KRW)")
|
||
|
|
method: SizingMethod = Field(..., description="Sizing method")
|
||
|
|
# fixed_ratio params
|
||
|
|
num_positions: int = Field(default=10, ge=1, le=50)
|
||
|
|
cash_ratio: float = Field(default=0.3, ge=0, lt=1.0)
|
||
|
|
# kelly params
|
||
|
|
win_rate: Optional[float] = Field(default=None, gt=0, le=1.0)
|
||
|
|
avg_win: Optional[float] = Field(default=None, gt=0)
|
||
|
|
avg_loss: Optional[float] = Field(default=None, gt=0)
|
||
|
|
# atr params
|
||
|
|
atr: Optional[float] = Field(default=None, gt=0)
|
||
|
|
risk_pct: float = Field(default=0.02, gt=0, le=1.0)
|
||
|
|
|
||
|
|
|
||
|
|
class PositionSizeResponse(BaseModel):
|
||
|
|
method: str
|
||
|
|
position_size: float
|
||
|
|
shares: int
|
||
|
|
risk_amount: float
|
||
|
|
notes: str
|
||
|
|
|
||
|
|
|
||
|
|
class MethodInfo(BaseModel):
|
||
|
|
name: str
|
||
|
|
label: str
|
||
|
|
description: str
|
||
|
|
|
||
|
|
|
||
|
|
class MethodsResponse(BaseModel):
|
||
|
|
methods: list[MethodInfo]
|