Algorithmic Trading in Python

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Algorithmic Trading in

Python

Team 6
Introduction
Goal of the Project
● Create “Financial Machine Learning Model” that predicts returns
● Implement “Algorithmic Trading” that utilizes fundamental and sentiment data to
derive absolute return strategy both in bull and bear market.

What Strategy:
● “Micro Alpha model”: Mainly Data-driven
● “General Sentiment” model: Measure the effect of sentiment in Social Media vs
Technical
● Algorithm Upgrade: include 8 Fundamental data factors
● Buy Long at positive ML signal, Sell Short at negative ML signal
● Short-term trading: 1 day
● 1 stock: Red Hat (RHT)
Data collection

- Fundamental Data
- Alternative Data
- Sentiment Analysis
Fundamental Data Collection
Profitability
● Diluted EPS from Continuing Operations: Absolute number
● EBIT Margin, EBITDA Margin: %

Growth
● Revenue % Growth, EBITDA % Growth, EBIT % Growth, Sequential %
Growth in Net Income from Continuing Operations
Financial Structure
● Net Debt to Equity

Feature of Quarterly Released Data: Look ahead bias


● Time delay of data: previous quarter’s data
● Difference in time horizon: “Daily” trading & sentimental analysis vs
“Quarterly” data
Alternative Data Collection

Load Cleaned
and Aggregated
Tweets
Load Twitter
install Libraries Past
WebScraped
From Github Load Final
Load past
Repo collect Df for ML
Data
the tweets
Load
Load Libraries Fundamental
past Data
Data Cleaning

What does it mean for B2B businesses when a tech giant like IBM acquires
RedHat The Cloud is about to be a whole lot more important in 2019 and
beyond.
Metrics Results
1.Positive Sentiment:
compound score >= 0.05 aggDfDay.tail()

2.Neutral Sentiment:
(compound score >- 0.05)
& (compound score < 0.05)

3.Negative Sentiment:
compound score <=- 0.05
Data Processing
Data Preparation
Correlation between the Target Variable and the Features
Correlation between
the target variable
and the features:
near zero

● Historical data

● Investors’
expectations

● Unexpected
events

● Nonlinear
relationship
Machine
Learning
Cyl > 5

Decision Tree True False

● Prone to Overfitting HP >= 192 27 mpg

● R Squared of Training Set: 0.99 True False


● R Squared of Test Set: -0.75
13 mpg 18 mpg
Decision Tree - Cross Validation
How easy is to Overfit a Model?
3 Lines of Code!

How easy is to lose all your money in the stock


market!
Random Forest - Why?

Reduces noise

Less Prone to overfit

Feature Selection
Random Forest - Feature Selection
Model For Backtesting
The hugely overfit Decision Tree will be used as predictor of returns.

In order to answer the following questions:

How will the overfitting affect the backtest?

We will be able to identify it?


Backtesting
Strategy 2: Adding Limit Deltas
Why?

Purpose is to limited the change in portfolio not more than 10% per day by using
bt.algos.LimitDeltas()

+10% max

Day t Value

-10%max
Strategy 3: Adding Limit Deltas & 1 Day Lag
Why?

Because there is no way that we can know the closing price before the market
close.
Predicted Return
How?
2014-01-01

By shifting the return for 1 day 2014-01-02 1.5%

2014-01-03 0.3%

2014-01-04 -0.8%

2014-01-05 -1.3%
Comparison of Strategies

Base Limit Limit Deltas


Strategy Deltas & 1 day lag

Total
-46.58% -8.62% -1.46%
Return

Sharpe
-1.04 -0.54 -0.22
Ratio

Sortino
-1.10 -0.64 -0.31
Ratio

CAGR -57.34% -11.44% -1.96%

Max
-49.75% -19.11% -7.05%
Drawdown
Conclusion
Machine Learning
● Overfitting: Discrepancy between ML model and Backtesting
● Difference based on the period of training data: ex) ‘2005 – 2007’ vs ‘2008 – 2010’
Algorithmic Trading
● Accuracy of the measurement of sentiment effect
● Appropriateness of the choice and number of factors
● Trading effect on the market: capital size of the model
● Unexpected external events: market regime, competitors, market
● Vulnerable to lose big & fast

Backtesting
● Biases - Look ahead, Data Snooping, Shorting
“Lose big & fast” But, could beat human traders!
Authors

- Diego Giménez - Yoonhee Bae

- Piya Thavornwong - Myungsung Kim

- Jorge Betancourt - Xuan Lu

AUTHORS:

You might also like