vexity 0.0.4

Tiny scripting language for hacking on abstractions of financial markets.
Documentation
# A basic example of market data
let mkt_data = [
  { time: "11:00", price: 4880.50, volume: 25010 },
  { time: "11:01", price: 4883.25, volume: 11737 },
  { time: "11:02", price: 4881.75, volume: 38914 },
  { time: "11:03", price: 4883.50, volume: 34819 },
  { time: "11:04", price: 4885.00, volume: 89312 },
  { time: "11:05", price: 4885.75, volume: 62384 },
  { time: "11:06", price: 4888.00, volume: 58192 },
  { time: "11:07", price: 4890.50, volume: 57191 },
  { time: "11:08", price: 4891.25, volume: 37371 },
  { time: "11:09", price: 4887.75, volume: 67812 },
  { time: "11:10", price: 4888.50, volume: 71231 },
  { time: "11:11", price: 4889.75, volume: 47712 },
  { time: "11:12", price: 4891.25, volume: 57912 },
  { time: "11:13", price: 4893.50, volume: 27912 },
  { time: "11:14", price: 4894.75, volume: 40412 },
  { time: "11:15", price: 4895.25, volume: 31731 }
]

# Smooth the price data using a simple
# moving average with a window length of 2
let sma_smoothed = sma_batch(mkt_data.map(|x| x.price), 2)
print(sma_smoothed)

# Smooth the price data using a volume weighted
# moving average with a window length of 5
let price_data = mkt_data.map(|x| x.price)
let volume_data = mkt_data.map(|x| x.volume)
let vwma_smoothed = vwma_batch(price_data, volume_data, 5)
print(vwma_smoothed)

# Calculate the least squares average price of
# the market data. Treating the dataset as one
# data window (widnow length of 15).
let least_squares_avg_price = lsma(price_data)
print(least_squares_avg_price)