hi -
i need input from the guys who designed the class crypto trading strategies: advanced. this question relates to section 1.7, specifically the Movement and Returns calculation.
If you look at the df1 table you see Movement and Return values are off by one period. For example, at 13:51:00 on 2018:07:27 movement is 0.000434 and return is 0.000022. then at the next period movement is 0.000022.
but the calculations are the same; movement is just the abs value of return. so these rows look off to me.
can you explain this?
thanks - russell
Hi Russell,
The Movement column is basically the past (previous minute's) volatility of the market, that is why we use the shift(1) in the code, and that is the reason why its numerical value is the same as that of the percentage returns column. Both these columns represent returns, but one is past returns while the other is current. And since we are interested in creating two clusters based only on volatility and not the direction, we use the absolute value of these past percentage returns as an input to the clustering model. Hope this helps.
thanks for the reply. so are you saying the return is from the current minute and the SMA and movement are from the previous minute? if so, why would you not include the current minute’s price in the SMA and movement calculation?
perhaps you can see what’s off with my replication of the code? import numpy as np import matplotlib.pyplot as plt import pandas as pd #import talib as ta from sklearn.cluster import KMeans df1=pd.read_csv(“1min_ETHUSDT-Upload.csv”).iloc[-100000:] # Set the timestamp to be the index for the data df1=df1.set_index(‘Timestamp’) #convert UNIX time stamp to datetime df1.index=pd.to_datetime(df1.index, unit=‘ms’) # Let us visualize the data to confirm if it really was trending for the given time
oops that didn’t format.
#Compute SMA, movement and market return df1[‘SMA’]=df1.Close.rolling(window=30).mean() df1[‘Movement’]=df1.Close.pct_change().abs() df1[‘Return’]=df1.Close.pct_change()
#Compute SMA, movement and market return df1[‘SMA’]=df1.Close.rolling(window=30).mean() df1[‘Movement’]=df1.Close.pct_change().abs() df1[‘Return’]=df1.Close.pct_change()
Hi Russel, yes you can include the current minute’s price in the SMA and movement calculation,. But then you will have to shift your ‘Return’ one step ahead. Change your Return code to the following: df1[‘Return’]=df1.Close.pct_change().shift(-1) Hope this helps.