113c6dfd71
11 funciones puras con implementación real: SMA, EMA, RSI, BollingerBands, VWAP, LogReturn, AnnualizedVolatility, SharpeRatio, MaxDrawdown, NormalizeOHLCV, TickToOHLCV 4 funciones impuras (stubs): FetchOHLCV, StreamTicks, WriteOHLCVToParquet, LoadOHLCVFromDuckDB Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
23 lines
574 B
Go
23 lines
574 B
Go
package finance
|
|
|
|
// SMA calcula la media movil simple de data con el periodo dado.
|
|
// Retorna un slice de longitud len(data) donde los primeros period-1
|
|
// elementos son 0 (sin datos suficientes).
|
|
func SMA(data []float64, period int) []float64 {
|
|
n := len(data)
|
|
result := make([]float64, n)
|
|
if period <= 0 || period > n {
|
|
return result
|
|
}
|
|
var sum float64
|
|
for i := 0; i < period; i++ {
|
|
sum += data[i]
|
|
}
|
|
result[period-1] = sum / float64(period)
|
|
for i := period; i < n; i++ {
|
|
sum += data[i] - data[i-period]
|
|
result[i] = sum / float64(period)
|
|
}
|
|
return result
|
|
}
|