Open sxczlhq opened 2 years ago
ps: returns.add(1).cumprod() - 1 ,leads to issues 178.
The following is the revised code after testing, please refer to: ++++++++ stats.py +++++++++++++ def compsum(returns): """Calculates rolling compounded returns""" return returns.cumsum()
def comp(returns): """Calculates total compounded returns""" return returns.sum()
def comprod(returns): """Calculates rolling compounded returns""" return returns.add(1).cumprod() - 1
def prod(returns): """Calculates total compounded returns""" return returns.add(1).prod() - 1
+++++++++++++++ utils.py ++++++++++++++++ def to_prices(returns, base=1e5): """Converts returns series to price data""" returns = returns.copy().fillna(0).replace( [_np.inf, -_np.inf], float('NaN')) return base + base * _stats.comprod(returns)
In stats.py,about as
def compsum(returns): """Calculates rolling compounded returns""" return returns.add(1).cumprod() - 1
def comp(returns): """Calculates total compounded returns""" return returns.add(1).prod() - 1
first,The function name is compsum, but cumprod() is used in the calculation process. second,It is not appropriate to use cumulative multiplication calculation in an investment cycle. so ,I suggest the following formula:
def compsum(returns): """Calculates rolling compounded returns""" return returns.cumsum()
def comp(returns): """Calculates total compounded returns""" return returns.sum()