Calmcode - cvxpy two: returns

Returns

1 2 3 4 5 6 7 8

Before starting, make sure you've installed the dependencies;

pip install pandas cvxpy matplotlib jupyterlab

If you prefer to use the same dataset to follow along you can download it directly or you can fetch it via;

wget https://calmcode.io/datasets/stocks.csv

Given all these preparations, you can use the following code to make the same visual;

import cvxpy as cp
import pandas as pd
df_stocks = pd.read_csv("stocks.csv").iloc[500:1800]
df_stocks.set_index('Date').plot(figsize=(12, 4));

To make the first order differences you need to run;

df_returns = df_stocks.set_index('Date').diff()
df_returns.mean()
df_returns.std()