1
$\begingroup$

I have an existing time series that I would like to make more volatile, or more variance.
I would like the highs to be higher and the lows to be lower.
The time series is somewhat stationary and I would like the amplification of the numbers in the series to keep the same slope. In other words, I would like the mean of the series to remain the same and the standard deviation of the series to increase.

Below is my attempt.
I fit a line to it with linear regression. This part works okay. The problem comes when I try to make every number above the regression line higher and every number below it low at a scale. See the picture below for how this code works. It's not giving me a spikey, volatile series I want. It's just dividing the highs and lows further apart.
Sorry, I don't know math notation, and I'm trying to do this in Python, so I'd really appreciate it if you could make your answer legible to a math illiterate like me.

def slope(series):
    x = [x for x in range(int(len(series)))]
    fit = np.polyfit(x, series, 1)
    fit_fn = np.poly1d(fit)
    return fit_fn(x)

ss = slope(time_series)

tu = []
w = 0
for n, z in enumerate(time_series):
    b = z * 1.3
    if ss[n] < z:
        r = (z - b)
    else:
        r = (z + b) 
    w += r
    tu.append(r)

This was my attempt.

enter image description here

This is the original.

enter image description here

What I want is just a time series with more extreme swings. I want everything to scale from the mean trend line.

$\endgroup$
7
  • 1
    $\begingroup$ Isn't wanting the standard deviation to stay the same while volatility increases contradictory? If you drop the former requirement, what about fitting a linear trend, obtaining the residuals, multiplying them by $c>1$ and adding them back to the fitted trend? That would increase the amplitude of the swings $c$ times. $\endgroup$ Sep 6, 2021 at 14:53
  • $\begingroup$ Thank you. I fixed the standard deviation part. As for your solution, I'm not sure where to begin with that. $\endgroup$
    – Renoldus
    Sep 6, 2021 at 16:36
  • 1
    $\begingroup$ You can begin by fitting a linear trend to your data. (I do not speak Python, so I cannot suggest a code bit.) $\endgroup$ Sep 6, 2021 at 16:50
  • $\begingroup$ I appreciate you paying attention to my lonely post. Yes, I fit a line with linear regression in the code. I tried a few combinations of multiplying and subtracting or adding to the time series if the the number was above or below the fit line. It's how I got the first picture in my post. It was the point I got lost at. $\endgroup$
    – Renoldus
    Sep 6, 2021 at 17:43
  • 2
    $\begingroup$ Are you able to extract residuals after fitting a linear trend? If yes, multiply them by $c$ and add to the fitted line. It should do the trick. You do not need to condition on whether the residual is positive or negative; maybe the conditioning is messing things up. $\endgroup$ Sep 6, 2021 at 18:33

1 Answer 1

1
$\begingroup$

Probably the quickest/easiest way to do this is to:

  • Stationarise the time series by taking differences or returns: e.g. $x_{diff}(t) = x(t)-x(t-1)$.
  • Subtract the mean and divide by the standard deviation: $x_{norm}(t) = \frac{x_{diff}(t)-\mu(x_{diff})}{\sigma(x_{diff})}$
  • You now have something resembling data drawn from a Gaussian distribution of mean 0 and standard deviation 1.
  • Now just multiply the data by whatever you want the new standard deviation to be, add back in the mean, and do a cumulative sum/product to convert from difference/returns back to original values.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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