Added vwat info to the features.db.
This commit is contained in:
+12
-4
@@ -92,10 +92,10 @@ func (a *Aggregator) flushBucket() {
|
||||
|
||||
_, err := a.featDB.Exec(`
|
||||
INSERT OR IGNORE INTO five_second_features
|
||||
(timestamp, log_return, realized_vol, ofi, volume_sum, close_price)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
(timestamp, log_return, realized_vol, ofi, volume_sum, close_price, vwap)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`, bucket.Timestamp, bucket.LogReturn, bucket.RealizedVol,
|
||||
bucket.OFI, bucket.VolumeSum, bucket.ClosePrice)
|
||||
bucket.OFI, bucket.VolumeSum, bucket.ClosePrice, bucket.VWAP)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("[aggregator] Failed to write feature bucket: %v", err)
|
||||
@@ -118,10 +118,12 @@ func (a *Aggregator) computeFeatures(ticks []Tick) FeatureBucket {
|
||||
}
|
||||
logReturn := math.Log(closePrice / refPrice)
|
||||
|
||||
// Order Flow Imbalance (OFI) and total volume
|
||||
// Order Flow Imbalance (OFI), total volume, and sum of price * volume
|
||||
var buyVol, sellVol, volumeSum float64
|
||||
var priceVolumeSum float64
|
||||
for _, t := range ticks {
|
||||
volumeSum += t.Volume
|
||||
priceVolumeSum += t.Price * t.Volume
|
||||
if t.Side == "Buy" {
|
||||
buyVol += t.Volume
|
||||
} else {
|
||||
@@ -130,6 +132,11 @@ func (a *Aggregator) computeFeatures(ticks []Tick) FeatureBucket {
|
||||
}
|
||||
ofi := buyVol - sellVol
|
||||
|
||||
vwap := closePrice
|
||||
if volumeSum > 0 {
|
||||
vwap = priceVolumeSum / volumeSum
|
||||
}
|
||||
|
||||
// Realized volatility: standard deviation of tick-to-tick log returns
|
||||
realizedVol := 0.0
|
||||
if n > 1 {
|
||||
@@ -164,5 +171,6 @@ func (a *Aggregator) computeFeatures(ticks []Tick) FeatureBucket {
|
||||
OFI: ofi,
|
||||
VolumeSum: volumeSum,
|
||||
ClosePrice: closePrice,
|
||||
VWAP: vwap,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user