strategy:irr: clean up

strategy:irr: clean up

strategy:irr: clean up

strategy:irr: clean up
This commit is contained in:
austin362667 2022-10-19 17:24:27 +08:00
parent 614209e9fd
commit 778a3d8be1
2 changed files with 7 additions and 23 deletions

View File

@ -22,18 +22,10 @@ exchangeStrategies:
irr:
symbol: BTCBUSD
# in milliseconds(ms)
# must > 10 ms
hftInterval: 1000
# indicator window
window: 0
# maxima position in USD
amount: 100
# qty per trade
quantity: 0.001
# minProfit pips in USD
pips: 0.0
# alpha1: negative return reversion
NR: true
# alpha2: moving average reversion
MR: true
# Draw pnl
drawGraph: true
graphPNLPath: "./pnl.png"

View File

@ -48,15 +48,9 @@ type Strategy struct {
orderExecutor *bbgo.GeneralOrderExecutor
bbgo.QuantityOrAmount
MinProfit float64 `json:"pips"`
Interval int `json:"hftInterval"`
NR bool `json:"NR"`
MR bool `json:"MR"`
Interval int `json:"hftInterval"`
// for back-test
Nrr *NRR
Ma *indicator.SMA
// realtime book ticker to submit order
obBuyPrice uint64
obSellPrice uint64
@ -399,9 +393,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
log.Infof("box ended at price: %f with time length: %d", boxClosePrice, boxCounter)
// box ending, should re-balance position
nirr := fixedpoint.NewFromFloat(((boxOpenPrice - boxClosePrice) / boxOpenPrice) / (float64(boxCounter) + 1))
qty := s.QuantityOrAmount.CalculateQuantity(fixedpoint.Value(boxClosePrice))
qty = qty.Mul(nirr.Abs().Div(fixedpoint.NewFromInt(1000)))
log.Infof("Alpha: %f with Diff Qty: %f", nirr.Float64(), qty.Float64())
log.Infof("Alpha: %f", nirr.Float64())
if nirr.Float64() < 0 {
_, err := s.orderExecutor.SubmitOrders(context.Background(), types.SubmitOrder{
Symbol: s.Symbol,
@ -409,7 +401,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
Quantity: s.Quantity,
Type: types.OrderTypeLimitMaker,
Price: fixedpoint.NewFromFloat(float64(s.obSellPrice)),
Tag: "irr re-balance: sell",
Tag: "irrSell",
})
if err != nil {
log.WithError(err)
@ -421,7 +413,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
Quantity: s.Quantity,
Type: types.OrderTypeLimitMaker,
Price: fixedpoint.NewFromFloat(float64(s.obBuyPrice)),
Tag: "irr re-balance: buy",
Tag: "irrBuy",
})
if err != nil {
log.WithError(err)
@ -452,7 +444,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
for {
select {
case <-intervalOpenTicker.C:
time.Sleep(time.Duration(s.Interval/10) * time.Millisecond)
time.Sleep(10 * time.Millisecond)
log.Infof("kline open time @ %s", time.Now().Format("2006-01-02 15:04:05.000000"))
if s.currentTradePrice > 0 && s.closePrice > 0 {