Amazing Synthetic Trading Class

Apr 28, 2023 | Python

Synthetic Trading Class

Just spent a week in Newark Ohio working on creating this new class to track and monitor synthetic trades so that decisions can be made from the status of the equity curve.  This class contains three methods, and the module includes two additional functions.


Class methods are:

  1. calcDailyEquity
  2. setSynthTradeInfo
  3. __inti__

Module includes:

  1. calcEquCurveRetAndRec
  2. calcSynthTotEquity functions.

Here is an example of what you can do with this:


Here is the code from a simple ES Mean Reversion System

# This module turns trading on and off based on the retracement and recovery of the equity curve
if curMarket == 0:
if len(synthEquity) > 0: print(myDate[curBar],” “, synthEquity[-1])
prevStopTrading = stopTrading
equCurveRet,equCurveRec = calcEquCurveRetandRec(synthEquity,100,equityAnchor)
if equCurveRet >= 0.10 and stopTrading == False:
stopTrading = True
equityAnchor = len(synthEquity)
print(myDate[curBar],”, stopTrading,”,equCurveRet)
equCurveRet,equCurveRec = calcEquCurveRetandRec(synthEquity,100,equityAnchor)
if stopTrading == True and equCurveRec >= 0.10:
stopTrading = False
equityAnchor = len(synthEquity)
print(myDate[curBar],”, startTrading,”,equCurveRec,”,”,equityAnchor)
synthMP = 0
if len(synthTrade[curMarket].mp) != 0:
synthMP = synthTrade[curMarket].mp[-1]

# Now you have to weave your synthetic orders inside the real order directives

if mp < 1 and dnCloses == 2 and stopTrading == False:
price = myOpen[D]
tradeName = “ESBuyNDC”
numShares = posSize

if synthMP < 1 and dnCloses == 2: price = myOpen[D] tempMP = 1 # print(myDate[curBar],” “,mySymbol,” Buy @ “,price,” “,tempMP) synthMP = synthTrade[curMarket].setSynthTradeInfo(‘l’,tempMP,myDate[curBar],curBar,posSize,price) # Long Exits if mp == 1 and barsSinceEntry > 4:
price =myOpen[D]
tradeName = “4thDayOut”
numShares = curShares
exitPosition(price, curShares, tradeName, sysMarkDict)

if synthMP == 1 and synthTrade[curMarket].barsSinceEntry > 4:
price = myOpen[D]
tempMP = 0
tempPosSize = synthTrade[curMarket].numShares[-1]
# print(myDate[curBar],” “,mySymbol,” LiqLong @ “,price,” “,tempMP,” “,tempPosSize)
synthMP = synthTrade[curMarket].setSynthTradeInfo(‘lx’,tempMP,myDate[curBar],curBar,tempPosSize,price)

Weave synthetic orders into regular order directives


This looks a little rough right now but I will clean it up and finalize robustness of the synthetic testing engine in September.  It will look  a lot better when I release it.  

Article written by George Pruitt

Quantified Models YouTube Channel

We have several videos available on our YouTube channel that you may find very useful in developing trading systems.

We hope this information has been useful to you.

The Enigmatic Turtle Trading System in Python

The Enigmatic Turtle Trading System in Python

[Corrections in bold and results –  August 6, 2020] My favorite book on the Turtle Trading System is Curtis Faith’s “Way of the Turtle.”  I like this book because of the thorough explanation of the rules as told by Curtis.  Having been in this...

read more

Subscribe to our Newsletter

Join our mailing list to receive the latest news and updates from Quantified Models team.

Subscribe to our Newsletter

You have Successfully Subscribed!

Skip to content