Algorithmic Trading in Python
Algorithmic Trading in Python
Algorithmic Trading in Python
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
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
Reduces noise
Feature Selection
Random Forest - Feature Selection
Model For Backtesting
The hugely overfit Decision Tree will be used as predictor of returns.
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
2014-01-03 0.3%
2014-01-04 -0.8%
2014-01-05 -1.3%
Comparison of Strategies
Total
-46.58% -8.62% -1.46%
Return
Sharpe
-1.04 -0.54 -0.22
Ratio
Sortino
-1.10 -0.64 -0.31
Ratio
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
AUTHORS: