How does one go about properly backtesting and visualising their strategy using their trading signals and historical prices where the trading signals are 1 for long, 0 for no position -1 for short?
Obviously the end result should look something like this, this visual originates from a simple moving average strategy from "Python for Finance"
My strategy is not the same however since the trading signals are just 1s and -1s I would expect to be able to get a similar result, however when I try using the following code, I get the following graph, and I have absolutely no idea why.
data['XONRETURNS'] = np.log(data['XON'] / data['XON'].shift(1))
data['XONSTRATEGY'] = (data['POSITIONXON'].shift(1)) * (data['XONRETURNS'])
ax = data[['XONRETURNS', 'XONSTRATEGY']].cumsum().apply(np.exp).plot(figsize=(10, 6))
XON is simply the raw price data and XON strategy is using the trading signals i.e. POSITIONXON.
My suspicion is that either the returns or something relating to taking the log(or not) is causing this issue?
General answers on backtesting from trading signals will also be very helpful so that I can start from scratch if need be.
Many thanks!