public static double AnnualisedStdDev(this ITimeSeries <double> timeseries)
 {
     return(Stats.Statistics.StandardDeviation(timeseries.Data) * Math.Sqrt(timeseries.PeriodsInYear()));
 }
        /// <summary>
        /// Calculates the residual risk (annualised standard deviation of the error term from the CAPM linear regession)
        /// </summary>
        /// <param name="asset">Asset time series</param>
        /// <param name="benchmark">Benchmark time series</param>
        /// <param name="riskfree">Risk-free rate of return specified as a fractional value, e.g. 0.05 for 5%</param>
        /// <returns>Returns the standard deviation</returns>
        public static double ResidualRisk(ITimeSeries <double> asset, ITimeSeries <double> benchmark, double riskfree = 0)
        {
            var Ra = asset.AsTimeSeries() - riskfree;
            var Rb = benchmark.AsTimeSeries() - riskfree;

            return(Math.Round(Statistics.StandardDeviation(Model.LinearRegression(Ra.Data, Rb.Data).Residuals) * Math.Sqrt(asset.PeriodsInYear()), DecimalDigits));
        }
 public static double AnnualisedMean(this ITimeSeries <double> timeseries)
 {
     return(Stats.Statistics.Mean(timeseries.Data) * timeseries.PeriodsInYear());
 }