https://github.com/bukosabino/ta
Tip revision: 40bcbb1d2ef7ad5fad99ced854972afd122076f6 authored by Bukosabino on 05 May 2018, 10:40:09 UTC
kst modifications; https://github.com/bukosabino/ta/issues/1
kst modifications; https://github.com/bukosabino/ta/issues/1
Tip revision: 40bcbb1
others.py
# -*- coding: utf-8 -*-
"""
.. module:: others
:synopsis: Others Indicators.
.. moduleauthor:: Dario Lopez Padial (Bukosabino)
"""
import pandas as pd
def daily_return(close, fillna=False):
"""Daily Return (DR)
Args:
close(pandas.Series): dataset 'Close' column.
fillna(bool): if True, fill nan values.
Returns:
pandas.Series: New feature generated.
"""
dr = (close / close.shift(1)) - 1
dr *= 100
if fillna:
dr = dr.fillna(0)
return pd.Series(dr, name='d_ret')
def cumulative_return(close, fillna=False):
"""Cumulative Return (CR)
Args:
close(pandas.Series): dataset 'Close' column.
fillna(bool): if True, fill nan values.
Returns:
pandas.Series: New feature generated.
"""
cr = (close / close.iloc[0]) - 1
cr *= 100
if fillna:
cr = cr.fillna(method='backfill')
return pd.Series(cr, name='cum_ret')