Qt Cumulative
# Calculate cumulative returns
data['Cumulative_Return']=(1 + data['Strategy_Return']).cumprod()
# Plot cumulative return curve
plt.figure(figsize=(10,6))
plt.plot(data['Cumulative_Return'], label='Strategy Cumulative Return', color='b')
plt.plot(data['Close'] / data['Close'].iloc, label='Stock Cumulative Return', color='g')
plt.title("Cumulative Return of Strategy vs. Stock")
plt.xlabel("Date")
plt.ylabel("Cumulative Return")
plt.legend()
plt.show()
Execute the above code, the output is as follows:
!(#)
YouTip