Skip to content

Commit

Permalink
fix(backtesting): change portfolio calc for shorting
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito committed Mar 20, 2023
1 parent 768f81e commit 1cc88c2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion exchange/paperwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,14 @@ func (p *PaperWallet) OnCandle(candle model.Candle) {
for asset, info := range p.assets {
amount := info.Free + info.Lock
pair := strings.ToUpper(asset + p.baseCoin)
total += amount * p.lastCandle[pair].Close
if amount < 0 {
v := math.Abs(amount)
liquid := 2*v*p.avgShortPrice[pair] - v*p.lastCandle[pair].Close
total += liquid
} else {
total += amount * p.lastCandle[pair].Close
}

p.assetValues[asset] = append(p.assetValues[asset], AssetValue{
Time: candle.Time,
Value: amount * p.lastCandle[pair].Close,
Expand Down

0 comments on commit 1cc88c2

Please sign in to comment.