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>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user