Permalink
Browse files

価格を釣り上げたい

  • Loading branch information...
ken39arg committed Aug 2, 2018
1 parent c942798 commit 3673e6542588d1d01dfa9c4bef7454595a1f4f3f
Showing with 16 additions and 3 deletions.
  1. +2 −2 bench/context.go
  2. +14 −1 bench/investor.go
@@ -232,9 +232,9 @@ func (c *Context) Next() ([]Task, error) {
}
var investor Investor
if i%2 == 1 {
investor = NewRandomInvestor(cl, c.lastTrade.Price*1000, 0, unitamount, c.lastTrade.Price-1)
investor = NewRandomInvestor(cl, c.lastTrade.Price*1000, 0, unitamount, c.lastTrade.Price)
} else {
investor = NewRandomInvestor(cl, 1, unitamount*100, unitamount, c.lastTrade.Price+1)
investor = NewRandomInvestor(cl, 1, unitamount*100, unitamount, c.lastTrade.Price+5)
}
tasks = append(tasks, NewExecTask(func(_ context.Context) error {
c.isubank.AddCredit(investor.BankID(), investor.Credit())
@@ -2,6 +2,7 @@ package bench
import (
"context"
"math"
"math/rand"
"strings"
"sync"
@@ -224,7 +225,8 @@ func (i *RandomInvestor) Next(trades []Trade) Task {
task.Add(i.UpdateBuyOrders())
r := rand.Intn(10)
amount := rand.Int63n(i.unitamount) + 1
price := rand.Int63n(i.unitprice/2) - (i.unitprice / 4) + trades[0].Price
rate := rand.Float64()*0.3 + 0.9 // 0.9 - 1.2 までの値をつける
price := int64(math.Floor(float64(trades[0].Price) * rate))
if price <= 0 {
price += i.unitprice
}
@@ -233,7 +235,12 @@ func (i *RandomInvestor) Next(trades []Trade) Task {
} else if r < 6 {
// このターンは買う
task.Add(NewExecTask(func(ctx context.Context) error {
i.mux.Lock()
if i.credit < price*amount {
amount = i.credit / price
}
i.mux.Unlock()
if amount <= 0 {
// 資金がない
return ErrNoScore
}
@@ -243,23 +250,29 @@ func (i *RandomInvestor) Next(trades []Trade) Task {
}
return err
}
i.mux.Lock()
i.buyorder++
i.mux.Unlock()
return nil
}, PostBuyOrdersScore))
} else {
// このターンは売る
task.Add(NewExecTask(func(ctx context.Context) error {
i.mux.Lock()
if i.isu < amount {
amount = i.isu
}
i.mux.Unlock()
if amount <= 0 {
// 売る椅子がない
return ErrNoScore
}
if err := i.c.AddSellOrder(amount, price); err != nil {
return err
}
i.mux.Lock()
i.sellorder++
i.mux.Unlock()
return nil
}, PostSellOrdersScore))
}

0 comments on commit 3673e65

Please sign in to comment.