def test_statistics(): alpha = [random.random() for val in range(count)] alpha_stats = Statistics() for val in alpha: alpha_stats.push(val) assert len(alpha_stats) == count assert error(mean(alpha), alpha_stats.mean()) < error_limit assert error(variance(alpha), alpha_stats.variance()) < error_limit assert error(stddev(alpha), alpha_stats.stddev()) < error_limit assert error(skewness(alpha), alpha_stats.skewness()) < error_limit assert error(kurtosis(alpha), alpha_stats.kurtosis()) < error_limit assert alpha_stats.minimum() == min(alpha) assert alpha_stats.maximum() == max(alpha) alpha_stats.clear() assert len(alpha_stats) == 0 alpha_stats = Statistics(alpha) beta = [random.random() for val in range(count)] beta_stats = Statistics() for val in beta: beta_stats.push(val) gamma_stats = alpha_stats + beta_stats assert len(beta_stats) != len(gamma_stats) assert error(mean(alpha + beta), gamma_stats.mean()) < error_limit assert error(variance(alpha + beta), gamma_stats.variance()) < error_limit assert error(stddev(alpha + beta), gamma_stats.stddev()) < error_limit assert error(skewness(alpha + beta), gamma_stats.skewness()) < error_limit assert error(kurtosis(alpha + beta), gamma_stats.kurtosis()) < error_limit assert gamma_stats.minimum() == min(alpha + beta) assert gamma_stats.maximum() == max(alpha + beta) delta_stats = beta_stats.copy() delta_stats += alpha_stats assert len(beta_stats) != len(delta_stats) assert error(mean(alpha + beta), delta_stats.mean()) < error_limit assert error(variance(alpha + beta), delta_stats.variance()) < error_limit assert error(stddev(alpha + beta), delta_stats.stddev()) < error_limit assert error(skewness(alpha + beta), delta_stats.skewness()) < error_limit assert error(kurtosis(alpha + beta), delta_stats.kurtosis()) < error_limit assert delta_stats.minimum() == min(alpha + beta) assert delta_stats.maximum() == max(alpha + beta)
def main(): args = list(map(float, sys.argv[1:])) print('Statistics Functions') print('Count:', len(args)) print('Mean:', mean(args)) print('Variance:', variance(args)) print('StdDev:', stddev(args)) print('Skewness:', skewness(args)) print('Kurtosis:', kurtosis(args)) fast_stats = FastStatistics() for arg in args: fast_stats.push(arg) print() print('FastStatistics') print('Count:', len(fast_stats)) print('Mean:', fast_stats.mean()) print('Variance:', fast_stats.variance()) print('StdDev:', fast_stats.stddev()) print('Skewness:', fast_stats.skewness()) print('Kurtosis:', fast_stats.kurtosis()) core_stats = CoreStatistics() for arg in args: core_stats.push(arg) print() print('CoreStatistics') print('Count:', len(core_stats)) print('Mean:', core_stats.mean()) print('Variance:', core_stats.variance()) print('StdDev:', core_stats.stddev()) print('Skewness:', core_stats.skewness()) print('Kurtosis:', core_stats.kurtosis()) fast_exp_stats = FastExponentialStatistics() for arg in args: fast_exp_stats.push(arg) print() print('FastExponentialStatistics') print('Decay Rate (default):', fast_exp_stats.get_decay()) print('Exponential Mean:', fast_exp_stats.mean()) print('Exponential Variance:', fast_exp_stats.variance()) print('Exponential StdDev:', fast_exp_stats.stddev()) core_exp_stats = CoreExponentialStatistics() for arg in args: core_exp_stats.push(arg) print() print('CoreExponentialStatistics') print('Decay Rate (default):', core_exp_stats.get_decay()) print('Exponential Mean:', core_exp_stats.mean()) print('Exponential Variance:', core_exp_stats.variance()) print('Exponential StdDev:', core_exp_stats.stddev()) fast_regr = FastRegression() for index, arg in enumerate(args, 1): fast_regr.push(index, arg) print() print('FastRegression') print('Count:', len(fast_regr)) print('Slope:', fast_regr.slope()) print('Intercept:', fast_regr.intercept()) print('Correlation:', fast_regr.correlation()) core_regr = CoreRegression() for index, arg in enumerate(args, 1): core_regr.push(index, arg) print() print('CoreRegression') print('Count:', len(core_regr)) print('Slope:', core_regr.slope()) print('Intercept:', core_regr.intercept()) print('Correlation:', core_regr.correlation())
series.append(r_t) #print (series) stats = Statistics() for x in series: stats.push(x) # Test kurtosis and skewness # Skewness < 0 indicates large decreases after many small gains, skewness > 0 indicates large gains after many small losses # Optimally want -0.8 < x < 0, or x > 1 print('skewness: ', stats.skewness()) # Kurtosis we want to be leptokurtic (> average) print('kurtosis: ', stats.kurtosis()) # TODO Jarque-Bera about normal distribution - pref want not a normal distribution (ie reject H0 / p-value ~= 0) # TODO time series tests # Evaluate trading over time inputdata (not the log series) # TODO, shorting?? start = 1000 isBought = False isInitial = True initialTradePrice = 1 current = start mintick = 0.00000001 # Minimum tick totalTrades = -1
def main(): args = list(map(float, sys.argv[1:])) print('Statistics Functions') print('Count:', len(args)) print('Mean:', mean(args)) print('Variance:', variance(args)) print('StdDev:', stddev(args)) print('Skewness:', skewness(args)) print('Kurtosis:', kurtosis(args)) fast_stats = FastStatistics() for arg in args: fast_stats.push(arg) print() print('FastStatistics') print('Count:', len(fast_stats)) print('Mean:', fast_stats.mean()) print('Variance:', fast_stats.variance()) print('StdDev:', fast_stats.stddev()) print('Skewness:', fast_stats.skewness()) print('Kurtosis:', fast_stats.kurtosis()) core_stats = CoreStatistics() for arg in args: core_stats.push(arg) print() print('CoreStatistics') print('Count:', len(core_stats)) print('Mean:', core_stats.mean()) print('Variance:', core_stats.variance()) print('StdDev:', core_stats.stddev()) print('Skewness:', core_stats.skewness()) print('Kurtosis:', core_stats.kurtosis()) fast_regr = FastRegression() for index, arg in enumerate(args, 1): fast_regr.push(index, arg) print() print('FastRegression') print('Count:', len(fast_regr)) print('Slope:', fast_regr.slope()) print('Intercept:', fast_regr.intercept()) print('Correlation:', fast_regr.correlation()) core_regr = CoreRegression() for index, arg in enumerate(args, 1): core_regr.push(index, arg) print() print('CoreRegression') print('Count:', len(core_regr)) print('Slope:', core_regr.slope()) print('Intercept:', core_regr.intercept()) print('Correlation:', core_regr.correlation())
def main(): args = list(map(float, sys.argv[1:])) print('Statistics Functions') print('Count:', len(args)) print('Mean:', mean(args)) print('Variance:', variance(args)) print('StdDev:', stddev(args)) print('Skewness:', skewness(args)) print('Kurtosis:', kurtosis(args)) exp_mean, exp_var = exp_mean_var(0.9, args) exp_cov, exp_cor = exp_cov_cor(0.9, enumerate(args, 1)) print('Exponential Moving Mean (decay=0.9):', exp_mean) print('Exponential Moving Variance (decay=0.9):', exp_var) print('Exponential Moving StdDev (decay=0.9):', exp_var**0.5) print('Exponential Moving Covariance (decay=0.9):', exp_cov) print('Exponential Moving Correlation (decay=0.9):', exp_cor) fast_stats = FastStatistics() for arg in args: fast_stats.push(arg) print() print('FastStatistics') print('Count:', len(fast_stats)) print('Mean:', fast_stats.mean()) print('Variance:', fast_stats.variance()) print('StdDev:', fast_stats.stddev()) print('Skewness:', fast_stats.skewness()) print('Kurtosis:', fast_stats.kurtosis()) core_stats = CoreStatistics() for arg in args: core_stats.push(arg) print() print('CoreStatistics') print('Count:', len(core_stats)) print('Mean:', core_stats.mean()) print('Variance:', core_stats.variance()) print('StdDev:', core_stats.stddev()) print('Skewness:', core_stats.skewness()) print('Kurtosis:', core_stats.kurtosis()) fast_exp_stats = FastExponentialStatistics() for arg in args: fast_exp_stats.push(arg) print() print('FastExponentialMovingStatistics') print('Decay Rate (default):', fast_exp_stats.decay) print('Exponential Mean:', fast_exp_stats.mean()) print('Exponential Variance:', fast_exp_stats.variance()) print('Exponential StdDev:', fast_exp_stats.stddev()) core_exp_stats = CoreExponentialStatistics() for arg in args: core_exp_stats.push(arg) print() print('CoreExponentialMovingStatistics') print('Decay Rate (default):', core_exp_stats.decay) print('Exponential Mean:', core_exp_stats.mean()) print('Exponential Variance:', core_exp_stats.variance()) print('Exponential StdDev:', core_exp_stats.stddev()) fast_regr = FastRegression() for index, arg in enumerate(args, 1): fast_regr.push(index, arg) print() print('FastRegression') print('Count:', len(fast_regr)) print('Slope:', fast_regr.slope()) print('Intercept:', fast_regr.intercept()) print('Correlation:', fast_regr.correlation()) core_regr = CoreRegression() for index, arg in enumerate(args, 1): core_regr.push(index, arg) print() print('CoreRegression') print('Count:', len(core_regr)) print('Slope:', core_regr.slope()) print('Intercept:', core_regr.intercept()) print('Correlation:', core_regr.correlation()) fast_exp_cov = FastExponentialCoveriance() for index, arg in enumerate(args, 1): fast_exp_cov.push(index, arg) print() print('FastExponentialCovariance') print('Decay Rate (default):', fast_exp_cov.decay) print('Exponential Moving Covariance:', fast_exp_cov.covariance()) print('Exponential Moving Correlation:', fast_exp_cov.correlation()) core_exp_cov = CoreExponentialCoveriance() for index, arg in enumerate(args, 1): core_exp_cov.push(index, arg) print() print('CoreExponentialCovariance') print('Decay Rate (default):', core_exp_cov.decay) print('Exponential Moving Covariance:', core_exp_cov.covariance()) print('Exponential Moving Correlation:', core_exp_cov.correlation())
print('Skewness:', skewness(args)) print('Kurtosis:', kurtosis(args)) fast_stats = FastStatistics() for arg in args: fast_stats.push(arg) print() print('FastStatistics') print('Count:', len(fast_stats)) print('Mean:', fast_stats.mean()) print('Variance:', fast_stats.variance()) print('StdDev:', fast_stats.stddev()) print('Skewness:', fast_stats.skewness()) print('Kurtosis:', fast_stats.kurtosis()) core_stats = CoreStatistics() for arg in args: core_stats.push(arg) print() print('CoreStatistics') print('Count:', len(core_stats)) print('Mean:', core_stats.mean()) print('Variance:', core_stats.variance()) print('StdDev:', core_stats.stddev()) print('Skewness:', core_stats.skewness()) print('Kurtosis:', core_stats.kurtosis())