Time Series question

Code a time series class in Python and call it Timeseries. The class Timeseries will have two vector valued elements: a) time and b) value. You can
choose the most appropriate data structure to represent internally time and
value (e.g. lists)
– When constructing a new object of type Timeseries, you will call something
like myTimeSeries = Timeseries(timeVec,priceVec)
– The Timeseries class will contain a method ”sample” which, given a vector
of times sampleTimes, returns a Timeseries object where the time member is
sampleTimes and values are the values of the Timeseries object immediately
prior or at the corresponding entry of sampleTimes[i]. For example if I have
the following
myT s = T imeseries([1, 2, 3, 4], [101, 102, 103, 104])
and
sampleT imes = [2.5, 3.1, 3.6]
Calling the method sample on myTs should return
myT s.sample(sampleT imes)− > T imeSeries([2.5, 3.1, 3.6], [102, 103, 103])
Make sure that the sample method is implemented efficiently as the sampleTimes vector may contain a large number of elements.
– The Timeseries class must contain a method to calculate the maximum drawdown (MDD) of the series. The method should return, apart form the MDD
the tuple of times the MDD refers to.
– The Timeseries class should also have methods to calculate to calculate
mean, variance and Sharpe ratio (assume that the risk free rate is zero).
– Given two Timeseries objects implement a function to calculate the covariance between the two time series. This function can be a stand-alone
(or static) method and does not have to belong to the Timeseries class. Note
that in general will not be synchronized. It is ok for the purpose of this
exercise to synchronize the Timeseries before calculating the correlation.
2
– Normalize the two Timeseries (call the respective values Y
(1) and Y
(2)) so
that they both start at 100. Build a new Timeseries where each element
satisfies
Y(3)t = Y(2)t − βY (1)t
where
β =
Cov(Y(2), Y (1))/
Var(Y (1))
.
and Cov and Var represent the covariance and variance operators respectively. As before, it is ok to synchronize Y(1) and Y(2) before calculating
Y(3). Note that Y(3) should be a Timeseries object. You can choose the
common time grid you deem to be most appropriate.
– Note that Y(3) amounts to a simple long-short trading strategy. Calculate
the MDD and Sharpe ratio of Y(3)
.

//