当前位置:网站首页>[backtrader source code analysis 7] analysis of the functions for calculating mean value, variance and standard deviation in mathsupport in backtrader (with low gold content)

[backtrader source code analysis 7] analysis of the functions for calculating mean value, variance and standard deviation in mathsupport in backtrader (with low gold content)

2022-06-13 00:49:00 Python's path to becoming a God

The previous articles tried to optimize backtrader Several time processing functions to improve efficiency , Use cython It can improve the efficiency of a single function, but in the whole, after the efficiency decreases and leads to failure , I tried again numba To improve those time processing functions , And I failed . At present, there is no better method to improve those time conversion functions , Which great God has a good way to help , Help each other . You can pay .
Next, this article analyzes several mathematical support functions : Average 、 variance 、 Standard deviation , On the whole, there is no gold content . In the next article , Focus on parsing a key source file :metabase.py

#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import math

#  Look at the , These functions are mainly used to calculate some indicators , Not used in the main body , Comment on , Come back later to see if you need to use cython improvement , There is no need to improve for the time being .
#  But these functions can actually be considered numpy To improve the ,numpy Specific functions are provided to calculate the mean value , Calculate the standard deviation 

#  This calculation is the average , With a parameter bessel, Used to determine whether the value of the denominator subtracts one... When calculating the average value . Molecular use math.fsum For calculation and 
def average(x, bessel=False):
    '''
    Args:
      x: iterable with len

      oneless: (default ``False``) reduces the length of the array for the
                division.

    Returns:
      A float wi

原网站

版权声明
本文为[Python's path to becoming a God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280600498211.html