Skip to content

Commit

Permalink
backtest only 1 position
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Oct 19, 2024
1 parent d146fca commit 440d16a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dev/src/dev/backtest/backtest.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
:atr [5.0 5.0 5.0 5.0
5.0 5.0 5.0
5.0 5.0 5.0 5.0 5.0]
:entry [:flat :long nil nil
:entry [:long :long nil nil
:long :flat :flat
:short nil nil nil]}))

Expand Down
13 changes: 9 additions & 4 deletions src/quanta/trade/backtest/commander.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
[nano-id.core :refer [nano-id]]
[quanta.trade.commander :as p]))

(defn has-position-in [position-a p]
(let [asset (:asset p)]
(some #(= asset (:asset %)) (vals @position-a))))

(defn open-position! [position-a trade-a p]
(let [p (select-keys p [:id :asset :side :qty :entry-price :entry-date :entry-idx])]
(swap! position-a assoc (:id p) p)
(swap! trade-a conj {:open p})
(when (not (has-position-in position-a p))
(let [p (select-keys p [:id :asset :side :qty :entry-price :entry-date :entry-idx])]
(swap! position-a assoc (:id p) p)
(swap! trade-a conj {:open p})
;(tm/log! (str "positon open: " p))
{:open p}))
{:open p})))

(defn close-position! [position-a trade-a roundtrip-a exit-p]
(let [id (:id exit-p)
Expand Down

0 comments on commit 440d16a

Please sign in to comment.