日线表格末尾追加次日预测行,展示振幅阈值供交易参考
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import date
|
||||
from datetime import date, timedelta
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -80,10 +80,15 @@ def contract_detail(request: Request, contract: str, db: Session = Depends(get_d
|
||||
latest = bars[0] if bars else None
|
||||
|
||||
# Predict next trading day amplitude: mean of latest 5 diffs
|
||||
# Compute next trading date
|
||||
next_date = latest.date + timedelta(days=1) if latest else None
|
||||
if next_date and next_date.weekday() >= 5:
|
||||
next_date += timedelta(days=7 - next_date.weekday())
|
||||
|
||||
# Predict next trading day amplitude
|
||||
next_amp = None
|
||||
if len(bars) >= 5:
|
||||
next_amp = round(sum(b.diff for b in bars[:5]) / 5)
|
||||
|
||||
template = request.app.state.templates.get_template("contract.html")
|
||||
return HTMLResponse(
|
||||
template.render(
|
||||
@@ -94,6 +99,8 @@ def contract_detail(request: Request, contract: str, db: Session = Depends(get_d
|
||||
rows=rows,
|
||||
latest=latest,
|
||||
next_amp=next_amp,
|
||||
next_date=next_date.strftime("%Y/%-m/%-d") if next_date else None,
|
||||
next_weekday=WEEKDAY_ZH.get(next_date.weekday(), "") if next_date else "",
|
||||
row_count=len(rows),
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user