feat(mcp): add quarterly pyramid distribution lookup

This commit is contained in:
yuxuanhui
2026-09-13 10:39:31 +08:00
parent db328c62dc
commit 7c8188df9c
8 changed files with 259 additions and 3 deletions
+20
View File
@@ -25,6 +25,7 @@ from ..research.workspace_contracts import FieldAvailabilityInput
from ..schemas import JobInput
from ..submission import CheckInput, correlation_allows_check, create_check_job, local_alpha, source
from ..submission import fingerprint as submission_fingerprint
from ..worldquant import WqError
from .contracts import DirectCandidate, History
from .queries import EvidenceQueries, page
@@ -48,6 +49,25 @@ class ResearchAccess:
def run_url(self, run_id):
return f"{self.public_origin}/#backtests?run_id={run_id}"
async def pyramid_distribution(self, args):
"""Read the supplied date's full quarter using the three-Alpha completion rule."""
from .pyramids import distribution, quarter_period
account = await self.db.get(Account, self.principal.account_id)
if not account or account.wq_user_id != self.principal.wq_user_id:
raise ResearchError("ACCOUNT_MISMATCH", "平台账户绑定已变化")
period = quarter_period(args.current_date)
try:
raw = await self.client.get_pyramid_alphas(period["start_date"], period["end_date"])
groups = distribution(raw, args.region, args.delay)
except WqError as exc:
raise ResearchError(exc.code.upper(), str(exc), retryable=True) from None
except ValueError as exc:
raise ResearchError("INVALID_PLATFORM_DATA", str(exc)) from None
return {"region": args.region, "delay": args.delay, "threshold": 3,
"current_date": args.current_date.isoformat(), "period": period,
"source": "worldquant_platform", **groups}
async def capabilities(self, args):
return {**await self.backtests.capabilities(), "max_candidates": 100,
"settings_schema": DirectCandidate.model_json_schema(),