Exemple #1
0
func PainRatio(Ra *utils.SlidingWindow, Rf float64, scale float64) (float64, error) {
	PI, err := PainIndex(Ra)
	if err != nil {
		return math.NaN(), err
	}
	n := Ra.Count()
	add_Sliding, err := utils.Add(1.0, Ra)
	if err != nil {
		return math.NaN(), err
	}
	prod_Sliding, err := utils.Prod(add_Sliding)
	if err != nil {
		return math.NaN(), err
	}
	Rp := math.Pow(prod_Sliding, float64(scale)/float64(n)) - 1.0
	Rf = Rf * scale
	return (Rp - Rf) / PI, nil
}
Exemple #2
0
/// <param name="returns"></param>
/// <param name="geometric"></param>
/// <returns></returns>
func Cumulative(returns *utils.SlidingWindow, geometric bool) (float64, error) {
	if returns == nil {
		return math.NaN(), errors.New("Cumulative Sliding window is Nil !!!")
	}
	if returns.Count() == 0 {
		return math.NaN(), errors.New("Cumulative Count == 0 !!")
	}
	if !geometric {
		return (returns.Sum()), nil
	} else {
		add_data, err := utils.Add(1.0, returns)
		if err != nil {
			return math.NaN(), err
		}
		prod_data, err := utils.Prod(add_data)
		if err != nil {
			return math.NaN(), err
		}
		return (prod_data - 1.0), nil
	}
}
Exemple #3
0
/// <param name="returns"></param>
/// <param name="scale"></param>
/// <param name="geometric"></param>
/// <returns></returns>
func Annualized(returns *utils.SlidingWindow, scale float64, geometric bool) (float64, error) {
	if returns == nil {
		return math.NaN(), errors.New("Returns Utils Sliding Window is nil")
	}
	if returns.Count() == 0 {
		return math.NaN(), errors.New("Returns Windows content is Zero")
	}
	n := returns.Count()
	if geometric {
		add_Sliding, err := utils.Add(1.0, returns)
		if err != nil {
			return math.NaN(), err
		}
		prod_Data, err := utils.Prod(add_Sliding)
		if err != nil {
			return math.NaN(), err
		}
		return math.Pow(prod_Data, float64(scale)/float64(n)) - 1.0, nil
	} else {
		return returns.Average() * float64(scale), nil
	}
}