Files
fn_registry/functions/finance/vwap.go
T
egutierrez 113c6dfd71 feat: 15 funciones finance — indicadores, riesgo e IO de mercado
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>
2026-03-28 02:23:31 +01:00

20 lines
459 B
Go

package finance
// VWAP calcula el Volume Weighted Average Price.
// prices y volumes deben tener la misma longitud.
// Retorna 0 si el volumen total es 0 o los slices estan vacios.
func VWAP(prices, volumes []float64) float64 {
if len(prices) == 0 || len(prices) != len(volumes) {
return 0
}
var cumPV, cumV float64
for i := range prices {
cumPV += prices[i] * volumes[i]
cumV += volumes[i]
}
if cumV == 0 {
return 0
}
return cumPV / cumV
}