portfolio_opt / apply_phantom.py
engineportf's picture
Upload folder using huggingface_hub
39cba9d verified
Raw
History Blame Contribute Delete
3.16 kB
import re
app_path = r"d:\portfolio engine\engine\static\app.js"
with open(app_path, "r", encoding="utf-8") as f:
app_js = f.read()
# 1. Increase antifragile time to 2.5s
app_js = app_js.replace("< 1500)", "< 2500)")
app_js = app_js.replace("Type ANTIFRAGILE in under 1.5 seconds.", "Type ANTIFRAGILE in under 2.5 seconds.")
# 2. Add phantomLine chart initialization
old_phantom_chart = """if (id === 'phantom' && window.Chart) {
new Chart(modal.querySelector('#phantomRadar'), { type: 'radar', data: { labels: ['Vol','Ret','Sharpe','DD','Alpha'], datasets: [{ label:'Phantom 60/40', data:[8, 9, 7, 8, 5], borderColor:'#00ffff' }] } });
}"""
new_phantom_chart = """if (id === 'phantom' && window.Chart) {
new Chart(modal.querySelector('#phantomRadar'), {
type: 'radar',
data: {
labels: ['Volatility', 'Returns', 'Sharpe Ratio', 'Max Drawdown', 'Alpha'],
datasets: [{
label:'Phantom 60/40 Portfolio Metrics',
data:[8, 9, 7, 8, 5],
borderColor:'#00ffff',
backgroundColor: 'rgba(0, 255, 255, 0.2)',
borderWidth: 2
}]
},
options: {
scales: { r: { ticks: { display: false }, grid: { color: 'rgba(255,255,255,0.1)' }, pointLabels: { color: '#a5b4fc', font: { size: 12 } } } },
plugins: { legend: { labels: { color: '#e2e8f0' } } },
responsive: true,
maintainAspectRatio: false
}
});
new Chart(modal.querySelector('#phantomLine'), {
type: 'line',
data: {
labels: ['2000', '2005', '2010', '2015', '2020', '2024'],
datasets: [
{ label: 'S&P 500', data: [100, 110, 130, 210, 340, 480], borderColor: '#ef4444', backgroundColor: 'transparent' },
{ label: 'Phantom 60/40', data: [100, 125, 160, 220, 310, 410], borderColor: '#00ffff', backgroundColor: 'transparent' }
]
},
options: {
scales: {
y: { grid: { color: 'rgba(255,255,255,0.05)' }, ticks: { color: '#94a3b8' } },
x: { grid: { color: 'rgba(255,255,255,0.05)' }, ticks: { color: '#94a3b8' } }
},
plugins: { legend: { labels: { color: '#e2e8f0' } } },
responsive: true,
maintainAspectRatio: false
}
});
}"""
# Fix indentation and replace
old_phantom_chart_actual = "if (id === 'phantom' && window.Chart) {\n new Chart(modal.querySelector('#phantomRadar'), { type: 'radar', data: { labels: ['Vol','Ret','Sharpe','DD','Alpha'], datasets: [{ label:'Phantom 60/40', data:[8, 9, 7, 8, 5], borderColor:'#00ffff' }] } });\n }"
if old_phantom_chart_actual in app_js:
app_js = app_js.replace(old_phantom_chart_actual, new_phantom_chart)
else:
# Just a fuzzy replace
import re
app_js = re.sub(r"if \(id === 'phantom' && window\.Chart\) \{.*?\}\s*\}", new_phantom_chart + "\n }\n }", app_js, flags=re.DOTALL)
with open(app_path, "w", encoding="utf-8") as f:
f.write(app_js)
print("Applied phantom chart and antifragile timer fixes")