# Logarithmic Returns – Why are they used in algorithmic trading?

### A brief research note on logarithmic returns. Should we be using them?

Disclaimer: the following post is an organized representation of my research and project notes. It doesn’t represent any type of advice, financial or otherwise. Its purpose is to be informative and educational. Backtest results are based on historical data, not real-time data. There is no guarantee that these hypothetical results will continue in the future. Day trading is extremely risky, and I do not suggest running any of these strategies live.

Logarithmic returns, also known as log returns, are a vital concept in financial analysis and algorithmic trading. They provide a robust way to measure and compare financial returns, factoring in the compounding effects and handling price series data effectively in both theoretical finance and practical investment scenarios. This article delves into the intricacies of logarithmic returns, highlighting their advantages and disadvantages in the context of algorithmic trading and backtesting strategies.

## What Are Logarithmic Returns?

Logarithmic returns are calculated using the natural logarithm of the ratio of successive prices. The formula is given by:

Where:

*P*is the price at time_{t}*t**P*_{t}_{ − 1}is the price at time*t*− 1*ln*denotes the natural logarithm

This approach to calculating returns has several distinct characteristics and benefits.

## Advantages of Using Logarithmic Returns

**Time Additivity**: Logarithmic returns over multiple periods can be summed to get the total return, simplifying the analysis over different time frames. This property is particularly useful in portfolio management and risk assessment.**Normality**: Logarithmic returns are often more normally distributed than simple arithmetic returns, which facilitates statistical analysis and the application of various financial models that assume normality.**Handling Volatility**: They can handle high volatility periods better due to their symmetrical nature, making them suitable for assets with significant price swings.**Compounding**: Logarithmic returns naturally account for compounding, providing a more accurate reflection of the cumulative return over time compared to arithmetic returns.

## Disadvantages of Using Logarithmic Returns

**Interpretation Complexity**: Logarithmic returns can be less intuitive to interpret compared to simple returns. Investors and traders may find it challenging to relate log returns to actual percentage changes in asset prices.**Negative Prices**: The calculation of logarithmic returns assumes that prices are always positive, which can be a limitation in certain financial contexts.**Approximation for Small Changes**: For small price changes, logarithmic returns approximate arithmetic returns. However, for large price changes, the difference between the two can be substantial, potentially leading to misinterpretation.

## Application in Algorithmic Trading and Backtesting

In algorithmic trading, logarithmic returns are invaluable for backtesting strategies. They provide a consistent method to measure performance and risk across different time frames and market conditions. By utilizing log returns, traders can:

**Develop Robust Models**: Ensure their trading models are statistically sound and account for the compounding effects of returns.**Perform Risk Analysis**: Better assess the risk and volatility of their strategies, leading to more informed decision-making.**Enhance Strategy Comparison**: Compare the performance of different strategies more effectively, given the time additivity property of log returns.

### Practical Calculation

To calculate logarithmic returns in a practical setting, you typically work with financial time series data. Using Python, for example, you can compute log returns as follows:

```
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Assuming `target` is your DataFrame and it has a 'Close' column
# Example:
# target = pd.DataFrame({
# 'close': [100, 102, 101, 105, 107]
# })
# Calculate the logarithmic returns
target['Log_Returns'] = np.log(target['close'] / target['close'].shift(1))
# Display the DataFrame with the new 'Log_Returns' column
print(target)
# Plotting the logarithmic returns
plt.figure(figsize=(10, 6))
plt.plot(target.index, target['Log_Returns'], marker='', linestyle='-', color='b')
plt.title('Logarithmic Returns')
plt.xlabel('Date')
plt.ylabel('Log Returns')
plt.grid(True)
plt.show()
```

## Summary

Logarithmic returns offer a powerful tool for financial analysis and algorithmic trading, providing numerous advantages in handling returns data. However, they also come with certain complexities and limitations. Understanding these can help traders and investors make more informed decisions, leveraging the strengths of log returns while mitigating their drawbacks.

So, should we be using log returns when testing trade strategies?

Probably.

Happy hunting!

The code for strategies and the custom functions/framework I use for strategy development in Python and NinjaScript can be found at the Hunt Gather Trade GitHub. This code repository will house all code related to articles and strategy development. If there are any paid subscribers without access, please contact me via e-mail. I do my best to invite members quickly after they subscribe. That being said, please try and make sure the e-mail you use with Substack is the e-mail associated with GitHub. It is difficult to track members otherwise.

Feel free to comment below or e-mail me if you need help with anything, wish to criticize, or have thoughts on improvements. Paid subscribers can access this code and more at the private HGT GitHub repo. As always, this newsletter represents refined versions of my research notes. That means these notes are plastic. There could be mistakes or better ways to accomplish what I am trying to do. Nothing is perfect, and I always look for ways to improve my techniques.

Achieving a deep understanding of what expected value really is is the pending task of many professional managers. Deep concepts are not easy.