May 25, 2019
After demo trading a failing strategy for a few months, let's investigate why performance has been less than stellar. First, let's reference our dataframe.
import pandas as pd
hdf = pd.read_csv('history.csv')
hdf = hdf[['accountBalance','halfSpreadCost','pl','time']]
hdf.head(2)
Plot the total equity curve of the strategy. This is the result of the trading system over the timeframe of interest, and includes any slippage or commission costs.
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
plt.plot(hdf.pl.cumsum())
plt.title('Strategy Equity Curve')
plt.xlabel('Trade Number')
plt.ylabel('Cumulative PnL')
plt.show()
Since we are also collecting the commissions cost of exits for this strategy, let's investigate the "half spread cost" and see what the total cost is.
plt.plot(hdf.halfSpreadCost)
plt.title('Exit Cost per Trade')
plt.xlabel('Trade Number')
plt.ylabel('Cost')
plt.show()
print('Total half spread cost on exits: $', round(hdf.halfSpreadCost.sum()))
print('Average of half spread cost: ', round(hdf.halfSpreadCost.mean()))
If we didn't have these costs, what would the equity curve look like?
hdf['Half Spreads'] = hdf['accountBalance'] + hdf['halfSpreadCost'].cumsum()
plt.plot(hdf['accountBalance'])
plt.plot(hdf['Half Spreads'])
plt.title('Cost of doing business')
plt.legend()
plt.show()
Let's see what the equity curve would look like if there were no commissions costs. Because I am too lazy to retrieve the actual cost of entries right now, we will approximate the entries to be the same cost as the exits by multiplying exit costs by 2, and assuming this averages out to be true over time.
hdf['Reality'] = hdf.accountBalance
hdf['approxTotalSpread'] = hdf['halfSpreadCost'] * 2
hdf['No Spreads'] = hdf['accountBalance'] + hdf['approxTotalSpread'].cumsum()
plt.plot(hdf.Reality)
plt.plot(hdf['Half Spreads'])
plt.plot(hdf['No Spreads'])
plt.axhline(hdf.accountBalance[0])
plt.title('Cost of Doing Business')
plt.legend()
plt.show()
The variance observed above, from the Reality curve to the No Spreads curve, represents the challenge in overcoming the cost of doing business for any trading system, or any similar betting system.
In order to obtain profitability, the edge must overcome the frequency of execution that incurs these costs.