Skip to content

Commit

Permalink
run backtest with derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytroshch committed Sep 21, 2023
1 parent 4e89b31 commit 2a549d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/components/StrategyEditor/StrategyEditor.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const mapDispatchToProps = (dispatch) => ({
constraints,
label,
id,
leverageSettings,
stopOrderSettings,
margin,
} = data
const processedStrategy = _omitBy(strategyContent, _isEmpty)
const sync = true
Expand All @@ -125,9 +128,12 @@ const mapDispatchToProps = (dispatch) => ({
trades,
candleSeed,
sync,
margin,
processedStrategy,
uuidv4(),
constraints,
leverageSettings,
stopOrderSettings,
],
],
}),
Expand Down
28 changes: 26 additions & 2 deletions src/components/StrategyEditor/StrategyEditor.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,20 @@ export const prepareStrategyBacktestingArgs = (strategy) => {
maxDrawdownPerc,
startDate,
endDate,
margin,
useMaxLeverage,
increaseLeverage,
leverage,
addStopOrder,
stopOrderPercent,
},
strategyContent,
id,
} = strategy

return {
const args = {
symbol: symbol?.wsID,
label,
startNum: new Date(startDate).getTime(),
endNum: new Date(endDate).getTime(),
[STRATEGY_OPTIONS_KEYS.TIMEFRAME]: timeframe,
Expand All @@ -164,13 +171,30 @@ export const prepareStrategyBacktestingArgs = (strategy) => {
id,
[STRATEGY_OPTIONS_KEYS.CANDLES]: candles,
[STRATEGY_OPTIONS_KEYS.CANDLE_SEED]: candleSeed,
[STRATEGY_OPTIONS_KEYS.MARGIN]: margin,
constraints: {
[STRATEGY_OPTIONS_KEYS.CAPITAL_ALLOCATION]: Number(capitalAllocation),
[STRATEGY_OPTIONS_KEYS.STOP_LOSS_PERC]: Number(stopLossPerc),
[STRATEGY_OPTIONS_KEYS.MAX_DRAWDOWN_PERC]: Number(maxDrawdownPerc),
},
label,
leverageSettings: {},
stopOrderSettings: {
addStopOrder,
},
}

if (margin) {
args.leverageSettings.useMaxLeverage = useMaxLeverage
if (!useMaxLeverage) {
args.leverageSettings.leverage = Number(leverage)
args.leverageSettings.increaseLeverage = increaseLeverage
}
}
if (addStopOrder && stopOrderPercent) {
args.stopOrderSettings.stopOrderPercent = Number(stopOrderPercent)
}

return args
}

export const prepareStrategyToLoad = (strategyToLoad, markets, strategies) => {
Expand Down

0 comments on commit 2a549d7

Please sign in to comment.