/// <summary> /// Estimates the Hurst Exponent, considering the specified hypothetical next value of the already stored time series. /// </summary> /// <remarks> /// Operation does not change the instance data. /// </remarks> /// <returns>The resulting linear fit object.</returns> public LinearFit ComputeNext(double simValue) { //Affect the simulated next value into the existing averages double[] avgValues = new double[_avgCollection.Count]; Parallel.For(0, _subIntervalLengthCollection.Count, _subIntervalIdx => { int intervalLength = _subIntervalLengthCollection[_subIntervalIdx]; RescaledRange intervalRescaledRange = new RescaledRange(intervalLength); for (int valueIdx = (_valueCollection.Count - intervalLength) + 1; valueIdx < _valueCollection.Count; valueIdx++) { intervalRescaledRange.AddValue(_valueCollection[valueIdx]); } intervalRescaledRange.AddValue(simValue); avgValues[_subIntervalIdx] = _avgCollection[_subIntervalIdx].SimulateNext(intervalRescaledRange.Compute()); }); //Add updated existing points LinearFit linFit = new LinearFit(); for (int i = 0; i < _avgCollection.Count; i++) { double x = Math.Log(_subIntervalLengthCollection[i]); double avg = avgValues[i]; double y = 0; if (avg != 0) { y = Math.Log(avg); } linFit.AddSamplePoint(x, y); } //Return return(linFit); }
/// <summary> /// Computes Hurst exponent estimation for next hypothetical value in time series. /// Function does not change the instance, it is a simulation only. /// </summary> /// <param name="simValue">Next time series value</param> public double ComputeNext(double simValue) { //Affect new value to existing averages double[] avgValues = new double[_avgCollection.Count]; Parallel.For(0, _subIntervalLengthCollection.Count, _subIntervalIdx => { int intervalLength = _subIntervalLengthCollection[_subIntervalIdx]; RescalledRange intervalRescalledRange = new RescalledRange(intervalLength); for (int valueIdx = (_valueCollection.Count - intervalLength) + 1; valueIdx < _valueCollection.Count; valueIdx++) { intervalRescalledRange.AddValue(_valueCollection[valueIdx]); } intervalRescalledRange.AddValue(simValue); avgValues[_subIntervalIdx] = _avgCollection[_subIntervalIdx].SimulateNext(intervalRescalledRange.Compute()); }); //Add updated existing points LinearFit linFit = new LinearFit(); for (int i = 0; i < _avgCollection.Count; i++) { double x = Math.Log(_subIntervalLengthCollection[i]); double avg = avgValues[i]; double y = 0; if (avg != 0) { y = Math.Log(avg); } linFit.AddSamplePoint(x, y); } //Add new point for sub-interval length = (_timeSeries.Length + 1) RescalledRange fullRescalledRange = new RescalledRange(_valueCollection.Count + 1); foreach (double value in _valueCollection) { fullRescalledRange.AddValue(value); } fullRescalledRange.AddValue(simValue); double fullRangeAvg = fullRescalledRange.Compute(); linFit.AddSamplePoint(Math.Log(_valueCollection.Count + 1), fullRangeAvg == 0 ? 0 : Math.Log(fullRangeAvg)); //Return return(linFit.A); }
/// <summary> /// Estimates the Hurst Exponent. /// </summary> /// <returns>The resulting linear fit object</returns> public LinearFit Compute() { LinearFit linFit = new LinearFit(); for (int i = 0; i < _avgCollection.Count; i++) { double x = Math.Log(_subIntervalLengthCollection[i]); double avg = _avgCollection[i].Result; double y = 0; if (avg != 0) { y = Math.Log(avg); } linFit.AddSamplePoint(x, y); } return(linFit); }