How to find coefficient that will minimize the distance between few times series I have 3 time series X1, X2, X3. 
I want to find the coefficient (c1, c2) that will minimize the distance between them as follow:
$$MIN\sum\sqrt{(X1-(c1*X2+c2*X3))^2}$$
The constrains are:
$$-1< c1,c2 < 1$$
How can I do it in R? 
 A: Andreas Brandmaier has developed an approach to evaluating pairs of time series that generates a complexity- and information theoretic-based distance function which he calls Permutation Distance Clustering (PDC). In addition, he has developed several R modules that perform his methodology:
1) https://cran.r-project.org/web/packages/pdc/pdc.pdf
2) https://www.jstatsoft.org/article/view/v067i05/v067i05.pdf
3) http://scidok.sulb.uni-saarland.de/volltexte/2012/4545/pdf/Andreas_M_Brandmaier_Dissertation.pdf
Here's a quote from the abstract to article 2):

The dissimilarity of time series is formalized as the squared
  Hellinger distance between the permutation distribution of embedded
  time series. The resulting distance measure has linear time
  complexity, is invariant to phase and monotonic transformations, and
  robust to outliers.

This quote does not mention that his approach does not rely on moment-based measures such as the mean, std dev, etc, which are the basis of traditional approaches to estimating distance functions, e.g., Euclidean distance, adding additional robustness to the methodology.
In addition, the introduction to paper 1) goes into some depth about how distance functions are used in cross-sectional approaches to clustering. For all intents and purposes, these notes related to clustering can be ignored as not being directly relevant to your objective. 
Given 3 time series for your data, you would want to execute 3 comparisons: x1 with x2, x1 with x3 and x2 with x3. The key metric is the squared Hellinger distance function that is a direct by-product of this approach. 
