I am looking for a way to make the following code work:
import pandas
path = 'data_prices.csv'
data = pandas.read_csv(path, sep=';')
data = data.sort_values(by=['TICKER', 'DATE'], ascending=[True, False])
data.columns
I have a 2 dimensional array with three columns, the data looks like this:
DATE;TICKER;PRICE
20151231;A UN Equity;41.81
20151230;A UN Equity;42.17
20151229;A UN Equity;42.36
20151228;A UN Equity;41.78
20151224;A UN Equity;42.14
20151223;A UN Equity;41.77
20151222;A UN Equity;41.22
20151221;A UN Equity;40.83
20151218;A UN Equity;40.1
20091120;PCG UN Equity;42.1
20091119;PCG UN Equity;41.53
20091118;PCG UN Equity;41.86
20091117;PCG UN Equity;42.23
20091116;PCG UN Equity;42.6
20091113;PCG UN Equity;41.93
20091112;PCG UN Equity;41.6
20091111;PCG UN Equity;42.01
Now, I want to calculate the x-day realized volatility where x came from an input field and x should not be bigger than the number of observations.
The steps that need to be taken:
- Calculate the log return for each line
- Take those returns and run the standard deviation on top of it
- Multiply by the square root of 255 to normalize for per annum volatility