6) operators
Arithmetic operator
enable arithmetic operations including basic math operations and rounding.
logical
logical opeator와 condition operator를 결합해서 조건문 작성 가능
다만 조건을 너무 엄격하게 설정하면
실제로 신호가 발생하는 데이터 수가 줄어들고
과최적화(overfitting) 위험이 커질 수 있습니다. 예시로 제시된 조건 유형은 다음과 같습니다:
- 거래량이 평소보다 높을 때만 포지션 변경
- 극단적 상황에서는 포지션 청산
- 변동성이 높은 구간에서는 포지션 변경 제한
방식은 두가지 가 있음
- a) if else(condition, if_true, if_false)
if_true / if_false에는 단순 값도 가능하고, 완전한 알파 표현식도 가능합니다.
- b) condition? if_true:if_false
- c) trade_when(entry_condition, Alpha, exit_condition)-> 포지션 유지 기능이 있기 때문에 turnover를 줄일 수 있음 / 강제청산 기능도 있음 exit
entry = True → 그날 Alpha 값으로 새로 계산해 저장
entry = False & exit = False → 이전 값 유지
exit = True → NaN (청산)
If the exit condition is –1, no position liquidation occurs.exit = True → “이 종목은 오늘부터 없다”
exit = -1 → “한번 잡으면 계속 간다”
time series
Time series operators perform operations related to past d-day values for specific stocks. 주의를 해야할 점은 최종 포트폴리오 구성은 항상 cross sectional operator를 기준으로 구성됨. 롱숏 중립 포트폴리오이기 때문에
항상 그날의 상대적 우열이 중요하고,
그래서 최종 단계는 cross-sectional입니다.
만약 순수 time-series 전략(예: 한 종목만 매수/매도)이라면 이 구조가 필요 없겠지만,
BRAIN은 기본적으로 시장 중립 롱숏 구조라서 이렇게 작동합니다.
- ts_mean(x,d) calculates the average of x over d days.예를 들어 d=5이면, 오늘 값을 포함해 최근 5일 평균을 구하는 구조입니다.
- ts_rank(x, d)
- 기존 rankd에 ts가 추가된 형태
- ts_zscore(x, d)
- Shows how far today's x is from the d-day average in standard deviation units (Z-score)
- ts_regression(y,x,lookback_days,rettype=0)
cross sectional operator
Cross-sectional operators compare or process values across target stocks at a specific point in time. For example, rank(x) orders x values at a specific time and distributes them from 0 to 1 (time series와 반대인 횡단면 분석)
- rank(x)
Returns a uniformly distributed value between 0.0 and 1.0 based on ranking among all stocks
- zscore(x)
Shows how far an instrument's x value is from the mean in standard deviation units (Z-score)
- winsorize(x, std=4)
winsorize(x, std=4): Limits extreme values so all x values fall between upper and lower bounds set by standard deviation multiples
vector operator
When searching for data fields, you might find vector-type data fields. Instead of having a single value per stock per day, these store multiple values (in vector format). To convert these into Alpha positions, you need to transform them into a single representative value like mean or median. These operators serve this purpose.
예시 1) 어떤 종목 A의 오늘 애널리스트 목표가 변화율이 [+3%, +1%, -2%, +4%]처럼 4개라면 벡터입니다. vec_mean(x) → (3+1-2+4)/4 = 1.5%로 단일 값 생성 → rank(vec_mean(x))로 알파 구성.
transformational operator
변환(Transformational) 연산자는 행렬(종목 × 날짜 구조) 내부의 값을 특정 연산을 통해 변환하는 역할을 합니다.
group operators
BRAIN에는 industry라는 group-type 데이터 필드가 존재합니다. 이 필드는 각 종목이 어떤 산업에 속하는지를 나타내는 그룹 라벨입니다.즉, industry는 계산 대상이 아니라 계산의 기준이 되는 그룹 변수입니다. group operator와 함께 쓰임Group operators include operations like calculating representative values (mean/sum/median) within groups or performing neutralization within groups