Synthetic Trading Class

SynthTradeClass

——————————————————————————-
Name:        synthTradeClass
Purpose:     Calculates and tracks positions based on synthetic orders
runs independed of ‘real’ order directives.
Author:      George
Created:     17/08/2022
Copyright:   (c) George 2022
——————————————————————————-

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:

Using RetAndRec functionality

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
enterLongPosition(price,posSize,tradeName,sysMarkDict)
unPackDict(sysMarkDict)

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)
unPackDict(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.  Take a look at www.georgepruitt.com to see some more results and explanations.

 

Tags: , ,

classic

yes

About This Site

This site is home to George’s Excellent Adventure into TradingSimula_18 and Python.  George grew tired of the old and expensive back testing software so he created his own and now is able to test and develop  Trend Following Systems utilizing EOD data and EOD intra-testing portfolio management.  This software, TradingSimula_18 can be found in his Trend Following Systems: A DIY Project – Batteries Included book – now in its 2nd edition.

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031