mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
strategy:irr: clean up
strategy:irr: clean up strategy:irr: clean up strategy:irr: clean up
This commit is contained in:
parent
614209e9fd
commit
778a3d8be1
|
@ -22,18 +22,10 @@ exchangeStrategies:
|
||||||
irr:
|
irr:
|
||||||
symbol: BTCBUSD
|
symbol: BTCBUSD
|
||||||
# in milliseconds(ms)
|
# in milliseconds(ms)
|
||||||
|
# must > 10 ms
|
||||||
hftInterval: 1000
|
hftInterval: 1000
|
||||||
# indicator window
|
# qty per trade
|
||||||
window: 0
|
|
||||||
# maxima position in USD
|
|
||||||
amount: 100
|
|
||||||
quantity: 0.001
|
quantity: 0.001
|
||||||
# minProfit pips in USD
|
|
||||||
pips: 0.0
|
|
||||||
# alpha1: negative return reversion
|
|
||||||
NR: true
|
|
||||||
# alpha2: moving average reversion
|
|
||||||
MR: true
|
|
||||||
# Draw pnl
|
# Draw pnl
|
||||||
drawGraph: true
|
drawGraph: true
|
||||||
graphPNLPath: "./pnl.png"
|
graphPNLPath: "./pnl.png"
|
||||||
|
|
|
@ -48,15 +48,9 @@ type Strategy struct {
|
||||||
orderExecutor *bbgo.GeneralOrderExecutor
|
orderExecutor *bbgo.GeneralOrderExecutor
|
||||||
|
|
||||||
bbgo.QuantityOrAmount
|
bbgo.QuantityOrAmount
|
||||||
MinProfit float64 `json:"pips"`
|
|
||||||
|
|
||||||
Interval int `json:"hftInterval"`
|
Interval int `json:"hftInterval"`
|
||||||
NR bool `json:"NR"`
|
|
||||||
MR bool `json:"MR"`
|
|
||||||
|
|
||||||
// for back-test
|
|
||||||
Nrr *NRR
|
|
||||||
Ma *indicator.SMA
|
|
||||||
// realtime book ticker to submit order
|
// realtime book ticker to submit order
|
||||||
obBuyPrice uint64
|
obBuyPrice uint64
|
||||||
obSellPrice 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)
|
log.Infof("box ended at price: %f with time length: %d", boxClosePrice, boxCounter)
|
||||||
// box ending, should re-balance position
|
// box ending, should re-balance position
|
||||||
nirr := fixedpoint.NewFromFloat(((boxOpenPrice - boxClosePrice) / boxOpenPrice) / (float64(boxCounter) + 1))
|
nirr := fixedpoint.NewFromFloat(((boxOpenPrice - boxClosePrice) / boxOpenPrice) / (float64(boxCounter) + 1))
|
||||||
qty := s.QuantityOrAmount.CalculateQuantity(fixedpoint.Value(boxClosePrice))
|
log.Infof("Alpha: %f", nirr.Float64())
|
||||||
qty = qty.Mul(nirr.Abs().Div(fixedpoint.NewFromInt(1000)))
|
|
||||||
log.Infof("Alpha: %f with Diff Qty: %f", nirr.Float64(), qty.Float64())
|
|
||||||
if nirr.Float64() < 0 {
|
if nirr.Float64() < 0 {
|
||||||
_, err := s.orderExecutor.SubmitOrders(context.Background(), types.SubmitOrder{
|
_, err := s.orderExecutor.SubmitOrders(context.Background(), types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
|
@ -409,7 +401,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
Quantity: s.Quantity,
|
Quantity: s.Quantity,
|
||||||
Type: types.OrderTypeLimitMaker,
|
Type: types.OrderTypeLimitMaker,
|
||||||
Price: fixedpoint.NewFromFloat(float64(s.obSellPrice)),
|
Price: fixedpoint.NewFromFloat(float64(s.obSellPrice)),
|
||||||
Tag: "irr re-balance: sell",
|
Tag: "irrSell",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err)
|
log.WithError(err)
|
||||||
|
@ -421,7 +413,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
Quantity: s.Quantity,
|
Quantity: s.Quantity,
|
||||||
Type: types.OrderTypeLimitMaker,
|
Type: types.OrderTypeLimitMaker,
|
||||||
Price: fixedpoint.NewFromFloat(float64(s.obBuyPrice)),
|
Price: fixedpoint.NewFromFloat(float64(s.obBuyPrice)),
|
||||||
Tag: "irr re-balance: buy",
|
Tag: "irrBuy",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err)
|
log.WithError(err)
|
||||||
|
@ -452,7 +444,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-intervalOpenTicker.C:
|
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"))
|
log.Infof("kline open time @ %s", time.Now().Format("2006-01-02 15:04:05.000000"))
|
||||||
|
|
||||||
if s.currentTradePrice > 0 && s.closePrice > 0 {
|
if s.currentTradePrice > 0 && s.closePrice > 0 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user