feat: signal abstraction layer + sizer + HS300 universe + PnL/IC reports

This commit is contained in:
Yuxuan Yan
2026-06-07 09:44:33 +08:00
parent 085e51abf1
commit da01312292
20 changed files with 610 additions and 23 deletions
+26
View File
@@ -0,0 +1,26 @@
"""Signal-driven multi-stock strategy."""
import backtrader as bt
import pandas as pd
class AlphaStrategy(bt.Strategy):
"""Trade each feed based on its precomputed ``signal`` line.
The strategy delegates the buy/sell/hold decision to a portfolio builder
(e.g. ``ThresholdBuilder``) and sizes entries with ``order_target_percent``.
"""
def __init__(self, builder):
self.builder = builder
def next(self):
for data in self.datas:
sig = data.signal[0]
if pd.isna(sig):
continue
in_position = bool(self.getposition(data).size)
action = self.builder.build(float(sig), in_position)
if action.action == "buy":
self.order_target_percent(data=data, target=action.size_pct)
elif action.action == "sell":
self.close(data=data)