How to develop a trading strategy

We'll begin our strategy development by focusing on the technical aspects. Let's take a look at the S&P 500 over the last few  years. We'll use pandas to import our data. This will give us access to several sources of stock data, including Yahoo! And Google.

  1. First, you'll need to install the data reader:
!pip install pandas_datareader 
  1. Then, go ahead and incorporate your imports:
import pandas as pd 
from pandas_datareader import data, wb 
import matplotlib.pyplot as plt 
 
%matplotlib inline 
pd.set_option('display.max_colwidth', 200) 
  1. Now, we'll get our data for the SPY ETF, which represents the stocks of the S&P 500. We'll pull data from the start of 2010 through December 2018:
import pandas_datareader as pdr 
 
start_date = pd.to_datetime('2010-01-01') 
stop_date = pd.to_datetime('2018-12-01') 
 
spy = pdr.data.get_data_yahoo('SPY', start_date, stop_date) 

This code generates the following output:

  1. We can now plot our data. We'll select only the closing price:
spy_c = spy['Close'] 
 
fig, ax = plt.subplots(figsize=(15,10)) 
spy_c.plot(color='k') 
plt.title("SPY", fontsize=20); 
  1. This generates the following output:

In the preceding diagram, we see the price chart of the daily closing price of the S&P 500 for the period we selected.

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

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