Skip to content

Commit

Permalink
RSI戦略の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
T.K committed Feb 9, 2024
1 parent 09b6718 commit cfdc452
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
6 changes: 3 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
assetName: "SOLUSDT"
duration: "30m"
start: "20200801"
end: "20210930"
simpleInterest: true
positionPersentage: 0.3
end: "20230930"
simpleInterest: false
positionPersentage: 0.9
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
// strategey.DonchainBacktest()
// strategey.EmaBacktest()
// strategey.SuperTrendBacktest()
strategey.RSIBryyrtBacktest()
strategey.RSIBetterBacktest()

// strategey.EmaBacktest()
// strategey.RunBacktestST()
Expand Down
2 changes: 2 additions & 0 deletions pkg/analytics/drawdown.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package analytics

import (
"fmt"
"math"
"sort"
dbquery "v1/pkg/data/query"
Expand Down Expand Up @@ -91,6 +92,7 @@ func MaxDrawdownPercent(s *execute.SignalEvents) float64 {
// TODO: Handle other sides if necessary
continue
}
fmt.Println(signal.AccountBalance)
if signal.AccountBalance > peak { // Update peak value if account balance is higher
peak = signal.AccountBalance
}
Expand Down
41 changes: 41 additions & 0 deletions pkg/execute/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ func (s *SignalEvents) CanBuy(t time.Time) bool {
return false
}

func (s *SignalEvents) CanClose(t time.Time) bool {
lenSignals := len(s.Signals)
if lenSignals == 0 {
return false
}

lastSignal := s.Signals[lenSignals-1]
if lastSignal.Side == "BUY" && lastSignal.Time.Before(t) {
return true
}
return false
}

func (s *SignalEvents) CanSell(t time.Time) bool {
lenSignals := len(s.Signals)
if lenSignals == 0 {
Expand Down Expand Up @@ -195,3 +208,31 @@ func (s *SignalEvents) Sell(strategyName string, assetName string, duration stri
s.Signals = append(s.Signals, signalEvent)
return true
}

func (s *SignalEvents) Close(strategyName string, assetName string, duration string, date time.Time, price, size float64, accountBalance float64, save bool) bool {

if !s.CanClose(date) {

return false
}
signalId := uuid.New()
signalEvent := SignalEvent{
SignalId: signalId,
Time: date,
StrategyName: strategyName,
AssetName: assetName,
Duration: duration,
Side: "SELL",
Price: price,
Size: size,
AccountBalance: accountBalance,
}

// if save {
// signalEvent.Save()

// }

s.Signals = append(s.Signals, signalEvent)
return true
}
4 changes: 2 additions & 2 deletions pkg/strategey/rsi_better.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (df *DataFrameCandle) BetterRsiStrategy(period int, buyThread float64, dcPe
sl := atr[i] * slRatio
// tp := atr[i] * tpRatio

if (values[i-1] < buyThread && values[i] <= buyThread && c[i-1] < donchain.Low[i-2] && c[i] <= donchain.Low[i-1]) && choppyEma[i] > 60 && !isBuyHolding {
if ((values[i-1] < buyThread && values[i] >= buyThread) && (c[i-1] < donchain.Low[i-2] && c[i] >= donchain.Low[i-1])) && choppyEma[i] > 60 && !isBuyHolding {
// fee := 1 - 0.01
if simple {
buySize = account.SimpleTradeSize(1)
Expand Down Expand Up @@ -194,7 +194,7 @@ func RunBetterRsiOptimize() {

}

func RSIBryyrtBacktest() {
func RSIBetterBacktest() {

df, account, _ := RadyBacktest()

Expand Down
7 changes: 4 additions & 3 deletions pkg/trader/acount.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ func NewAccount(initialBalance float64) *Account {

func (a *Account) TradeSize(persetege float64) float64 {

fee := 1 - 0.01
size := a.Balance * persetege * fee
size := a.Balance * persetege
// fmt.Println("トレードサイズ内でのアカウントバランス", a.Balance)
return size
}
Expand All @@ -26,7 +25,9 @@ func (a *Account) SimpleTradeSize(amount int) float64 {
}

func (a *Account) Buy(price, size float64) bool {
cost := price * size

fee := 1 - 0.01
cost := price * size * fee
if cost > a.Balance {
return false
}
Expand Down

0 comments on commit cfdc452

Please sign in to comment.