13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

456

sentiment_handler = SentdexSentimentHandler(

config.CSV_DATA_DIR, "sentdex_sample.csv",

events_queue, tickers=tickers,

start_date=start_date, end_date=end_date

)

base_quantity = 2000

sent_buy = 6

sent_sell = -1

strategy = SentdexSentimentStrategy(

tickers, events_queue,

sent_buy, sent_sell, base_quantity

)

strategy = Strategies(strategy, DisplayStrategy())

In order to execute this strategy it is necessary to utilise your QSTrader virtual environment,

as always, and type the following into the terminal, where the list of tickers must be adapted to

suit the particular strategy at hand. Make sure to include SPY if a benchmark comparison is

desired.

The following example simulation consists of a selection of S&P500 defence stocks, including

Boeing, General Dynamics, Lockheed Martin, Northrop-Grumman and Raytheon:

$ python sentdex_sentiment_backtest.py --tickers=BA,GD,LMT,NOC,RTN,SPY

The truncated output of the defence stocks example will be as follows:

..

..

---------------------------------

Backtest complete.

Sharpe Ratio: 1.62808089233

Max Drawdown: 0.0977963517677

Max Drawdown Pct: 0.0977963517677

30.5 Strategy Results

30.5.1 Transaction Costs

The strategy results presented here are given net of transaction costs. The costs are simulated

using Interactive Brokers US equities fixed pricing for shares in North America. They are

reasonably representative of what could be achieved in a real trading strategy.

30.5.2 Sentiment on S&P500 Tech Stocks

The base quantity of shares used for each ticker is 2,000.

The tech stocks sentiment analysis strategy posts a CAGR of 21.0% compared to the benchmark

of 9.4%, using 2,000 shares of each of the five tickers. It generates large gains in only

three months, namely May 2013, October 2013 and July 2015. The remainder of the time it

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!