Răsfoiți Sursa

Strategy

- rm old strategies
- add PPO strategy
Alexey Kim 6 zile în urmă
părinte
comite
d8d703c36a

+ 0 - 18
probability.go

@@ -22,30 +22,12 @@ func (x *Probability) Next(n int) (*Probability_Stamp, bool) {
 	return x.Stamps[n], true
 }
 
-func IsAction(action Action, oneOf ...Action) bool {
-	if oneOf == nil || len(oneOf) == 0 {
-		return false
-	}
-
-	for i := range oneOf {
-		if action == oneOf[i] {
-			return true
-		}
-	}
-
-	return false
-}
-
 func ActionToSide(action Action) Side {
 	switch action {
-	case Action_DOUBLE_SELL:
-		return SHORT
 	case Action_SELL:
 		return SHORT
 	case Action_BUY:
 		return LONG
-	case Action_DOUBLE_BUY:
-		return LONG
 	default:
 		return BASE
 	}

+ 2 - 7
strategy/alpaca/stocks_dqn_seed_250523_161749/strategy.go → strategy/alpaca/ppo_250625/strategy.go

@@ -77,7 +77,7 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 
 	for i := range orders {
 		if util.IsLongOrder(orders[i], strategy) &&
-			sentio.IsAction(turn.Action, sentio.Action_HOLD, sentio.Action_SELL, sentio.Action_DOUBLE_SELL) &&
+			sentio.Action_SELL == turn.Action &&
 			ts.Before(time.Now()) {
 			if _, err = market.CloseOrder(orders[i], nil); err != nil {
 				return err
@@ -88,7 +88,7 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 		}
 
 		if util.IsShortOrder(orders[i], strategy) &&
-			sentio.IsAction(turn.Action, sentio.Action_HOLD, sentio.Action_BUY, sentio.Action_DOUBLE_BUY) &&
+			sentio.Action_BUY == turn.Action &&
 			ts.Before(time.Now()) {
 			if _, err = market.CloseOrder(orders[i], nil); err != nil {
 				return err
@@ -122,11 +122,6 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 		return nil
 	}
 
-	// Prevent Market.CreateOrder while probability is not clear
-	if sentio.Action_HOLD == turn.Action || ts.After(time.Now()) {
-		return nil
-	}
-
 	if quotes, err = market.Quotes(); err != nil {
 		return err
 	}

+ 0 - 135
strategy/alpaca/stocks_dqn_seed/strategy.go

@@ -1,135 +0,0 @@
-package main
-
-import (
-	"git.beejay.kim/Gshopper/sentio"
-	"git.beejay.kim/Gshopper/sentio/util"
-	"time"
-)
-
-var Strategy = qqq{}
-
-type qqq struct{}
-
-func (strategy qqq) Name() string {
-	return "Alpaca: QQQ [TQQQ : SQQQ]"
-}
-
-func (strategy qqq) Model() string {
-	return "stocks_dqn_seed"
-}
-
-func (strategy qqq) MarketId() string {
-	return "alpaca"
-}
-
-func (strategy qqq) Interval() uint8 {
-	return 1
-}
-
-func (strategy qqq) PositionSymbols() map[sentio.Side]string {
-	return map[sentio.Side]string{
-		sentio.BASE:  "QQQ",
-		sentio.LONG:  "TQQQ",
-		sentio.SHORT: "SQQQ",
-	}
-}
-
-func (strategy qqq) MaxTradeDuration() time.Duration {
-	return time.Duration(strategy.Interval()) * time.Minute * 3
-}
-
-func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.RiskManager) error {
-	if market == nil || turn == nil {
-		return nil
-	}
-
-	var (
-		now     = market.Clock().Now()
-		symbols = util.Symbols(strategy)
-		quotes  map[string]sentio.Quote
-		orders  []sentio.Order
-		err     error
-	)
-
-	// skip too early orders or late orders
-	if (now.Hour() == 9 && now.Minute() < 45) || now.Hour() > 15 {
-		return nil
-	}
-
-	// close all orders before market close
-	if now.Hour() == 15 && now.Minute() > 55 {
-		return util.CloseAllOrders(market, strategy)
-	}
-
-	// retrieve running orders
-	if orders, err = market.Orders(sentio.OrderListCriteria{
-		Status:  "open",
-		Symbols: symbols,
-	}); err != nil {
-		return err
-	}
-
-	// update stoplosses or close running orders
-	var (
-		ts              = turn.Time.AsTime().Round(time.Minute)
-		hasClosedOrders = false
-	)
-
-	for i := range orders {
-		if util.IsLongOrder(orders[i], strategy) &&
-			sentio.IsAction(turn.Action, sentio.Action_HOLD, sentio.Action_SELL, sentio.Action_DOUBLE_SELL) &&
-			ts.Before(time.Now()) {
-			if _, err = market.CloseOrder(orders[i], nil); err != nil {
-				return err
-			}
-
-			hasClosedOrders = true
-			continue
-		}
-
-		if util.IsShortOrder(orders[i], strategy) &&
-			sentio.IsAction(turn.Action, sentio.Action_HOLD, sentio.Action_BUY, sentio.Action_DOUBLE_BUY) &&
-			ts.Before(time.Now()) {
-			if _, err = market.CloseOrder(orders[i], nil); err != nil {
-				return err
-			}
-
-			hasClosedOrders = true
-			continue
-		}
-
-		if orders[i].GetCreatedAt().Round(time.Minute).Add(strategy.MaxTradeDuration()).Before(time.Now()) {
-			if _, err = market.CloseOrder(orders[i], nil); err != nil {
-				return err
-			}
-
-			hasClosedOrders = true
-			continue
-		}
-
-		if err = market.UpdateOrder(orders[i].GetId(), rs); err != nil {
-			return err
-		}
-	}
-
-	// Prevent new orders if we just closed one
-	if hasClosedOrders || len(orders) > 0 {
-		return nil
-	}
-
-	// Prevent BUYs on closing market
-	if now.Hour() == 15 && now.Minute() > 45 {
-		return nil
-	}
-
-	// Prevent Market.CreateOrder while probability is not clear
-	if sentio.Action_HOLD == turn.Action || ts.After(time.Now()) {
-		return nil
-	}
-
-	if quotes, err = market.Quotes(); err != nil {
-		return err
-	}
-
-	return util.CreateOrder(market, strategy, turn.Action, quotes, rs)
-}