... cvxpy two: returns


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 here 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()

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider signing up for the newsletter.