np.array([Finance, Python, Streamlit, Cloud Platform]) == http://184.108.40.206:8501/
A finance strategy (CPPI), implemented on Streamlit/Python, deployed on AWS EC2
In this article, I would like to show you how to design a CPPI (Constant proportion portfolio investment) strategy and publish it on the Internet. The result is http://220.127.116.11:8501/ (much more fun if you open the link on a big screen rather in a mobile browser)
Here are the steps.
First, let’s remember what CPPI is.
DIVERSIFICATION allows you to eliminate specific or idiosyncratic risks. It cannot help you deal with systematic risk as in 2008 crisis, when systematic risk impacted all the assets simultaneously.
HEDGING, as an alternative, helps you with systematic risks but it is purely symmetric: you get protection on the downside only if you give up on the upside proportionately. Not very attractive…
CPPI Insurance Strategy gives you downside protection but offer much more upside potential by dynamic hedging nature. It is all about allocating to a risky asset in a multiple of the difference between asset value and a given floor, and then reducing the risky allocation if/when getting close to the floor.
The code below is a step-by-step implementation of CPPI. I agree a vectorized-implement code would be more efficient but also equally hard to understand.
Below show the benefit of CPPI over fully invested in Turkish equity indices. As you can clearly see, CPPI protects the investment in large drawdowns whereas it provides quite a lot of upside.
Also, if you compare the risk parameters of two portfolios, you can clearly see how Sharpe ratio, VaR and Drawdown Ratios of CPPI portfolio show huge improvements over the risky portfolio.
Let’s also look at the performance of another index, the transportation index, with and without CPPI strategy below. Wow! Such a big protection in CPPI portfolio!
In the execution part, I implemented CPPI in nonparametric and parametric ways using several sector indices. I also included a random walk path to the assets using Geometric Brownian Motion. All parameterized!
To make the app online and web friendly, I used Streamlit library of Python (https://www.streamlit.io/) . Definitely worth checking out!
Below is a shortened code snippet with Streamlit code, but you can fork the whole code from my github account: https://github.com/deimosnphobos/cppi_strategy
Final task was to deploy it on a Cloud Application Platform. I tried Heroku: Cloud Application Platform first, but somehow I couldn’t be able to run it smoothly -sometimes it worked, sometimes not. So I switched to Amazon Elastic Compute Cloud (Amazon EC2 - Amazon AWS). It was much harder to configure than Heroku, but just did what it was supposed to do!
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the…
The result is at http://18.104.22.168:8501/. Please feel free to play with it, and let me know if you have any questions about it.