Skip to main content

vwap

Function vwap 

Source
pub fn vwap(
    highs: &[f64],
    lows: &[f64],
    closes: &[f64],
    volumes: &[f64],
) -> Result<Vec<Option<f64>>>
Expand description

Calculate Volume Weighted Average Price (VWAP).

VWAP is the average price weighted by volume. It’s commonly used as a trading benchmark. Formula: VWAP = Σ(Typical Price × Volume) / Σ(Volume) where Typical Price = (High + Low + Close) / 3

§Arguments

  • highs - High prices
  • lows - Low prices
  • closes - Close prices
  • volumes - Trading volumes

§Returns

Vector of cumulative VWAP values.

§Example

use finance_query::indicators::vwap;

let highs = vec![102.0, 104.0, 103.0, 105.0];
let lows = vec![100.0, 101.0, 100.5, 102.0];
let closes = vec![101.0, 103.0, 102.0, 104.0];
let volumes = vec![1000.0, 1200.0, 900.0, 1500.0];

let result = vwap(&highs, &lows, &closes, &volumes).unwrap();
assert_eq!(result.len(), 4);