0
$\begingroup$

I have a GBPUSD Forex time series. I am preparing the series as an input to LSTM. As a best practice for LSTM I am making the series stationary and I have tried both linear returns and log returns for this:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.tsa.stattools as ts

df = pd.read_csv('gbpusd.csv', index_col=['Date'], parse_dates=['Date'],
    usecols=['Date','Close'])
df = df[df.index >= pd.to_datetime('2020-01-01')]
df['LinearReturns'] = df['Close'].pct_change() # Arithmetic Returns
df['LogReturns'] =  np.log(df['Close']/df['Close'].shift(1)) # Log Returns
df.dropna(how='any', inplace=True)

fig = plt.figure(figsize=(24, 18))
fig.subplots_adjust(hspace=0.4)
ax1, ax2, ax3, ax4, ax5 = fig.subplots(5)
ax1.set_title('Close')
ax1.set(xlabel='Date', ylabel='Close')
ax1.plot(df['Close'])
ax2.set_title('Linear Returns')
ax2.set(xlabel='Date', ylabel='Returns')
ax2.plot(df['LinearReturns'])
ax3.set_title('Linear Returns PDF')
ax3.hist(df['LinearReturns'], 159, range=[-0.0005, 0.0005])
ax3.plot()
ax4.set_title('Log Returns')
ax4.set(xlabel='Date', ylabel='Returns')
ax4.plot(df['LogReturns'])
ax5.set_title('Log Returns PDF')
ax5.hist(df['LogReturns'], 159, range=[-0.0005, 0.0005])
ax5.plot();

linear_adf = ts.adfuller(df['LinearReturns'])
log_adf = ts.adfuller(df['LogReturns'])
print(f'Linear Returns (ADF, P-Value,...): {linear_adf}')
print(f'Log Returns (ADF, P-Value,...):    {log_adf}')

These are the results:

enter image description here

Linear Returns  (ADF, P-Value,...): (-53.67346634155517, 0.0, 79, 225629, {'1%': -3.4303789828630094, '5%': -2.8615528100499765, '10%': -2.5667768183276514}, -3188386.7366126943)
Log Returns (ADF, P-Value,...):     (-53.67104323432776, 0.0, 79, 225629, {'1%': -3.4303789828630094, '5%': -2.8615528100499765, '10%': -2.5667768183276514}, -3188345.3657192886)

Augmented Dickey-Fuller shows a P-Value of 0.0 for both returns, which is a proof of stationary characteristic.

It looks like the linear and the log returns have the same magnitude. my questions:

  1. What is the difference in my case in using linear or log returns? Also, what is the difference in general and why would it matter?
  2. I read somewhere that using the log is better for when you inverse the output of the LSTM as it will reduce the prediction exploding errors. Do you have an opinion on this?
  3. Is there a better way of making this specific series (trending, no seasonality and some outliers) stationary?
$\endgroup$
5
  • 1
    $\begingroup$ Because the series obviously is not stationary and hasn't become stationary through your operations, could you explain what you mean by "making" it stationary? $\endgroup$ – whuber Aug 12 '20 at 16:15
  • $\begingroup$ @whuber I have added Augmented DF test to show that it is stationary. By making it stationary, I meant removing any trend. $\endgroup$ – Adam Aug 12 '20 at 22:47
  • 1
    $\begingroup$ That's known as "first order stationary." In a stationary series, the distributions of the responses look the same at any time--and that's obviously not the case with your series, which grows visibly more variable about a third of the way through. $\endgroup$ – whuber Aug 13 '20 at 13:04
  • $\begingroup$ @whuber The plotted returns can be realizations of a strictly stationary but conditionally heteroskedastic time series (which is reasonable in this particular case). $\endgroup$ – Michael Aug 13 '20 at 17:04
  • $\begingroup$ @whuber I am not looking for strict stationarity as Michael mentioned $\endgroup$ – Adam Aug 13 '20 at 19:17
2
$\begingroup$

What is the difference in my case in using linear or log returns? Also, what is the difference in general and why would it matter?

The log returns and arithmetic returns would be close, trivially, if the returns are close to zero. FX returns for major currency pairs can be measured in basis points (percent of a percent)---empirically, this is very close to zero. (A 4 basis point move would be a huge move for this pair). As a result, the difference between these two quantities are negligible. This can be seen already in the time series and histogram plots you provide. (Incidentally, exchange rates between majors are also quoted in increments of 0.0001, except the yen.)

I read somewhere that using the log is better for when you inverse the output of the LSTM as it will reduce the prediction exploding errors. Do you have an opinion on this?

If the inputs series are close, one would expect the outputs to be also close.

Is there a better way of making this specific series (trending, no seasonality and some outliers) stationary?

For price series in general, computing returns is about the only standard thing to do if your method requires stationarity. Note that information regarding levels is lost when one computes the return series.

As a comment, FX series may not be the best playground for RNN-type methods. Those spikes in the return series are easily identifiable, and explained, by major economic events. Similarly, in a higher frequency exchange rate series with intra-day data, you would see clustering around the London 4pm fix, for example.

$\endgroup$
2
  • $\begingroup$ thank you, what do you mean by 'levels'? You can reconstruct the time-series after the prediction (knowing the last price). $\endgroup$ – Adam Aug 14 '20 at 14:48
  • $\begingroup$ @Adam Just the initial series of price/exchange rate levels. One wouldn't be able to address issues such as, for example, cointegration using the return/first-differenced series $\endgroup$ – Michael Aug 14 '20 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.