Skip to content

Commit

Permalink
added support for multiple variables, to scale out tests even further
Browse files Browse the repository at this point in the history
  • Loading branch information
mccaffers committed Feb 9, 2024
1 parent 03bcc09 commit 68e64d8
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 42 deletions.
68 changes: 59 additions & 9 deletions scripts/backtestings/aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main() {

######################################
### EXPERIMENT DEFINITION
source $my_dir/experiments/momentum/forex/momentum_14a2da93_focused
source $my_dir/experiments/momentum/focused/fixed
######################################

# Remove binary files & tests
Expand Down Expand Up @@ -107,19 +107,69 @@ kineticTPFunc(){
for pips in `seq $kineticLimitRange`
do
export kineticLimit=$pips

randomStrategyHHLLFunc
variableA_range_Func
done
}

randomStrategyHHLLFunc(){
for pips in `seq $randomStrategyAmountOfHHLLSseq`
do
export randomStrategyAmountOfHHLL=$pips
variableA_range_Func(){
if [ -z "$variableA_range" ]; then
deploy
done
else
for pips in `seq $variableA_range`
do
export variableA=$pips
variableB_range_Func
done
fi
}

variableB_range_Func(){
if [ -z "$variableB_range" ]; then
deploy
else
for pips in `seq $variableB_range`
do
export variableB=$pips
variableC_range_Func
done
fi
}

variableC_range_Func(){
if [ -z "$variableC_range" ]; then
deploy
else
for pips in `seq $variableC_range`
do
export variableC=$pips
variableD_range_Func
done
fi
}

variableD_range_Func(){
if [ -z "$variableD_range" ]; then
deploy
else
for pips in `seq $variableD_range`
do
export variableD=$pips
variableE_range_Func
done
fi
}

variableE_range_Func(){
if [ -z "$variableE_range" ]; then
deploy
else
for pips in `seq $variableE_range`
do
export variableE=$pips
deploy
done
fi
}

instanceCount=0

Expand All @@ -128,7 +178,7 @@ deploy () {
let instanceCount=instanceCount+1

envsubst < $SCRIPT_DIR/template.txt > $SCRIPT_DIR/data.sh

# Deploy
aws ec2 run-instances --image-id ${AWS_MACHINE_IMAGE} \
--count 1 \
Expand Down
32 changes: 32 additions & 0 deletions scripts/backtestings/experiments/momentum/focused/fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
declare -a strategies=("Momentum_59ca71ff")

## Multiple Indexes
declare -a symbolsArray=("GBRIDXGBP")

# Forex from 2004
yearsStart=2021
yearsEnd=2023

# These don't mean anything in RandomHHLL as the SL/TP is defined by the highest and lowest value from the last time period
stopLossInPipsRange="200 1 200" # STOP LOSS Distance in PIPs
limitInPipsRange="200 1 200" # TAKE PROFIT Distance in PIPs

# Account Equity
accountEquity=10000
maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# ####################
# Strategy Variables

# amount of periods to keep
variableA_range="5 5 15"

# variableB = period
variableB_range="30 30 90"

# variableC = maxSpeed
variableC_range="0.5 0.5 1.5"

# variableD = max stop value
variableD_range="100 900 1000"
2 changes: 1 addition & 1 deletion scripts/backtestings/experiments/momentum/forex/fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="5 5 15"
variableA_range="5 5 15"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="5 5 15"
variableA_range="5 5 15"
4 changes: 2 additions & 2 deletions scripts/backtestings/experiments/momentum/indices/fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare -a strategies=("Momentum_4d991e3b")
declare -a strategies=("Momentum_2ff0b2b2")

## Multiple Indexes
declare -a symbolsArray=("JPNIDXJPY" "ESPIDXEUR" "FRAIDXEUR" "DEUIDXEUR" "AUSIDXAUD" "USATECHIDXUSD" "USA500IDXUSD" "USA30IDXUSD" "EUSIDXEUR" "GBRIDXGBP")
Expand All @@ -17,4 +17,4 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="5 5 15"
variableA_range="5 5 15"
2 changes: 1 addition & 1 deletion scripts/backtestings/experiments/random-hh-ll/bonds/range
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="4 2 10"
variableA_range="4 2 10"
#RANDOMHHLL_HOURS_TO_KEEP=5
#RANDOMHHLL_TP_LOOKBACK_OVER_HOURS=2
2 changes: 1 addition & 1 deletion scripts/backtestings/experiments/random-hh-ll/crypto/range
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="4 2 10"
variableA_range="4 2 10"
#RANDOMHHLL_HOURS_TO_KEEP=5
#RANDOMHHLL_TP_LOOKBACK_OVER_HOURS=2
2 changes: 1 addition & 1 deletion scripts/backtestings/experiments/random-hh-ll/forex/range
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="4 2 10"
variableA_range="4 2 10"
#RANDOMHHLL_HOURS_TO_KEEP=5
#RANDOMHHLL_TP_LOOKBACK_OVER_HOURS=2
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ maximumDrawndownPercentage=75
fasterProcessingBySkippingSomeTickData=true

# Strategy Variables
randomStrategyAmountOfHHLLSseq="4 2 10"
variableA_range="4 2 10"
#RANDOMHHLL_HOURS_TO_KEEP=5
#RANDOMHHLL_TP_LOOKBACK_OVER_HOURS=2
6 changes: 5 additions & 1 deletion scripts/backtestings/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export tradingSize=${tradingSize}
export instanceCount=${instanceCount}
export kineticStopLoss=${kineticStopLoss}
export kineticLimit=${kineticLimit}
export randomStrategyAmountOfHHLL=${randomStrategyAmountOfHHLL}
export operatingEnvironment=${operatingEnvironment}
export fasterProcessingBySkippingSomeTickData=${fasterProcessingBySkippingSomeTickData}
export variableA=${variableA}
export variableB=${variableB}
export variableC=${variableC}
export variableD=${variableD}
export variableE=${variableE}

export consoleLog=false
export systemLog=false
Expand Down
7 changes: 6 additions & 1 deletion src/Models/IEnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ public interface IEnvironmentVariables
int kineticStopLoss {get; init;}
int kineticLimit {get; init;}
bool doNotCleanUpDataFolder {get;init;}
int randomStrategyAmountOfHHLL {get; init;}
bool fasterProcessingBySkippingSomeTickData {get;init;}

decimal? variableA {get;init;}
decimal? variableB {get;init;}
decimal? variableC {get;init;}
decimal? variableD {get;init;}
decimal? variableE {get;init;}

Dictionary<string, decimal> getScalingFactorDictionary();
decimal GetScalingFactor(string symbol);

Expand Down
18 changes: 14 additions & 4 deletions src/backtesting/Analysis/Reporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ public void EndOfRunReport(string reason = "")
stopDistanceInPips = decimal.Parse(envVariables.stopDistanceInPips),
limitDistanceInPips = decimal.Parse(envVariables.limitDistanceInPips),
instanceCount = envVariables.instanceCount,
randomHHLLValue = envVariables.randomStrategyAmountOfHHLL
variableA = envVariables.variableA,
variableB = envVariables.variableB,
variableC = envVariables.variableC,
variableD = envVariables.variableD,
variableE = envVariables.variableE,
};


Expand Down Expand Up @@ -117,7 +121,7 @@ public virtual async Task SendStack(TradingException message)

public void TradeUpdate(DateTime date, string symbol, decimal profit)
{
tradeUpdateArray.Add(new ReportTradeObj()
var tradeReport = new ReportTradeObj()
{
date = date,
symbols = envVariables.symbols,
Expand All @@ -128,8 +132,14 @@ public void TradeUpdate(DateTime date, string symbol, decimal profit)
stopDistanceInPips = stopDistanceInPips,
limitDistanceInPips = limitDistanceInPips,
trailingStopLoss = envVariables.kineticStopLoss,
randomHHLLValue = envVariables.randomStrategyAmountOfHHLL
});
variableA = envVariables.variableA,
variableB = envVariables.variableB,
variableC = envVariables.variableC,
variableD = envVariables.variableD,
variableE = envVariables.variableE,
};

tradeUpdateArray.Add(tradeReport);

_=BatchTradeUpdate();
}
Expand Down
14 changes: 12 additions & 2 deletions src/backtesting/Utilities/ReportObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public class ReportFinalObj {
public decimal limitDistanceInPips {get;set;}

public int instanceCount { get;set; }
public decimal randomHHLLValue {get;set;}

public decimal? variableA {get;set;}
public decimal? variableB {get;set;}
public decimal? variableC {get;set;}
public decimal? variableD {get;set;}
public decimal? variableE {get;set;}

public IEnvironmentVariables? environmentVariables {get;set;}
}
Expand All @@ -51,7 +56,12 @@ public class ReportTradeObj {
public decimal stopDistanceInPips {get;set;}
public decimal limitDistanceInPips {get;set;}
public decimal trailingStopLoss {get;set;}
public decimal randomHHLLValue {get;set;}
public int instanceCount { get; init; } = 0;
public IEnvironmentVariables? environmentVariables {get;set;}

public decimal? variableA {get;set;}
public decimal? variableB {get;set;}
public decimal? variableC {get;set;}
public decimal? variableD {get;set;}
public decimal? variableE {get;set;}
}
2 changes: 1 addition & 1 deletion src/strategies/BaseStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BaseStrategy
protected readonly IWebNotification webNotification;
protected readonly ICloseOrder closeOrder;

protected BaseStrategy(IRequestOpenTrade requestOpenTrade, ITradingObjects tradeObjs, IEnvironmentVariables envVariables,ICloseOrder closeOrder, IWebNotification webNotification)
protected BaseStrategy(IRequestOpenTrade requestOpenTrade, ITradingObjects tradeObjs, IEnvironmentVariables envVariables, ICloseOrder closeOrder, IWebNotification webNotification)
{
this.requestOpenTrade = requestOpenTrade;
this.envVariables = envVariables;
Expand Down
Loading

0 comments on commit 68e64d8

Please sign in to comment.