Trading System Optimisation Code
-
Hi
I have confusion regarding the trading system optimization and optimal parameter selection feature you are providing. I tried to do the same manually but the results varied with the ones I got using your trading system optimization feature. Can you tell how it decides the optimal parameters?
-
Hello.
If you open the source code
qnt/optimizer.py
, you can find that the optimizer uses these functions for optimization:def standard_stats_function(data, output): """ Calculates statistics for the iteration output. :param data: market data :param output: weights :return: dict """ start_date = qns.get_default_is_start_date_for_type(data.name) stat = qns.calc_stat(data, output.sel(time=slice(start_date, None))) return stat.isel(time=-1).to_pandas().to_dict() def standard_stats_to_weight(stat): """ Converts the statistics to weight. :param stat: dict :return: """ res = stat.get('sharpe_ratio', float('-inf')) if math.isfinite(res): return res else: return float('-inf')
You can use other functions if you want. Just specify
stats_function
andstats_to_weight
when you call optimize_strategy.It is ok that you use your own optimization algorithm. This one is the simplest implementation and it may not suit you perfectly. You can just reuse some code from
optimizer.py
which relates to workers. It may be useful if you want to speed up your optimizer.Regards.