From dbe6dc5f37badf8f1667779cd06a71765bdc817e Mon Sep 17 00:00:00 2001 From: keikeicheung Date: Wed, 6 Dec 2023 22:54:29 +0800 Subject: [PATCH 1/2] #983 Simulated prices provider to have random small walk logic - fixed a big jump at doWidenBidAndAsk (ric not in states) --- .../vuu/provider/simulation/SimulatedPricesProvider.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala b/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala index 6ed0f410a..b8f57b5bf 100644 --- a/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala +++ b/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala @@ -261,10 +261,10 @@ class SimulatedPricesProvider(val table: DataTable, @volatile var maxSleep: Int Map(f.Ric -> ric, f.Ask -> ask, f.Bid -> bid, f.Phase -> "C") ++ BidAskSize() } - final val MaxSpread = 100 + final val MaxSpread = 10 protected def doWidenBidAndAsk(ric: String): Map[String, Any] = { - if (!states.get(ric).contains(ric)) { + if (!states.get(ric).contains(f.Bid)) { seedStartValues(ric) } else { getState(ric) match { From 504a2f94c34590ab718bb754c744266628c1f772 Mon Sep 17 00:00:00 2001 From: keikeicheung Date: Wed, 6 Dec 2023 23:20:11 +0800 Subject: [PATCH 2/2] #983 Simulated prices provider to have random small walk logic - always round to 2 dp --- .../simulation/SimulatedPricesProvider.scala | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala b/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala index b8f57b5bf..23e6f114d 100644 --- a/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala +++ b/example/price/src/main/scala/org/finos/vuu/provider/simulation/SimulatedPricesProvider.scala @@ -89,8 +89,8 @@ class SimulatedPricesProvider(val table: DataTable, @volatile var maxSleep: Int val maxBidValue = maxBid(bid, tempAsk, spreadMultipler, priceMaxDelta) val minAskValue = minAsk(bid, tempAsk, spreadMultipler, priceMaxDelta) val maxAskValue = maxAsk(bid, tempAsk, spreadMultipler, priceMaxDelta) - val newBid = (nextRandomDouble(minBidValue, maxBidValue) * 100).round / 100.0 - val newAsk = (nextRandomDouble(minAskValue, maxAskValue) * 100).round / 100.0 + val newBid = round(nextRandomDouble(minBidValue, maxBidValue)) + val newAsk = round(nextRandomDouble(minAskValue, maxAskValue)) (newBid, newAsk) } @@ -252,8 +252,8 @@ class SimulatedPricesProvider(val table: DataTable, @volatile var maxSleep: Int val tempBid = nextRandomDouble(mid - priceMaxDelta, mid - 1) val ask = nextRandomDouble(mid + 1, mid + priceMaxDelta) val bid = if (tempBid < 0) mid else tempBid - val newBid = (bid * 100).round / 100.0 - val newAsk = (ask * 100).round / 100.0 + val newBid = round(bid) + val newAsk = round(ask) (newBid, newAsk) } protected def buildSampleRow(ric: String): Map[String, Any] = { @@ -277,8 +277,8 @@ class SimulatedPricesProvider(val table: DataTable, @volatile var maxSleep: Int else spread - val newBid = bid - activeSpread - val newAsk = ask + activeSpread + val newBid = round(bid - activeSpread) + val newAsk = round(ask + activeSpread) Map(f.Ric -> ric, f.Ask -> newAsk, f.Bid -> newBid, f.Scenario -> "widenBidAndAsk", f.Phase -> "C") ++ BidAskSize() case None => throw new Exception("shouldn't get here") } @@ -293,11 +293,15 @@ class SimulatedPricesProvider(val table: DataTable, @volatile var maxSleep: Int val bid = states.get(ric)(f.Bid).asInstanceOf[Double] val ask = states.get(ric)(f.Ask).asInstanceOf[Double] val (newBid:Double, newAsk:Double) = generateNextBidAsk(bid, ask, 10, 5, nextRandomDouble) - val last = ((ask + (newAsk - ask) / 2) * 100).round / 100.0 + val last = round(ask + (newAsk - ask) / 2) Map(f.Ric -> ric, f.Ask -> newAsk, f.Bid -> newBid, f.Scenario -> "fastTick", f.Last -> last, f.Phase -> "C") ++ BidAskSize() } } + private def round(value: Double): Double = { + (value * 100).round / 100.0 + } + protected def doOpenTick(ric: String): Map[String, Any] = { if (!states.get(ric).contains(f.Bid)) @@ -306,7 +310,7 @@ class SimulatedPricesProvider(val table: DataTable, @volatile var maxSleep: Int val bid = states.get(ric)(f.Bid).asInstanceOf[Double] val ask = states.get(ric)(f.Ask).asInstanceOf[Double] val (newBid: Double, newAsk: Double) = generateNextBidAsk(bid, ask, 8, 4, nextRandomDouble) - val open = ask + (newAsk - ask) / 2 + val open = round(ask + (newAsk - ask) / 2) Map(f.Ric -> ric, f.Scenario -> "open", f.Open -> open, f.Phase -> "O") ++ BidAskSize() } }