日线表格末尾追加次日预测行,展示振幅阈值供交易参考
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 import APIRouter, Depends, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from sqlalchemy.orm import Session
|
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
|
latest = bars[0] if bars else None
|
||||||
|
|
||||||
# Predict next trading day amplitude: mean of latest 5 diffs
|
# 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
|
next_amp = None
|
||||||
if len(bars) >= 5:
|
if len(bars) >= 5:
|
||||||
next_amp = round(sum(b.diff for b in bars[:5]) / 5)
|
next_amp = round(sum(b.diff for b in bars[:5]) / 5)
|
||||||
|
|
||||||
template = request.app.state.templates.get_template("contract.html")
|
template = request.app.state.templates.get_template("contract.html")
|
||||||
return HTMLResponse(
|
return HTMLResponse(
|
||||||
template.render(
|
template.render(
|
||||||
@@ -94,6 +99,8 @@ def contract_detail(request: Request, contract: str, db: Session = Depends(get_d
|
|||||||
rows=rows,
|
rows=rows,
|
||||||
latest=latest,
|
latest=latest,
|
||||||
next_amp=next_amp,
|
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),
|
row_count=len(rows),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -52,9 +52,19 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<span class="na">—</span>
|
<span class="na">—</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if next_date %}
|
||||||
|
<tr style="background:var(--accent-light);font-weight:500;">
|
||||||
|
<td>{{ next_date }}</td>
|
||||||
|
<td>{{ next_weekday }}</td>
|
||||||
|
<td class="na">—</td>
|
||||||
|
<td class="na">—</td>
|
||||||
|
<td class="na">—</td>
|
||||||
|
<td class="na">—</td>
|
||||||
|
<td class="na">—</td>
|
||||||
|
<td><span style="color:var(--accent);font-weight:700;">{{ next_amp }}</span></td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user