Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...
Join 11,500+ Quant Scientists learning one article at a time
Join 11,500+ Quant Scientists learning one article at a time
Matt and I talk a lot about "responsible" algorithmic trading.
What do we mean by that?
Well our goal is to build profitable algorithmic trading strategies.
And keep the profits!
That's why we focus on risk so much. It's hard enough to build profitable strategies, but giving away the profits?
Ouch.
In today's issue of the QS Newsletter (get the code), we are going to build a simple risk metric we use all the time. It's called downside deviation.
What You’ll Learn:
Download historical stock price data and compute the mean return
Use NumPy to build a function to compute downside deviation
Compare it to standard deviation (which is normally used)
BONUS: Get the Python Code for EVERYTHING you see in this post
Disclaimer:
The information and educational material provided by Quant Science, LLC are for educational purposes only and should not be considered as financial advice or recommendations to purchase, hold, or sell any securities or other financial instruments. Before you proceed, please review our full disclaimer here.
Want exclusive access to our FULL codebase for this Quant Science tutorial plus dozens more?
Join thousands of aspiring Python quants here 👉
Since you're here, you probably want to learn how to get started developing (profitable) algorithmic trading strategies and reinvest those profits.
Here are the steps:
Find edge
Analyze risk
Backtest trading strategies
Execute trades automatically
Easy right? Well, not exactly... Avoid the 5 biggest mistakes beginners make with our free, 5-day email course:
Click here to join our free 5-Day Algorithmic Trading Course 👉
Now on to the show...
Portfolio risk is the potential for financial loss and uncertainty about its extent. Downside deviation is a common measure of financial risk that measures the volatility of negative returns.
This measure gives a more accurate picture of the type of risk traders care about:
The risk of losing money.
Since volatility to the upside is not usually a concern, downside risk is used by traders to gauge the risks that lead to portfolio drawdown—a key worry.
All we need is NumPy and yFinance.
The calculation for downside deviation is straightforward.
Instead of using pandas methods (returns is a pandas Series), you’ll see how to use NumPy to concisely make the calculation.
The function first creates an empty array the same size as the returns input (less one to remove the NaNs).
Then we use the clip method to grab all the returns between negative infinity and 0.
From there, we square the returns, take the mean value, apply the square root, then annualize by multiplying by the square root of 252.
Let's compare downside deviation with it's cousin, standard deviation.
When comparing the downside deviation to the standard deviation of returns, it will be different. In the case of this example (at the time of writing) it’s 33% lower!
That’s because AAPL has been rallying over the time period. If you repeat the analysis for a trading portfolio or asset that has not been on a steady incline, your results will be different.
You just took the first step in responsible algorithmic trading by learning a simple but effective risk metric—downside deviation.
But, there's more to learn in algorithmic trading:
Backtesting your portfolio construction algorithm to make sure the strategy will work in the future
Executing the trades automatically
Monthly rebalancing
Tracking your actual Profit and Loss
Incorporating Trading Fees
Are you interested in learning algorithmic trading strategies that maximize returns responsibly, help you manage risk, and grow your investments?
We implement 3 core trading strategies including portfolio, momentum, and spread trades that have worked in our favor in the past and continue to produce results for our students.
Join 400+ of us that are learning to apply python to algorithmic trading to grow investments.
Leo was up 11.5% in just 13 trading days.
Alex was waiting 9 years for a course like this:
There's nothing worse than going at this alone--
❌ Learning Python is tough.
❌ Learning Trading is tough.
❌ Learning Math & Stats is tough.
It's no wonder why it's easy to feel lost, make bad decisions, and lose money.
Want help?
👉 Join 10,700+ future Quant Scientists on our Python for Algorithmic Trading Course Waitlist: https://learn.quantscience.io/python-algorithmic-trading-course-waitlist
Gain access to exclusive tools that Wall Street's Elite don't want you to have. Don't miss the next issue...
Join 11,500+ Quant Scientists learning one article at a time
Join 11,500+ Quant Scientists learning one article at a time