Add average SLTP

This commit is contained in:
2025-03-02 18:10:52 +07:00
parent 6f4db52bbb
commit 963b7bbf83
2 changed files with 41 additions and 6 deletions

View File

@@ -5,12 +5,12 @@ public class BacktestScorer
// Updated weights without ProfitEfficiency // Updated weights without ProfitEfficiency
private static readonly Dictionary<string, double> Weights = new Dictionary<string, double> private static readonly Dictionary<string, double> Weights = new Dictionary<string, double>
{ {
{ "GrowthPercentage", 0.30 }, // Increased weight for profitability { "GrowthPercentage", 0.28 },
{ "SharpeRatio", 0.18 }, { "SharpeRatio", 0.18 },
{ "MaxDrawdownPc", 0.15 }, { "MaxDrawdownPc", 0.15 },
{ "HodlComparison", 0.15 }, { "HodlComparison", 0.05 },
{ "WinRate", 0.10 }, { "WinRate", 0.18 },
{ "ProfitabilityBonus", 0.07 }, // New direct profitability component { "ProfitabilityBonus", 0.11 },
{ "TradeCount", 0.03 }, { "TradeCount", 0.03 },
{ "RecoveryTime", 0.02 } { "RecoveryTime", 0.02 }
}; };

View File

@@ -14,13 +14,17 @@ import type {
} from '../../../generated/ManagingApi' } from '../../../generated/ManagingApi'
import { BacktestClient, BotClient } from '../../../generated/ManagingApi' import { BacktestClient, BotClient } from '../../../generated/ManagingApi'
import type { IBacktestCards } from '../../../global/type' import type { IBacktestCards } from '../../../global/type'
import { Toast, SelectColumnFilter, Table } from '../../mollecules' import { Toast, SelectColumnFilter, Table, CardText } from '../../mollecules'
import BacktestRowDetails from './backtestRowDetails' import BacktestRowDetails from './backtestRowDetails'
const BacktestTable: React.FC<IBacktestCards> = ({ list, isFetching }) => { const BacktestTable: React.FC<IBacktestCards> = ({ list, isFetching }) => {
const [rows, setRows] = useState<Backtest[]>([]) const [rows, setRows] = useState<Backtest[]>([])
const { apiUrl } = useApiUrlStore() const { apiUrl } = useApiUrlStore()
const [optimizedMoneyManagement, setOptimizedMoneyManagement] = useState({
stopLoss: 0,
takeProfit: 0,
})
async function runBot(backtest: Backtest, isForWatchOnly: boolean) { async function runBot(backtest: Backtest, isForWatchOnly: boolean) {
const t = new Toast('Bot is starting') const t = new Toast('Bot is starting')
@@ -260,7 +264,29 @@ const BacktestTable: React.FC<IBacktestCards> = ({ list, isFetching }) => {
) )
useEffect(() => { useEffect(() => {
setRows(list) setRows(list!)
if (list!.length > 0) {
// const optimized = list![0].optimizedMoneyManagement
// setOptimizedMoneyManagement({
// stopLoss: optimized.stopLoss,
// takeProfit: optimized.takeProfit,
// })
// Get average optimized money management for every backtest
const optimized = list!.map((b) => b.optimizedMoneyManagement)
const stopLoss = optimized.reduce((acc, curr) => acc + curr.stopLoss, 0)
const takeProfit = optimized.reduce(
(acc, curr) => acc + curr.takeProfit,
0
)
setOptimizedMoneyManagement({
stopLoss: stopLoss / optimized.length,
takeProfit: takeProfit / optimized.length,
})
}
}, [list]) }, [list])
const renderRowSubComponent = React.useCallback( const renderRowSubComponent = React.useCallback(
@@ -289,6 +315,15 @@ const BacktestTable: React.FC<IBacktestCards> = ({ list, isFetching }) => {
{isFetching ? ( {isFetching ? (
<progress className="progress progress-primary w-56"></progress> <progress className="progress progress-primary w-56"></progress>
) : (<> ) : (<>
<div className='w-full'>
<CardText
title="Average Optimized Money Management"
content={
"SL: " +optimizedMoneyManagement.stopLoss.toFixed(2) + "% | TP: " + optimizedMoneyManagement.takeProfit.toFixed(2) + "% " +
"| R/R: " + (optimizedMoneyManagement.takeProfit / optimizedMoneyManagement.stopLoss).toFixed(2)
}
></CardText>
</div>
<Table <Table
columns={columns} columns={columns}
data={rows} data={rows}