@@ -211,24 +211,27 @@ func (s *Strategy) generateSubmitOrders(ctx context.Context) ([]types.SubmitOrde
211
211
midPrice := ticker .Buy .Add (ticker .Sell ).Div (fixedpoint .NewFromFloat (2.0 ))
212
212
log .Infof ("mid price: %+v" , midPrice )
213
213
214
- // calcualte skew by the difference between base weight and target weight
215
- baseValue := baseBalance .Total ().Mul (midPrice )
216
- baseWeight := baseValue .Div (baseValue .Add (quoteBalance .Total ()))
217
- skew := s .SkewFactor .Mul (baseWeight .Sub (s .TargetWeight ))
218
-
219
214
if s .ATRMultiplier .Float64 () > 0 {
220
215
atr := fixedpoint .NewFromFloat (s .atr .Last ())
221
216
log .Infof ("atr: %s" , atr .String ())
222
217
s .HalfSpreadRatio = s .ATRMultiplier .Mul (atr ).Div (midPrice )
223
218
log .Infof ("half spread ratio: %s" , s .HalfSpreadRatio .String ())
224
219
}
225
220
221
+ // calcualte skew by the difference between base weight and target weight
222
+ baseValue := baseBalance .Total ().Mul (midPrice )
223
+ baseWeight := baseValue .Div (baseValue .Add (quoteBalance .Total ()))
224
+ skew := s .SkewFactor .Mul (s .HalfSpreadRatio ).Mul (baseWeight .Sub (s .TargetWeight ))
225
+
226
+ // let the skew be in the range of [-r, r]
227
+ skew = skew .Clamp (s .HalfSpreadRatio .Neg (), s .HalfSpreadRatio )
228
+
226
229
// calculate bid and ask price
227
- // bid price = mid price * (1 - max(r + skew, 0 ))
230
+ // bid price = mid price * (1 - r - skew))
228
231
bidSpreadRatio := fixedpoint .Max (s .HalfSpreadRatio .Add (skew ), fixedpoint .Zero )
229
232
bidPrice := midPrice .Mul (fixedpoint .One .Sub (bidSpreadRatio ))
230
233
log .Infof ("bid price: %s" , bidPrice .String ())
231
- // ask price = mid price * (1 + max( r - skew, 0 ))
234
+ // ask price = mid price * (1 + r - skew))
232
235
askSrasedRatio := fixedpoint .Max (s .HalfSpreadRatio .Sub (skew ), fixedpoint .Zero )
233
236
askPrice := midPrice .Mul (fixedpoint .One .Add (askSrasedRatio ))
234
237
log .Infof ("ask price: %s" , askPrice .String ())
0 commit comments