Following $100k Optiver Realized Volatility Prediction Competition on Kaggle, interest in financial time-series and concepts has drastically increased. Besides, in this website we have not travelled past the very introductory concepts in time-series ecnnometrics. Therefore in this blog post we are going to introduce the concepts of simple returns, log returns and realized volatility.
In the following article we have already explored time-series and simple operations in pandas and numpy.
To illustrate the log returns and more complex concepts we are going to demonstrate them with the help of python and pandas and numpy libraries.
Simple returns vs log returns
To begin with, benefit of using financial returns instead of prices is normalization which allows us to measure and compare all financial instruments and assets. This is also a requirement for many multidimensional statistical analysis and machine learning techniques.
The simple return on an asset is the amount we receive or lose after holding an asset for a certain time frame.
Meanwhile we calculate log returns as
where P is price of an asset and t is a time period.
In pandas we calculate the simple returns with an in-built pandas function
pct_change that calculates percentage change and use numpy
log to calculate log returns in addition to pandas
diff that differences the series.
data['simple_returns'] = data.close.pct_change() def log_return(list_stock_prices): return np.log(list_stock_prices).diff() data['log_return'] = log_return(data.close)
The main advantage of log returns is that we can easily aggregate them across time unlike simple returns. For instance, the log return for a year is the sum of the log returns of the days within the year. Additionally, log returns are symmetric around 0 and log return values can range from minus infinity to plus infinity. Whereas, simple returns’ downside is limited at -100% and a negative movement of -25% (movement from 100$ to 75$) does not reverse the losses by going +25% (75$ to 93.75$).
Volatility plays an important role in trading and financial model forecasting. Next to directly modeling high–frequency returns, intra–day returns are also used to construct lower–frequency daily volatility measures, known as realized volatility. The application of volatility has tremendously risen due to the availability of high-frequency data and computational resources.
Layman’s definition: Realized volatility is the magnitude of daily price movements, regardless of direction, of some underlying, over a specific period.
Technical definition: Realized volatility is the daily standard deviation of log returns of an underlying asset, index, instrument, security, or ETF, over a defined period, with an assumed mean of zero.https://www.realvol.com/Realizedvolatilitydefinition.htm
Traders and data scientist use realized volatility to assess the predictive performance and adequacy of existing models and strategies due to our ability to observe the metric (non-latent character). Realized volatility is a particularly powerful indicator of the price risk and its dynamics.
The formula for realized volatility:
In Python we create a function that calculates realized volatility with the help of numpy functions
sum and pandas
def realized_volatility(series): return np.sqrt(np.sum(series**2)) df.groupby(df.index.date).agg(realized_volatility)
Andersen and Bollerslev (1998) have suggested an ex-post intra-daily volatility measure based on the sum of the squared intra-day returns. This concept is now known as realized variance, and this is an ex-post observable measure.
def realized_variance(series): return np.sum(series**2) df.groupby(df.index.date).agg(realized_variance)
- Andersen, T. and Bollerslev, T., 1998. Deutsche Mark-Dollar Volatility: Intraday Activity Patterns, Macroeconomic Announcements, and Longer Run Dependencies. The Journal of Finance, 53(1), pp.219-265.
- Kaggle notebok: https://www.kaggle.com/pavfedotov/time-series-analysis-nifty50-stationarity-adf/edit/run/69210765
- Blockchain Data Indexer with TrueBlocks
- Great blockchain insights with PARSIQ triggers for AXS
- Generating Fast and Easy PARSIQ triggers for CryptoPunks
- Simple App with Ceramic Data Model and Unstoppable Domains
- Simple QR code generator on AWS with Flask
You can contact me for professional inquires via my social media: