Master Thesis, 30 credits
PREDICTION OF CURRENCY PAIRS
Statistical relations between futures and forward contracts
Anna Aronsson and Elsa Kjellén
Copywrite © 2021 Anna Aronsson and Elsa Kjell´en All rights reserved
PREDICTION OF CURRENCY PAIRS,
STATISTICAL RELATIONS BETWEEN FUTURES AND FORWARD CON- TRACTS
Submitted in fulfilment of the requirements for the degree Master of Science in Industrial Engineering and Management
Department of Mathematics and Mathematical Statistics Ume˚a University
SE - 907 87 Ume˚a, Sweden
Abstract
Forecasting prices is a widely extended topic on the financial mar- kets and is used by traders all over the world to make profitable trades. However, there exists limited amount of research regarding the relation between the price movements of futures and forward contracts. In this thesis work that relation has been investigated in order to see if it is possible to increase the efficiency of the pric- ing for two different currency pairs that are traded on the forex exchange market. The aim was to develop a statistical model that could find statistical relations so that an improvement in the pre- dictions was seen. Throughout the project two different models were tested to find this relation, using time series data that in- cluded the trade dates, prices and delivery dates for the contracts.
The Random Forest algorithm performed best in this study with a prediction that generated low mean squared errors, and high out- of-bag scores. Even though the algorithm performed quite well, none of the results found, provided evidence of a useful statistical relation between futures and forward contracts.
Sammanfattning
Prediktion av priser ¨ar ett v¨al unders¨okt omr˚ade p˚a de finansiella marknaderna. Det finns dock en begr¨ansad m¨angd forskning p˚a f¨orh˚allandet mellan tv˚a olika terminskontrakt. I detta examensar- bete har denna relation unders¨okts f¨or att se om det ¨ar m¨ojligt att
¨
oka effektiviteten i priss¨attningen f¨or tv˚a olika valutapar som hand- las p˚a valutamarknaden. M˚alet var att utveckla en statistisk mod- ell som kunde hitta statistiska relationer s˚a att en f¨orb¨attring av prediktioner s˚ags. Under projektets g˚ang testades tv˚a olika mod- eller f¨or att hitta denna relation med hj¨alp av tidsseriedata som inkluderade handelsdatum, priser och leveransdatum f¨or kontrak- ten. Random Forest-algoritmen fungerade b¨ast i denna studie med en f¨oruts¨agelse som genererade l˚aga mean squared errors och h¨oga out-of-bag scores. Trots att algoritmen fungerade ganska bra gav inget av de hittade resultaten bevis f¨or en anv¨andbar statistisk re- lation mellan terminskontrakten.
.
PREDIKTION AV VALUTAPAR,
STATISTISKA F ¨ORH˚ALLANDEN MELLAN TERMINSKONTRAKT
Acknowledgments
First of all, we would like to thank our supervisors at Swedbank FX Trading, Pauline Ingvarsson and P¨ar Hellstr¨om for their sup- port throughout this thesis work, always providing good feedback and creative solutions. We would also like to thank Jianfeng Wang for his positive feedback and great insight in the project throughout the entire semester. We are also very grateful to Markus ˚Adahl for his thoughts and efforts. Your statistical and risk oriented compe- tence helped us moving forward in the right direction. Lastly, we would like to acknowledge M˚ans Karlsson for his feedback, helpful suggestions and ideas when they were needed.
Contents
1 Introduction 1
1.1 Company Description . . . 1
1.2 Background . . . 1
1.3 Aim . . . 2
1.4 Formulation of the Problem . . . 2
1.5 Project Scope . . . 2
1.5.1 Confidentiality . . . 2
1.5.2 Limitations . . . 3
1.6 Thesis Disposition . . . 3
2 Theory 4 2.1 Important Terminologies on the FX Market . . . 4
2.1.1 Currency Pairs . . . 4
2.1.2 Over-The-Counter and Marked-To-Market . . . 4
2.1.3 Bid-Ask Spread . . . 4
2.1.4 Market Transparency . . . 5
2.2 Futures and Forward Contracts . . . 5
2.2.1 Futures Contract . . . 5
2.2.2 Forward Contract . . . 5
2.2.3 Duration and Expiration of Contracts . . . 6
2.3 Vector Autoregression . . . 6
2.3.1 Granger Causality . . . 7
2.3.2 Types of Stationarity . . . 7
2.3.3 Augmented Dickey Fuller Test . . . 8
2.3.4 Kwiatkowski-Phillips-Schmidt-Shin Test . . . 8
2.4 Random Forest . . . 9
2.4.1 Decision Tree . . . 9
2.4.2 Bagging . . . 9
2.4.3 Out-of-Bag Score . . . 10
4 Method 14
4.1 Pre-Processing Data . . . 14
4.1.1 Processing Futures Contract Data . . . 14
4.1.2 Processing Forward Contract Data . . . 15
4.2 Data Setup . . . 16
4.2.1 Inverse Distance Weighted Interpolation . . . 16
4.2.2 Stationary Time Series . . . 17
4.3 Modelling VAR . . . 17
4.3.1 VAR-model with Two Currency Pairs . . . 19
4.4 Modelling Random Forest . . . 21
5 Result 23 5.1 Results Vector Autoregression . . . 23
5.1.1 VAR-model including both currency pairs . . . 29
5.2 Results Random Forest . . . 34
5.2.1 Predictions made without the response in t−1 as predictor 34 5.2.2 Predictions made including the response in t − 1 as pre- dictor . . . 41
6 Discussion 50 7 Conclusions 52 References 54 Appendix 55 A.1 VAR-Model with Two Currency Pairs . . . 59
A.2 Random Forest Prediction, Opposite Contract as Predictor . . . 61
A.3 Feature Importance, Opposite Contract as Predictor . . . 65
A.4 Random Forest Prediction, Both Contracts as Predictors . . . 67
A.5 Feature Importance, Both Contracts as Predictors . . . 70
1 Introduction
The introduction outlines the company description and the background to the project. It describes the aim for the thesis work and further the problem formulation, limitations and recommendations to the reader regarding dispo- sition.
1.1 Company Description
Swedbank was founded in 1820 and their first office were positioned in Gothen- burg and enabled ordinary people to deposit and withdraw money at any time.
Today, Swedbank is one of the largest fullservice banks in Sweden and has over seven million customers worldwide with domestic markets in Sweden, Estonia, Latvia and Lithuania. It is coordinated as three main business areas, Swedish Banking, Baltic Banking, and Large Corporations and Institutions (LC&I).
The largest business area is Swedish Banking, which accounts for more than half of the overall profit and is the largest private bank in Sweden. Nearly one fifth of the operational profit is from the Baltic Banking. Their LC&I branch offers Trade Finance and other services to institutions, banks and corporations.
The Trade Finance unit operates with the purpose of minimizing the risk of import and export, where the transaction requires both a seller and buyer of different types of goods (Swedbank, n.d.).
1.2 Background
During the last couple of decades, technology has had a huge impact on finan- cial markets. In trading, it is of high importance to be quick at adapting to new information, to enable making arbitrage. Algorithmic trading describes the phenomenon where trading is done automatically, instantly, when a couple of predetermined conditions are met. Over 30% of the trading made in the US is done with the help of algorithmic trading technology. These algorithms are based on statistical models and financial mathematics (Kolm and Maclin,
System and Trade Finance, Swedbank provides solutions for businesses on the international market to make payments and deliveries. In currency trading, the margins are usually small. However, companies need to secure their cash flow preventing big losses due to fluctuations in the currency market.
The thesis project is centered around the trading of currency pairs in the futures and forwards market. With the use of statistical and financial tools, one wants to investigate if there are any statistical relations between the futures and forward FX markets that can be used to make profitable decisions when trading. Data of the currency pairs Japanese Yen (JPY)/US Dollars (USD) and Euros (EUR)/USD is used in this study.
1.3 Aim
The aim for this project is to investigate whether information in the futures market is valuable for predicting movements in the forward market, and vice versa. If so, the information in one of the two markets would be very useful for trading in the other, giving Swedbanks FX trading a competitive advantage.
One has succeeded in all cases where the results point in the direction whether if one instruments data is useful or not for predicting the other instrument.
1.4 Formulation of the Problem
With the aim established, the following formulation of the problem is given:
• Is it possible with help of futures contracts to predict the movement of forward contracts, and vice versa, so that it can generate more efficient pricing and statistical arbitrage when pricing currency pairs?
1.5 Project Scope
1.5.1 Confidentiality
The confidentiality in this thesis work regards trading data and the company’s business. The students have signed a confidentiality agreement and all infor- mation and results presented in the report is approved by the company before being published.
1.5.2 Limitations
Due to the projects scope being large there are some limitations to this project, they are as following:
• Data that the thesis project is based on will be from a limited time period, being from November 2nd - December 1st 2020.
• The thesis work will be investigating two currency pairs, JPYUSD and EURUSD.
1.6 Thesis Disposition
This report includes 8 sections where the thesis project is thorough explained.
Section 1 gives an insight in the background for the project and clarifies the aim, Section 2 describes theory necessary for the thesis work. Section 3 de- scribes the data sets relevant for this project and further, in Section 4, an explanation for the work methodology and tools that are used is conferred. In Section 5 the results discovered are presented objectively and factual. Section 6 includes an examination of the results and discussion regarding accuracy, if the aim is reached and potential further development. The 7th Section covers the conclusions that can be drawn from the thesis project.
2 Theory
The theory in this project is important since the project involves a lot of lit- erature studies within the area of foreign exchange trading, different contracts and markets, technology developments and statistical results. The following sections regarding financial instruments, terms and markets will give further insight in the theory of this project.
2.1 Important Terminologies on the FX Market
2.1.1 Currency Pairs
Currencies are traded on the FX market, two currencies traded make a cur- rency pair. The currency being bought is referred to as the base currency, while the currency being used to pay with is called quoted currency. An ex- ample could be buying EUR and paying with USD, creating the currency pair EURUSD (Weithers, 2006, p.2-18).
2.1.2 Over-The-Counter and Marked-To-Market
Participants at the FX market can trade Over-the-counter (OTC) which means that the buyers and sellers negotiate deals with each other and settle on a price in private. Trades can also be Marked-To-Market (MTM), meaning that the prices of the contracts are listed on a market and trading is done without any negotiation (Weithers, 2006, p.35-36).
2.1.3 Bid-Ask Spread
The Bid-Ask Spread is explained as the difference between the bid and ask prices
Bid-Ask Spread = Bid Price − Ask Price.
It is the cost for instantaneously buying and selling a security. The spread usually increases during times of ambiguity and high volatility. Given this, the security needs to have a larger gain to cover the spread and transaction cost of the trade. The spread is not uniform throughout the day, it fluctuates and usually increases when different trading sessions overlap. The bid and ask price is determined by the financial institutions themselves and it is important for them to be as accurate as possible to be able to compete on the market
(Aldridge, 2010, p.118-120).
For example, if the bid price for a EURUSD transaction is 1.2520, and the ask price is 1.2521. Then the spread is 0.0001, also known as one pip, which is the fourth decimal point.
2.1.4 Market Transparency
Market transparency is the measurement of information available for partici- pants. Pre-trade transparency often refers to the information available about prices and current market trend of buying and selling. Post trade transparency refers to the information available about previous trades, such as the price and order size and what party that were involved (Kolm and Maclin, 2010, p.21- 27).
2.2 Futures and Forward Contracts
The instruments relevant in this thesis are futures and forward contracts.
These two are financial derivatives that allow investors to speculate.
2.2.1 Futures Contract
A future contract is described as an agreement to either buy or sell a security or asset, at a predetermined price, at a specified time in the future. Futures contracts are standardized and used by speculators and hedgers, and the par- ticipants are not known for each other. The purpose for this is to prevent losses due to price changes and this is done by hedging the price movement. The contract obligates the parties to make the transaction at the arranged price, no matter what the current market price looks like (CME Group, 2021).
2.2.2 Forward Contract
2.2.3 Duration and Expiration of Contracts
A forward contract with a duration of one month expires in 30 days from the contract being traded, with the exception of the expiration date landing on a bank holiday. Futures contracts however, always expire on the third Wednesday of either March, June, September or December, independent of purchase date (Brooks et al, 2001, p.35).
2.3 Vector Autoregression
The aim of this thesis is to investigate relations between the two time series, F uturest and F orwardt. Vector Autoregression (VAR) is a tool for under- standing how different time series relate to each other and is used in this thesis. In order to understand Vector Autoregression, the basic concepts of time series are needed.
A time series refers to observations, equally spaced out in time, during spe- cific time periods. Time series analysis is a statistical tool for handling time series data (Prado and West, 2010, p.1). Important concepts for the time se- ries analysis are autocorrelation, seasonality and stationarity. Autocorrelation is described as the similarity between observations as a function of the time lag between them (Aldridge, 2010, p.95-96). Seasonality means that periods of fluctuation can be found in the data that identifies increases and decreases that repeat with the same number of, for example minutes, days or years. Weak stationarity means that the covariance is sovereign of time and the mean and variance are constant. Thereby, the statistical properties do not change de- pending on time (Aldridge, 2010, p.98).
In a VAR-model, each time series is expressed as a linear combination of its own previous observations, as well as the previous observations of the other time series present in the model. Let one assume there are two stationary time series, F uturest and F orwardt. In a VAR-model, these two time series could be expressed as following,
F uturest = β10 + β11F uturest−1 + · · · + β1pF uturest−p + γ11F orwardt−1 +
· · · + γ1pF orwardt−p+ 1t
F orwardt = β20 + β21F uturest−1+ · · · + β2pF uturest−p + γ21F orwardt−1 +
where F uturest−1represents the first lag of time series F uturest ,F orwardt−1 the first lag of time series F orwardt. β and γ are coefficients estimated by or- dinary least square for each series and vector of independent and identically distributed error terms with mean zero.
If at any time lag t in a time series, the coefficient of the lagged term has a low p-value, that term is statistically significant for predicting the time se- ries (Hanck et al, 2020, Vector Autoregressions, paragraph 1).
2.3.1 Granger Causality
In order to understand the causality between futures and forward contracts the Granger Causality test is introduced. The Granger Causality test uses a VAR-model when testing if one time series is significant for predicting another.
The hypothesis of the test are the following:
H0: Time series F uturest does not Granger cause F orwardt, or vice versa H1: Time series F uturest does Granger cause F orwardt, or vice versa
If H0 can be rejected then F uturest is said to Granger cause F orwardt (or vice versa) and F uturest is said to be statistically significant for predicting F orwardt The test is made under the assumption that all time series in the model are stationary (L¨utkepohl, 2005, p.41-43).
2.3.2 Types of Stationarity
There are different types of stationarity.
• Weak stationarity refers to when the expected value of a time series is independent of time and the covariance function is independent of time but dependent on timehorizon (Brockwell and Davis, 2016, p.13).
2.3.3 Augmented Dickey Fuller Test
Augmented Dickey Fuller Test (ADF) determines whether a time series is dif- ference stationary by testing if the series has a unit root. The hypothesis for ADF-test are
H0: There is a unit root present for the time series, H1: There is no unit root present for the time series.
If H0 is rejected, the series is assumed to be difference stationary (Singh,2018).
2.3.4 Kwiatkowski-Phillips-Schmidt-Shin Test
The Kwiatkowski-Phillips-Schmidt-Shin (KKPS) test also uses unit roots to determine trend stationary of a time series. The hypothesis of the test follows H0: The series is trend stationary,
H1: A unit root implying non-stationarity can be found.
If H0 can not be rejected, the series is assumed to be trend stationary (Singh, 2018).
2.4 Random Forest
In bagging, decision trees are made using bootstrap samples. These trees can be highly correlated if similar sets of predictors are used for multiple trees. In random forest, this problem is solved by only allowing a random sample of m predictors, m ≈ √
p to be used in each split, making the trees less correlated (James et al, 2013, p.318-319).
2.4.1 Decision Tree
Decision trees are a supervised learning tool used for prediction. From training on historical data (supervised learning), decision trees identify a set of decision rules for the features of the data set, that best split up the data in such way that the prediction error is minimized. Decision trees can be used for both classification and regression. In this report, regression trees are used.
A regression tree uses a greedy algorithm called recursive binary splitting for splitting the predictor space, containing all possible values for the predictors X1, X2..Xp, into regions. The recursive binary splitting algorithm starts out with all observations from the training set in one region (the root of the tree).
It then splits this region into two smaller regions (creating two branches).
When the leafs (the terminal nodes) of the tree have less than a predeter- mined number of observations, the splitting stops. The algorithm is greedy, meaning that for each step it will make the split resulting in the lowest residual sum of squares (RSS) for that step. The formula to calculate RSS is presented in Equation (1).
RSS =
J
X
j=1
X
i∈Rj
yi− ˆyRj2
(1) where ˆyRj is the j:th regions mean response from the training data (James et al, 2013, p.303-309).
variance of the set can be reduced by dividing the data set into B number of small training sets, make a prediction model (such as a regression tree) for each small training set and then take the average of the resulting predictions. The formula for calculating the average of the resulting predictions is presented in Equation (2)
fˆavg(x) = 1 B
B
X
b=1
fˆb(x). (2)
However, since one usually only has one training set, one can use bootstrap, taking repeated samples of the training data to generate B bootstrapped train- ing sets and train the prediction method on each of those sets. Then take the average of predictions, the calculation for this is shown in Equation (3)
fˆbag(x) = 1 B
B
X
b=1
fˆ∗b(x). (3)
Bagging is very useful for decision trees that by themselves are prone to over- fitting (James et al, 2013, p.316-317).
2.4.3 Out-of-Bag Score
When using bagging models, each bootstrapped training sample usually in- cludes around two thirds of the training data, leaving one third of the training data as ”out of the bag” (OOB). The mean prediction error of the out-of-bag samples is called out-of-bag error. The out-of-bag score, is defined as 1 − OOB error.
The importance of each feature in a bagging model can be estimated by muting that feature and then compare the OOB-error for the bagging model with the feature to the OOB-error with the feature muted, as shown in Equation (4)
Importance of featurexj = ErrOOB(xj) − ErrOOB(xmutedj ) (4) (James et al, 2013, p.318-319).
3 Data Description
This section includes a description of how the data was collected for this thesis work and also how the data was considered. The data was provided by the company and is collected from large market data providers. It covers the period November 2nd - December 1st 2020 and regards the currency pairs JPYUSD and EURUSD for forward and futures contracts, and spot prices. The data provided for the forward contracts contains different maturity dates, contract periods of 2 weeks, 3 weeks, 1 month and 3 months will be considered. The data was provided in CVS files and connected to each other by the timestamps where the prices were settled.
In the following subsection, the description of the data is split into three parts.
One part regarding the futures contract data, one regarding the forward con- tract data and lastly the spot price data. Furthermore, down in the method section the data pre-processing is described. Note, all data displayed in this thesis is fictional, due to confidentiality.
3.1 Futures Contract Data
The futures contract data includes all data provided that regards the futures contracts. It includes multiple parameters that is collected from the futures market when buying or selling these contracts. The most relevant information in this data is the timestamps and prices since this is what will be compared to with the forward contracts. An example data set is provided in Table 1.
Table 1: An example data set of futures contract data.
Date and Time Delivery Date Trade Price Ask or Bid Ticker Symbol
2020-11-02 00:00:00 2020-12 ... 95000 B JY
2020-11-02 00:00:01 2020-12 ... 95010 B JY
2020-11-02 00:00:03 2020-12 ... 95220 A JY
2020-11-02 00:00:05 2020-12 ... 95000 B JY
futures contracts are always delivered the third Wednesday of either March, June, September and December. Trade Price refers to the total price of the contract and can either be a bid price or an ask price. The Ticker Symbol shows the product code.
3.2 Forward Contract Data
The forward contracts data includes timestamps and price parameters for both the bid and ask prices of the forward contracts. An example for the forward data is provided in Table 2.
Table 2: An example data set of forward contract data.
Ask Bid
Date and Time Open Price Close Price Open Price Close Price
2020-11-02 00:01 3.30 ... 3.29 3.29 ... 3.27
2020-11-02 00:02 3.31 ... 3.32 3.30 ... 3.29
2020-11-02 00:03 3.32 ... 3.33 3.31 ... 3.31
2020-11-02 00:04 3.30 ... 3.29 3.29 ... 3.27
2020-11-02 00:05 3.31 ... 3.31 3.30 ... 3.30
2020-11-02 00:06 3.32 ... 3.32 3.30 ... -´3.31
... ... ... ... ... ... ...
2020-12-01 22:59 3.34 ... 3.33 3.32 ... 3.32
The Open Price data shows the dots for the forward contract at beginning of each minute, and the Close Price at the end of each minute. A dot means 1/10000, for example in this case it would for the first timestamp be 3.30/10000.
3.3 Spot Price Data
The spot price data looks similar to the forward contract data. It consists of the prices and timestamps for both bid and ask prices. An example of the spot price data is provided in Table 3.
Table 3: An example data set of spot price data.
Ask Bid
Date and Time Open Price Close Price Open Price Close Price
2020-11-02 00:01 105.9 ... 105.9 105.1 ... 105.2
2020-11-02 00:02 105.8 ... 105.9 105.2 ... 105.2
2020-11-02 00:03 105.9 ... 105.8 105.4 ... 105.3
2020-11-02 00:04 105.7 ... 105.7 105.3 ... 105.4
2020-11-02 00:05 105.6 ... 105.7 105.3 ... 105.3
2020-11-02 00:06 105.8 ... 105.7 105.4 ... 105.5
... ... ... ... ... ... ...
2020-12-01 22:59 105.6 ... 105.8 105.2 ... 105.3
The open and close prices in this data represent the price at the beginning versus the end of each minute.
4 Method
This section contains a description of the methods implemented during the project, divided into four sub-parts. The pre-processing of data is presented first. Thereafter the data set up is explained. The pre-prosessing and data set up are the same for both the VAR-models and the Random Forest model.
Lastly the modelling is presented, the first section describing the modelling for the VAR-models, the second part describing the modelling of the Random Forrest-model.
4.1 Pre-Processing Data
Large data files of historical data were provided. As it is shown in the section Data, the original data for the two types of contracts were of two different time frequencies, inverted currency pairs and some prices provided with dots. In this section, the processing of the futures, forward and spot data are provided.
4.1.1 Processing Futures Contract Data
Through linear interpolation one can increase or decrease the frequency of data points. Assume a data set with points at xi and xi+1. A data point y(x), where xi < x < xi+1, can be created through the average of the two nearest points:
ˆ
y(x) = yi+ (yi+1− yi) + (xi+1− xi) xi+i− xi
(Bayen and Siauw, 2015, p.212).
The data for the futures contracts was given with a frequency of seconds.
To downsize the data set and make it comparable with the time frequency for the forward contract data, the futures data was converted to minute frequency through linear interpolation.
The prices for the contracts were calculated with the Trade Price and the Trade Price Decimal by following formula:
F uturesP rice = T radeP rice 10T radeP riceDecimal
These results in the final futures contract data that is presented in Table 4.
Table 4: An example data set of final futures contract data.
Date and Time Delivery Date Futures Price Ask or Bid Ticker Symbol
2020-11-02 00:01 2020-12 ... 0.009500 B JY
2020-11-02 00:02 2020-12 ... 0.009501 B JY
2020-11-02 00:03 2020-12 ... 0.009522 A JY
2020-11-02 00:04 2020-12 ... 0.009500 B JY
2020-11-02 00:05 2020-12 ... 0.009550 JY
2020-11-02 00:04 2020-12 ... 0.009590 A JY
... ... ... ... ... ...
2020-12-01 23:59 2020-12 ... 0.009600 A JY
4.1.2 Processing Forward Contract Data
As it can be seen in the Data Description section, the data for the forward contracts was given with dots and not the total price of the contract. In or- der to compare the different contract data, the forward dots were subtracted from the spot prices, resulting in the total price of the forward contracts. In addition, the currency pair given in the forward and spot data was inverted compared to the currency pair given in the futures data, meaning that the base currency in the forward contracts was the quoted currency in the futures contracts data. Due to this, the data had to be processed in the sense so that all the data can be comparable.
The method used to implement this was to add the forward data to the spot data. To posses the same currency as the product versus payment, the ask and bid, high and low data must be inverted. An explanatory example for this implementation is given in Tables 5, 5a, 5b and 5c.
Table 5: Spot price and forward contract data with the same timestamps added together and inverted resulting in comparable forward contract data.
Ask Open High Price Price ...
105.9 105.9 ...
105.8 105.9 ...
105.9 106.0 ...
105.7 105.8 ...
105.6 105.7 ...
105.8 105.9 ...
... ... ... 105.6 105.8 ...
(a) Spot price example data.
Ask Open High
Price Price ...
3.30 3.29 ...
3.31 3.30 ...
3.32 3.31 ...
3.30 3.29 ...
3.31 3.31 ...
3.32 3.32 ...
... ... ... 3.34 3.33 ...
(b) Forward contract ex- ample data, expressed in dots.
Bid
Open Low
Price Price ...
0.009442 0.009442 ...
0.009451 0.009442 ...
0.009442 0.009433 ...
0.009460 0.009451 ...
0.009469 0.009460 ...
0.009451 0.009442 ...
... ... ... 0.009469 0.009451 ...
(c) Comparable forward contract example data.
4.2 Data Setup
4.2.1 Inverse Distance Weighted Interpolation
As mentioned in the theory section (See Theory 2.2.3), forward contracts can expire on any day apart from bank holidays, while futures contracts always expire on one out of four fixed dates. All the futures contracts in the futures data set expire on December 16th, 2020, while the forward contracts expire on many different dates. It would be incorrect to compare the prices of a futures contract and forward contract bought at the same time, if they do not also expire the same time.
By performing inverse distance weighted interpolation (IDW) on forward con- tracts bought the same time t0 but with different maturity dates t1...tn, one can estimate the price of a fictional forward contract bought at t0 expiring at any chosen time between t1 and tn by formula:
ˆ
y = Σni=1d1
i ∗ yi
Σni=1d1
i
,
where ˆy is the estimated price of a forward contracts bought at t0 expiring at chosen time t∗, t1 < t∗ < tn. yi...yn are the observed prices of contracts bought at t0 expiring between t1...tn. d1...dn are the distances in time between the known observations y1...yn expires and the expiry of the estimated value ˆy (Bartier and Keller, 1996, p.795-796).
An IDW, centered around the futures contracts expiry date, 16th of December 2020, was carried out using forward contracts of duration two and three weeks, one and three months, generating estimated prices for forward contracts traded from November 2nd to December 1st.
4.2.2 Stationary Time Series
When using statistical models to analyse data, it is highly preferable that the data is stationary (see Theory 2.3.2). The series of price data for futures contracts, and the series of generated price data for the forward contracts, were tested for stationarity using the ADF test and the KKPS test. Both tests were used since the ADF-test mainly determines a series difference sta- tionary while the KKPS-test determines trend-stationarity (See Theory 2.3.3).
Returns on futures contracts and forward contracts were calculated using the price series data. This in order to create a stationary series, more suitable for modeling and further analysis.
4.3 Modelling VAR
Four data frames containing the relevant data from the pre-processing was created, two for each currency pair. Each data frame contains of futures and forward contacts, for either the ask-data or the bid-data, this since the bid and ask for a contract occurs at different times. In Table 6 an explanatory data frame for the ask data is shown.
Table 6: An example data frame for Ask-data
Date and Time Forward Price Futures Price Forward Return Futures Return 2020-11-02 00:01 0.009510 0.009500 0.000002 0.000002 2020-11-02 00:02 0.009510 0.009501 0.000000 0.000002 2020-11-02 00:03 0.009508 0.009522 0.000001 0.000006
... ... ... ... ...
2020-12-01 23:59 0.009620 0.009601 0.000002 0.000003
The aim of the thesis is to investigate the relations between the price move- ments of futures and forwards contracts. As mentioned earlier (see Theory 2.3.2), it is suitable to use stationary data when analysing statistical relations of time series, Therefore the returns on futures and forwards were used when looking at correlation. A cross-correlation model was implemented, calculating the cross-correlation of the of the two time series
xt: Time series of returns on futures contracts.
yt: Time series of returns on forward contracts.
By formula
rxy(T ) = σxy(T ) pσx2σ2y,
where rxy is the cross-correlation, Xtthe time series for returns on forwards, yt the time series for returns on futures and T is the time lag that xtis delayed by.
Furthermore, the two time series xt and yt were tested for Granger Causality.
Second order bivariate VAR(2)-models for the bid and the ask time series were implemented:
xt yt
=a1 a2
+ b111 b112 b121 b122
xt−1 yt−1
+b211 b212 b221 b222
xt−2 yt−2
+ εx,t εy,t
, where a1 and a2 are the intercepts,
¯1 coefficients for the first order lag terms and¯2 for the second order lag terms, vector of independent and identically distributed error terms with mean zero.
The amount of time lags in the model were selected by inspecting signifi-
the Akaike Information Criterion (AIC) were also used as an indicator, AIC(p) = ln| ˆΣ| + 2k2p
T ,
where Σ is the models estimated covariance matrix, T represents the sample size and k the number of time series in the model and p the number of lags.
AIC penalizes complexity and favors model fit. The lower the AIC score the better.
After selecting number of lags, the models were tested for both long term and short term forecasting, with the help of pythons inbuilt function forecast.
The same method of testing futures and forwards for cross-correlation, fol- lowed by creating VAR models generating forecasts was done for both curren- ciy pairs, JPYUSD and EURUSD.
Thereafter, the bivariate VAR-models were evaluated, using the the forecasts and the coefficient of determination R2 for each model
R2 = 1 − Pn
i=1(yi− ˆyi)2 Pn
i=1(yi− ¯y)2,
where y is the average, R2 shows the percentage of of original variation that has been explained by the model (James et al, 2013, p.69-70).
4.3.1 VAR-model with Two Currency Pairs
The bivariate VAR-models were used to investigate the relation between fu- tures and forwards of the same currency pair. However, in order to see how the relation between futures and forwards is effected by the currency pair itself, a model taking currency into consideration was needed. A VAR(2)-model with all four time series was made and then used for forecasting,
xt yt wt
zt
=
a1 a2 a3
a4
+
b111 b112b113 b114 b121 b122b123 b124 b131 b132b133 b134 b141 b142b143 b144
xt−1 yt−1 wt−1
zt−1
+
b211 b212b213 b214 b221 b222b223 b224 b231 b232b233 b234 b241 b242b243 b244
xt−2 yt−2 wt−2
zt−2
+
εx,t εy,t εw,t εz,t
,
where a1-a4 are intercepts, b1 coefficients for the first order lag terms and b2 for the second order lag terms, independent and identically distributed error terms with mean zero.
Furthermore, the same steps as those are used for the bivariate time series were done for the VAR-model with two currency pairs.
4.4 Modelling Random Forest
When using machine learning models such as Random Forest, it is preferred to have multiple variables in the model. The new varibles Rolling Mean, EWMA, MADQ, Hour and Spot Price were added to the data set.
Rolling mean is the same as a moving average (MA):
Rolling Mean = A1, A2...An n
where A is the average response for each time period n. EWMA is the Exponen- tially Weighted Moving Average:
EW M At= α ∗ rt+ (1 − α) ∗ EW M At−1
where 0 ≤ α ≤ 1 is the weight given to the current observation, and rt is the series value at time t. The higher the α, the more weight is put on the current observation compared to earlier observations (Danielsson, 2011, p.33).
MADQ stands for Moving Average Difference Quota and calculated the difference between long period MA and short period MA:
M ADQ = M Atlong M Atshort
In our data set, the long period is 60 minutes and the short period is 30 min- utes. The variable Hour indicates the hour of the day from 00:00 to 23:00.
Before time series data can be used in supervised learning models such as Random Forest it needs to be reformulated into a supervised learning prob- lem. By creating an input and output column for each variable and put the values for each time step as input and then place the values for that variable one time step later in the output column. For example,
After converting the data sets into learning problems, they were ready to be used in initial Random Forest models. The number dept and number of trees used in the Random Forest models were chosen through testing. Staring out small with low dept and fewer trees, increasing one parameter at the time, comparing results and complexity. As usual, there is a trade off between pre- diction accuracy and complexity of the model that needs to be taken into account.
In order to test whether the futures contract actually added any useful in- formation for predicting the forward contract (and vice versa), the following predictions were made.
First, each contract type was predicted using the features of the other con- tract type as predictors but not including its own previous value as a predictor:
Response : Futures
Predictors :Rolling Meanf orward, EWMAf orward MADQf orward, Spot Price, Hour, Response : Forward
Predictors :Rolling Meanf utures, EWMAf utures MADQf utures, Spot Price, Hour.
Thereafter, the contract types were predicted using the features of the other contract as well as its own previous value:
Response :Futures
Predictors :Rolling Meanf orward, EWMAf orward MADQf orward, Spot Price, Hour, Futurest−1,
Response :Forward
Predictors :Rolling Meanf utures, EWMAf utures MADQf utures Spot Price, Hour, Forwardt−1.
Lastly, predicting each time series without using any information from the other contract type was tested. After each prediction, the feature importance, OOB-score and MSE of the prediction was evaluated.
5 Result
5.1 Results Vector Autoregression
In Figure 1 it is shown that the cross correlation between futures and forwards for JPYUSD data is around 50%. For t = ±1 it is around 3%. For the EU- RUSD data set, the cross correlation at 0 time lags is 66% and around 3% in timelag t = ±1.
Furthermore, the Granger causality test found that all four time series Granger caused each other. The time series all have statistically significant relation- ships to each other. The time series of futures and forward contracts having high correlation and Granger causality, implying that one of the contract types could be useful in predicting the other. Following formula shows a representa- tion of the estimated VAR(2)-model
ˆxt ˆ yt
=ˆa1 ˆ a2
+
ˆb111 ˆb112 ˆb121 ˆb122
ˆxt−1 ˆ yt−1
+
ˆb211 ˆb212 ˆb221 ˆb222
ˆxt−2 ˆ yt−2
+ εx,t εy,t
.
Table 8: Estimates of VAR(2)-model for currency pair JPYUSD using ask data.
Data for JPYUSD Ask
Response Coefficients Estimates Standard Error P-value Futures Price, xt aˆ1 -0.0000 1.0000 0.896
ˆb111 -0.0345 0.0064 0.000
ˆb112 0.0982 0.0130 0.000
ˆb221 -0.0301 0.0064 0.000
ˆb222 0.0273 0.0130 0.036
Forward Price yt aˆ2 0.0000 0.0000 0.771
ˆb111 0.0125 0.0032 0.000
ˆb112 -0.0145 0.0064 0.024
ˆb221 -0.0015 0.0032 0.646
ˆb222 -0.0027 0.0064 0.679
Table 9: Estimates of VAR(2)-model for currency pair JPYUSD using bid data.
Data for JPYUSD Bid
Response Coefficients Estimates Standard Error P-value Futures price, xt aˆ1 0.000000 0.000000 0.897
ˆb111 -0.021922 0.006389 0.001 ˆb112 0.073417 0.012848 0.000 ˆb221 -0.030082 0.006388 0.000 ˆb222 0.025738 0.012851 0.045 Forward price, yt aˆ2 0.000000 0.000000 0.770 ˆb111 0.014233 0.003178 0.000 ˆb112 -0.019807 0.006391 0.002 ˆb221 –0.000198 0.003178 0.950 ˆb222 –0.008454 0.006393 0.186
Table 10: Estimates of VAR(2)-model for currency pair EURUSD using ask data.
Data for EURUSD Ask
Response Coefficients Estimates Standard Error P-value Futures price, xt aˆ1 0.000001 0.000001 0.369
ˆb111 -0.025846 0.006865 0.000 ˆb112 0.044170 0.010287 0.000 ˆb221 -0.008260 0.006865 0.229 ˆb222 -0.001272 0.010286 0.902 Forward price, yt aˆ2 0.000001 0.000001 0.159 ˆb111 0.025363 0.004579 0.000 ˆb112 -0.037986 0.006862 0.000 ˆ
Table 11: Estimates of VAR(2)-model for currency pair EURUSD using bid data.
Data for EURUSD Bid
Response Coefficients Estimates Standard Error P-value Futures price, xt aˆ1 0.000001 0.000001 0.3670
ˆb111 -0.019763 0.006882 0.0040 ˆb112 0.030716 0.010280 0.0030 ˆb221 -0.009356 0.006882 0.1740 ˆb222 -0.004404 0.010280 0.6680 Forward price, yt aˆ2 0.000001 0.000001 0.1630 ˆb111 0.021491 0.004606 0.0000 ˆb112 -0.041699 0.006881 0.0000 ˆb221 0.003784 0.004606 0.4110 ˆb222 -0.023749 0.006881 0.0010
In the upper half in each of the Tables 8 - 11, one can see the estimated coeffi- cients for predicting the futures price xt, and in the lower half in each table the estimated coefficients for the forwards price yt. There seems to be a pattern that the first and second lags of both futures and forwards are significant for predicting the futures contract, since this is the case for all data sets except the ask data for EURUSD in Table 9. Likewise, looking at the lower half of Tables 8 - 11, there seems to be a pattern of the first lags of futures and forwards being significant for predicting forward prices.
Table 12: Correlation of residuals for VAR(2)-model for JPYUSD ask data.
Futures contracts Forward contracts
Futures contracts 1.000 0.336
Forward contracts 0.336 1.000
Table 13: Correlation of residuals for VAR(2)-model for JPYUSD bid data.
Futures contracts Forward contracts
Futures contracts 1.000 0.332
Forward contracts 0.332 1.000
Table 14: Correlation of residuals for VAR(2)-model for EURUSD ask data.
Futures contracts Forward contracts
Futures contracts 1.000 0.472
Forward contracts 0.472 1.000
Table 15: Correlation of residuals for VAR(2)-model for EURUSD bid data.
Futures contracts Forward contracts
Futures contracts 1.000 0.476
Forward contracts 0.476 1.000
In Tables 12-15, one can see that the correlation of residuals for all time series are quite high. This indicates that there probably is an underlying factor not included in the model, that effects all time series in a similar way.
Figure 3: Forecasts over a 200 minute time period for the JPYUSD bid data.
Figure 4: Forecasts over a 200 minute time period for the EURUSD ask data.
Figure 5: Forecasts over a 200 minute time period for the EURUSD bid data.
Looking at Figures 2-5, none of the forecasts seem to be very accurate, even though there was strong statistical significance for many lag terms in the VAR- model.
Table 16: R2 for the bivariate VAR(2)-model.
FuturesJ P Y U SD ForwardJ P Y U SD FuturesEU RU SD ForwardEU RU SD
Long Term Ask 0.0575 -0.0002 0.1332 -0.0651
Long Term Bid 0.0569 -0.0002 0.1037 -0.0474
Short Term Ask 0.0641 -0.0036 0.1412 -0.0828
Short Term Bid 0.0675 -0.0048 0.1765 -0.0623
Looking at Table 16 the R2values for the futuresJ P Y U SDcontracts are less than 0.07, meaning very little of the variation for futuresJ P Y U SD is explained by the model. Futhermore, the long and short term forecasts for the forwardJ P Y U SD
in this section. The results for the bid data is found in Appendix A.1. Fur- thermore, since there are a total of 32 coefficients in the dual currency pair VAR(2)-model, the coefficients are written out in text form, rather than rep- resented by letters and indexes.
Table 17: Results for the VAR-model with both currency pairs, using ask data.
Response: FuturesJ P Y U SD
Coefficients Standard Error P-value
Intercept 0.0000 0.0000 0.9050
Lag 1, FuturesJ P Y U SD -0.0416 0.0070 0.0000 Lag 1, ForwardJ P Y U SD 0.0980 0.0143 0.0000
Lag 1, FuturesEU RU SD 0.0002 0.0001 0.0030
Lag 1, ForwardEU RU SD -0.0001 0.0001 0.3340 Lag 2, FuturesJ P Y U SD -0.0368 0.0070 0.0000 Lag 2, ForwardJ P Y U SD 0.0321 0.0143 0.0250
Lag 2, FuturesEU RU SD 0.0002 0.0001 0.0050
Lag 2, ForwardEU RU SD -0.0002 0.0001 0.0540 Response: ForwardJ P Y U SD
Intercept 0.0000 0.0000 0.8230
Lag 1, FuturesJ P Y U SD 0.0115 0.0033 0.0010 Lag 1, ForwardJ P Y U SD -0.0317 0.0069 0.0000
Lag 1, FuturesEU RU SD 0.0000 0.0000 0.8570
Lag 1, ForwardEU RU SD 0.0003 0.0001 0.0000
Lag 2, FuturesJ P Y U SD -0.0020 0.0033 0.5410 Lag 2, ForwardJ P Y U SD -0.0076 0.0069 0.2650 Lag 2, FuturesEU RU SD -0.0000 0.0000 0.7410
Lag 2, ForwardEU RU SD 0.0001 0.0000 0.1530
Response : FuturesEU RU SD
Intercept 0.0000 0.0000 0.3610
Lag 1, FuturesJ P Y U SD 0.5058 0.6801 0.4570 Lag 1, ForwardJ P Y U SD 7.8131 1.4042 0.0000 Lag 1, FuturesEU RU SD -0.0295 0.0072 0.0000
Lag 1, ForwardEU RU SD 0.0236 0.0109 0.0310
Lag 2, FuturesJ P Y U SD 0.0901 0.6799 0.8950 Lag 2, ForwardJ P Y U SD 1.4721 1.4047 0.2950 Lag 2, FuturesEU RU SD -0.0088 0.0072 0.2190
Lag 2, Forward -0.0077 0.0109 0.4800
Table 18: Continuation of Table 17.
Coefficients Standard Error P-value Response: ForwardEU RU SD
Intercept 0.0000 0.0000 0.1520
Lag 1, FuturesJ P Y U SD 2.2008 0.4530 0.0000 Lag 1, ForwardJ P Y U SD 6.5196 0.9352 0.0000
Lag 1, FuturesEU RU SD 0.0164 0.0048 0.0010
Lag 1, ForwardEU RU SD -0.0545 0.0073 0.0000 Lag 2, FuturesJ P Y U SD -1.8690 0.4529 0.0000 Lag 2, ForwardJ P Y U SD 2.8553 0.9356 0.0020 Lag 2, FuturesEU RU SD -0.0001 0.0048 0.9810 Lag 2, ForwardEU RU SD -0.0317 0.0073 0.0000 The result from the dual-currency VAR model shown In Table 17 do not show any obvious pattern.
Table 19: Correlation of residuals for VAR(2)-model with both currencies, using ask data.
FuturesJ P Y U SD ForwardJ P Y U SD FuturesEU RU SD ForwardEU RU SD
FuturesJ P Y U SD 1.0000 0.3227 0.3957 0.1546
ForwardJ P Y U SD 0.3227 1.0000 0.2522 0.3912
FuturesEU RU SD 0.3957 0.2522 1.0000 0.4763
ForwardEU RU SD 0.1546 0.3912 0.4763 1.0000
The correlation of residuals shown in Table 19 are still relatively high, indicat- ing that there is some underlying factor not included in the model, effecting all time series in a similar way. However, it is lower than in the bivariate VAR-models in Tables 12-15. Since there is lower correlation of residuals in the VAR-model with two currency pairs, it seems that the currency pair is a factor explaining some of the previously unexplained variation.
Figure 6: Forecasts over a 200 minute time period for the currency pairs JPYUSD and EURUSD ask data.
Similar to the results of the forecasts made by the bi-variate models, the fore- casts made by the VAR-model using both currency pairs, seen in Figure 6, are not very accurate despite many lag-terms being significant in Table 17.
Table 20: R2 for the VAR(2)-model with two currency pairs.
FuturesJ P Y U SD ForwardJ P Y U SD FuturesEU RU SD ForwardEU RU SD
Long Term Ask 0.0581 -0.0005 0.1353 -0.0635
Short Term Ask 0.0798 -0.0088 0.1364 -0.0744
Looking at the R2 values in Table 20, less than 8% of the variation for the futuresJ P Y U SD contracts, and less than 14% of the futuresEU RU SD contracts is explained by the model. Furthermore, the long and short term forecasts for the forward contracts have negative R2 values, indicating that using ¯y for predicting the forward contracts would explain more of the variance than the VAR-model does.
5.2 Results Random Forest
After tuning and testing, the resulting Random Forest model had a width of 100 trees and a dept of 4 nodes. The data sets have been split up into six different training, validation and test sets.
5.2.1 Predictions made without the response in t − 1 as predictor The forecasts in Figures 7-8 presents six graphs each predicted only with the other contracts features. In other words, the futures contracts are predicted solely based on the forward contracts features. Likewise, the prediction of the futures contracts were predicted solely using the features of the forward contracts.
Figure 7: The features of the futures contracts used for predicting the forward prices, and vice versa, for the JPYUSD Ask data.
Figure 8: The features of the futures contracts used for predicting the forward prices, and vice versa, for the EURUSD Ask data.
Similar to the result for the JPYUSD ask futures predictions in Figure 7, there are two periods where the futures prediction deviates far from the actual values for the EURUSD ask data as well. One of them is found in the top left graph in Figure 8. The prediction results for JPYUSD and EURUSD bid is found in Appendix A.2 due to very similar forecasts as in the ask predictions.
Figure 9: Feature importance in predicting the forward contracts for the JPYUSD ask data.
Figure 10: Feature importance in predicting the futures contracts for the JPYUSD ask data.
Figure 11: Feature importance in predicting the forward contracts for the EU- RUSD ask data.
Figure 12: Feature importance in predicting the futures contracts for the EU- RUSD ask data.
It can be seen in Figures 9-12 that when predicting forward movements, the spot price is the most significant feature, while for the futures the features used varies. The feature importance for the JPYUSD and EURUSD bid were very similar to the feature importance for the JPYUSD and EURUSD ask, and are therefore presented in Appendix A.3.
Table 21: Mean squared error for the prediction for JPYUSD and EURUSD.
The six splits represents the six test sets that were created for each data set.
Contract/Data Split 1 2 3 4 5 6
ForwardJ P Y U SD Ask 5.767e-12 1.113e-11 8.439e-12 9.168e-12 4.707e-12 1.472e-11 FuturesJ P Y U SD Ask 9.215e-11 4.085e-09 9.006e-11 1.847e-11 6.216e-10 1.491e-11 ForwardJ P Y U SD Bid 6.141e-12 1.122e-11 8.416e-12 9.412e-12 4.479e-12 1.635e-11 FuturesJ P Y U SD Bid 7.514e-11 3.655e-09 9.465e-11 1.854e-11 5.060e-10 1.401e-11 ForwardEU RU SDAsk 9.234e-08 2.084e-07 7.358e-08 5.912e-08 1.523e-07 1.011e-07 FuturesEU RU SDAsk 9.407e-06 3.525e-07 6.770e-08 4.301e-07 4.841e-07 1.506e-07 ForwardEU RU SDBid 8.475e-08 2.023e-07 8.141e-08 5.577e-08 1.635e-07 9.219e-08 FuturesEU RU SDBid 1.001e-05 3.012e-07 7.353e-08 4.097e-07 5.375e-07 4.704e-07
Table 22: Out of Bag Score for the prediction for JPYUSD and EURUSD. The six splits represents the six test sets that were created for each data set.
Contract/Data Split 1 2 3 4 5 6
ForwardJ P Y U SD Ask 0.9843 0.9980 0.9924 0.9899 0.9948 0.9647 FuturesJ P Y U SD Ask 0.8481 0.9169 0.9271 0.9762 0.8695 0.9423 ForwardJ P Y U SD Bid 0.9841 0.9978 0.9924 0.9898 0.9950 0.9623 FuturesJ P Y U SD Bid 0.8781 0.9198 0.9263 0.9767 0.8820 0.9450 ForwardEU RU SD Ask 0.9935 0.9881 0.9904 0.9777 0.9723 0.9863 FuturesEU RU SD Ask 0.8671 0.7780 0.9566 0.8817 0.9413 0.9308 ForwardEU RU SD Bid 0.9934 0.9875 0.9903 0.9772 0.9723 0.9866 FuturesEU RU SD Bid 0.8678 0.8326 0.9566 0.8799 0.9451 0.9137 In Table 21 the mean squared error is presented for the predictions. It can be seen that all the prediction for the currency pairs JPYUSD and EURUSD has low MSE. In Table 22 the out of bag score is presented, and it showed that the OOB score for the forward contracts is better than for the futures contracts.
5.2.2 Predictions made including the response in t − 1 as predictor
Figure 13: The features of the futures contract, combined with one time lag historical price data from the own contract, used for predicting the forward prices, and vice versa, for the JPYUSD ask data.
Figure 14: The features of the futures contract, combined with one time lag historical price data from the own contract, used for predicting the forward prices, and vice versa, for the EURUSD ask data.
Due to similar prediction results for the JPYUSD and EURUSD bid data, these predictions are presented in Appendix A.4.
Figure 15: Feature importance in predicting the forward contracts for the JPYUSD ask data.
Figure 16: Feature importance in predicting the futures contracts for the JPYUSD ask data.
Figure 17: Feature importance in predicting the forward contracts for the EU- RUSD ask data.
Figure 18: Feature importance in predicting the futures contracts for the EU- RUSD ask data.
Looking at Figure 16 it is very clear that F uturest−1 is the most important feature for predicting F uturest. Likewise, in Figure 15 it is clear that the F orwardt−1is the most important feature for predicting F orwardt. The same pattern is shown for the EURUSD ask data in Figures 18 and 17. The results for the bid data sets were highly similar and can be found in the Appendix A.5. For each of the data sets time series the single most important predictor for time series in time t, is the time series itself in time t − 1.