Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#983 Simulated prices provider to have random small walk logic - fixe… #1055

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -252,19 +252,19 @@ 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] = {
val(bid: Double, ask:Double) = initBidAsk(5,nextRandomDouble)
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 {
Expand All @@ -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")
}
Expand All @@ -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))
Expand All @@ -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()
}
}
Expand Down
Loading