Esempio n. 1
0
/// <summary>
/// calculate a traditional or modified Sharpe Ratio of Return over StdDev or
/// VaR or ES
///
/// The Sharpe ratio is simply the return per unit of risk (represented by
/// variability).  In the classic case, the unit of risk is the standard
/// deviation of the returns.
/// </summary>
func SharpeRatio(Ra *utils.SlidingWindow, Rf_val float64, scale float64) (float64, error) {
	Rf, err := utils.CreateList(Rf_val, Ra.Count())
	if err != nil {
		return math.NaN(), err
	}
	xR, err := Excess(Ra, Rf)
	if err != nil {
		return math.NaN(), err
	}
	numerator := 0.0
	denominator := 0.0
	annualize := 1
	if annualize == 1 {
		denominator, err = StdDev_Annualized(Ra, scale)
		if err != nil {
			return math.NaN(), err
		}
		numerator, err = Annualized(xR, scale, true)
		if err != nil {
			return math.NaN(), err
		}
	} else {
		denominator, err = StdDev(Ra)
		if err != nil {
			return math.NaN(), err
		}
		numerator = xR.Average()
	}

	return numerator / denominator, nil
}
Esempio n. 2
0
File: capm.go Progetto: bxy09/gfstat
func Beta2(Ra, Rb *utils.SlidingWindow, Rf float64) (float64, error) {
	RfList, err := utils.CreateList(Rf, Ra.Count())
	if err != nil {
		return math.NaN(), err
	}
	return Beta(Ra, Rb, RfList)
}
Esempio n. 3
0
//= "full"
// = false
func DownsideDeviation2(Ra *utils.SlidingWindow, MAR float64) (float64, error) {
	if Ra == nil || Ra.Count() <= 0 {
		return math.NaN(), errors.New("In DownsideDeviation2, Ra == nil || Ra.Count() <= 0")
	}
	newMAR, _ := utils.CreateList(MAR, Ra.Count())
	return DownsideDeviation(Ra, newMAR)
}