Signal visualization

While creating signals is just the beginning of the process of building a trading strategy, we need to visualize how the strategy performs in the long term. We will plot the graph of the historical data we used by using the matplotlib library. This library is well known in the Python world for making it easy to plot charts:

  1. We will start by importing this library:
import matplotlib.pyplot as plt
  1. Next, we will define a figure that will contain our chart:
fig = plt.figure()
ax1 = fig.add_subplot(111, ylabel='Google price in $')
  1. Now, we will plot the price within the range of days we initially chose:
goog_data_signal['price'].plot(ax=ax1, color='r', lw=2.)
  1. Next, we will draw an up arrow when we buy one Google share:
ax1.plot(goog_data_signal.loc[goog_data_signal.positions == 1.0].index,
goog_data_signal.price[goog_data_signal.positions == 1.0],
'^', markersize=5, color='m')
  1. Next, we will draw a down arrow when we sell one Google share:
ax1.plot(goog_data_signal.loc[goog_data_signal.positions == -1.0].index,
goog_data_signal.price[goog_data_signal.positions == -1.0],
'v', markersize=5, color='k')
plt.show()

This code will return the following output. Let's have a look at the following plot:

Up to this point, we introduced the trading idea, we implemented the signal triggering buy and sell orders, and we talked about the way of restricting the strategy by limiting the position to one share on the market. Once these steps are satisfactory, the following step is backtesting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
54.175.120.161