# Quantitative Modeling for Algorithmic Traders – Primer

3 May 2017

Quantitative Modeling techniques enable traders to mathematically identify, what makes data “tick” – no pun intended 🙂 .

They rely heavily on the following core attributes of any sample data under study:

1. Expectation – The mean or average value of the sample
2. Variance – The observed spread of the sample
3. Standard Deviation – The observed deviation from the sample’s mean
4. Covariance – The linear association of two data samples
5. Correlation – Solves the dimensionality problem in Covariance

## Why a dedicated primer on Quantitative Modeling?

Understanding how to use the five core attributes listed above in practice, will enable you to:

1. Construct diversified DARWIN portfolios using Darwinex’ proprietary Analytical Toolkit.
2. Conduct mean-variance analysis for validating your DARWIN portfolio’s composition.
3. Build a solid foundation for implementing more sophisticated quantitative modeling techniques.
4. Potentially improve the robustness of trading strategies deployed across multiple assets.

Hence, a post dedicated to defining these core attributes, with practical examples in R (statistical computing language) should hopefully serve as good reference material to accompany existing and future posts.

### Why R?

1. It facilitates the analysis of large price datasets in short periods of time.
2. Calculations that would otherwise require multiple lines of code in other languages, can be done much faster as R has a mature base of libraries for many quantitative finance applications.

### Before progressing any further, we need to download EUR/USD and GBP/USD sample data from Yahoo Finance (time period: January 01 to March 31, 2017)

In R, this can be achieved with the following code:

`library(quantmod)`

`getSymbols("EUR=X",src="yahoo",from="2017-01-01", to="2017-03-31")`

`getSymbols("GBP=X",src="yahoo",from="2017-01-01", to="2017-03-31")`

Note: “EUR=X” and “GBP=X” provided by Yahoo are in terms of US Dollars, i.e. the data represents USD/EUR and USD/GBP respectively. Hence, we will need to convert base currencies first.

To achieve this, we will first extract the Adjusted Close Price from each dataset, convert base currency and merge both into a new data frame for use later:

`eurAdj = unclass(`EUR=X`\$`EUR=X.Adjusted`)`

`# Convert to EUR/USD`
`eurAdj = 1/eurAdj   `

`gbpAdj <- unclass(`GBP=X`\$`GBP=X.Adjusted`)`

`# Convert to GBP/USD`
`gbpAdj <- 1/gbpAdj`

`# Extract EUR dates for plotting later.`
`eurDates = index(`EUR=X`)   `

`# Create merged data frame.`
`eurgbp_merged <- data.frame(eurAdj,gbpAdj)`

EUR/USD and GBP/USD (Jan 01 – Mar 31, 2017)

Finally, we merge the prices and dates to form one single dataframe, for use in the remainder of this post:

`eurgbp_merged = data.frame(eurDates, eurgbp_merged)`

`colnames(eurgbp_merged) = c("Dates", "EURUSD", "GBPUSD")`

In future blog posts, we will examine how to construct diversified DARWIN Portfolios using the information above in practice.