——————————————————————————-
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:
calcDailyEquity
setSynthTradeInfo
__inti__
Module includes:
calcEquCurveRetAndRec
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 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
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.
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.