闲来无事让 chatgpt 生成了一个回测任意倍数杠杆 SPY 的代码,回测了一下过去两年
结果发现 15x SPY,MER=10%(甚至99.99%)都能大赚特赚
不过这看上去更像是2024一年的功劳,杠杆调小一点的话可以不在23年年末回调回去
顺带一提,显然这种 ETF 活不过任何一次熔断
Python 代码如下,敬请把玩,不构成投资建议:
import numpy as np
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt#Parameters
START_DATE = “2023-01-01”
END_DATE = “2025-01-01”
LEVERAGE = 15
EXPENSE_RATIO = 0.10 # 10% per year#Download historical S&P 500 data (SPY ETF as a proxy)
spy = yf.download(“SPY”, start=START_DATE, end=END_DATE)
spy[“Daily Return”] = spy[“Close”].pct_change()#Simulating a 15× leveraged ETF
leveraged_returns = LEVERAGE * spy[“Daily Return”]#Apply Expense Ratio (daily)
daily_expense = (1 - EXPENSE_RATIO) ** (1/252) # Convert annual to daily reduction
leveraged_returns = leveraged_returns * daily_expense#Create cumulative returns
spy[“Cumulative SPY”] = (1 + spy[“Daily Return”]).cumprod()
leveraged_cumulative = (1 + leveraged_returns).cumprod()#Plot results
plt.figure(figsize=(12, 6))
plt.plot(spy.index, spy[“Cumulative SPY”], label=“SPY (S&P 500)”, linewidth=2)
plt.plot(spy.index, leveraged_cumulative, label=“Hypothetical 15× S&P 500 ETF”, linewidth=2, linestyle=“dashed”)
plt.yscale(“log”) # Log scale for better visualization
plt.xlabel(“Year”)
plt.ylabel(“Cumulative Return”)
plt.title(“Backtest of Hypothetical 15× Leveraged S&P 500 ETF”)
plt.legend()
plt.grid()
plt.show()