Calculation of trading strategies
-
Hello, any indicator has some parameter dependence, for example a lookback period which defines a window of data values used for defining the indicator.
The value of the indicator changes as the window rolls over time day by day.
-
@support Hi, my strategy was rejected : Not enough bid information. The strategy must trade from January 1st, 2006
-
@dark-pidgeot Hello, does the strategy trade at all since 1 Jan 2006? It must trade, otherwise it is rejected.
-
@support
Hello, it trades before 2006 but not after 2006. I don't understand the reason, however, in the backtest, it trades over the entire period. -
@support When I backtest my strategy, the logs says : WARNING! There are not enough points in the data for the slippage calculation.
Add 15 extra data points to the data head (load data more historical data).
WARNING! There are not enough points in the output.
The output series should start from 2006-01-01 or earlier instead of 2006-01-25 -
@dark-pidgeot Ok, thanks. For computing slippage the toolbox uses a fixed percentage of ATR(14), an indicator called the Average True Range, which is computed using the data points for the last 14 days. So to generate a position on 2 Jan 2006, let us say, you need data for the last 15 days also. Otherwise ATR will not be computed.
-
-
Could you send a code snippet showing how you load the data?
-
@support Hi, the head on the strategy is :
import xarray as xr
import qnt.ta as qnta
import qnt.data as qndata
import qnt.output as qnout
import qnt.stats as qns
from IPython.display import display
import xarray as xr
import qnt.ta as qnta
import qnt.backtester as qnbt
import qnt.data as qndatadata = qndata.stocks.load_ndx_data(min_date="2000-01-01")
-
@dark-pidgeot Ok, thanks. It means that you are using a single-pass approach, not the built-in backtester.
Is your system generating trades since 1 Jan 2006 or you do not have any trade before?
-
@support Yes, i Use the single pass, I must change it on multi pass ?
-
@dark-pidgeot The single pass is ok. However, when the code is run, it will be automatically sliced and run in multi-pass fashion to avoid unintentional forward looking (example: usage of global means).
Here it seems that your system makes no trades at all before 1 Jan 2006. Can you check that visualizing the equity curve?
-
@support Hello,
when I do the test, it seems ok except on the last day
-
-
-
@dark-pidgeot Ok, thanks. If you click on the logs button, there should be info explaining he reason for the failure on Sep 1st. Can you share it?
-
@support Hello, yes I can provide you with the logs without the code.
I am still surprised, I followed the simulation. Everything is going well except for the last day. How is it possible that on the last day, it crashes -
@support Calculation start...
[NbConvertApp] Converting notebook strategy.ipynb to html
[NbConvertApp] Executing notebook with kernel: python3
[NbConvertApp] Writing 699954 bytes to strategy.html
Calculation completed.
Strategy body:In [1]:
%%javascript
window.IPython && (IPython.OutputArea.prototype._should_scroll = function
(lines) { return false; })
// run this cell for disabling widget scrolling
In [2]:
import xarray as xr
import qnt.ta as qnta
import qnt.data as qndata
import qnt.output as qnout
import qnt.stats as qns
from IPython.display import display
import xarray as xr
import qnt.ta as qnta
import qnt.backtester as qnbt
import qnt.data as qndata
data = qndata.stocks.load_ndx_data(min_date="2005-01-01")HIDDEN strategy CODE
SINGLE PASS
is_liquid = data.sel(field="is_liquid")
weights = is_liquid*weightsclean weights taking corner cases into account:
weights = qnout.clean(weights, data, "stocks_nasdaq100")
check before submission:
qnout.check(weights, data, "stocks_nasdaq100")
qnout.write(weights)calc stats
stats = qns.calc_stat(data, weights.sel(time=slice("2000-01-01",None)))
stats.to_pandas().tail()
import qnt.graph as qngraph
import qnt.stats as qnstats
statistics = qnstats.calc_stat(data, weights)
performance = statistics.to_pandas()['equity']
qngraph.make_plot_filled(performance.index, performance, name='PnL (Equity)')qnout.check(weights, data)
100% (35181 of 35181) |##################| Elapsed Time: 0:00:00 Time: 0:00:00
100% (35957 of 35957) |##################| Elapsed Time: 0:00:00 Time: 0:00:00
100% (14750756 of 14750756) |############| Elapsed Time: 0:00:00 Time: 0:00:00
fetched chunk 1/6 1s
100% (14750752 of 14750752) |############| Elapsed Time: 0:00:00 Time: 0:00:00
fetched chunk 2/6 3s
100% (14750720 of 14750720) |############| Elapsed Time: 0:00:00 Time: 0:00:00
fetched chunk 3/6 4s
100% (14750628 of 14750628) |############| Elapsed Time: 0:00:00 Time: 0:00:00
fetched chunk 4/6 6s
100% (14750720 of 14750720) |############| Elapsed Time: 0:00:00 Time: 0:00:00
fetched chunk 5/6 7s
100% (979196 of 979196) |################| Elapsed Time: 0:00:00 Time: 0:00:00
fetched chunk 6/6 7s
Data loaded 8s
Output cleaning...
fix uniq
ffill if the current price is None...
Check liquidity...
Ok.
Check missed dates...
Ok.
Normalization...
Output cleaning is complete.
Check liquidity...
Ok.
Check missed dates...
Ok.
Check the sharpe ratio...
Period: 2006-01-01 - 2022-09-01
Sharpe Ratio =#####
Ok.
Check correlation.
correlation check disabledOk. This strategy does not correlate with other strategies.
Write output: /root/fractions.nc.gz
Check liquidity...
Ok.
Check missed dates...
Ok.
Check the sharpe ratio...
Period: 2006-01-01 - 2022-09-01
Sharpe Ratio = #####
Ok.
Check correlation.
correlation check disabledOk. This strategy does not correlate with other strategies.
In [3]:
performance = statistics.to_pandas()['equity']
qngraph.make_plot_filled(performance.index, performance, name='PnL (Equity)')
Submit...
Post task: https://stat.quantiacs.io/regular/task/343939393231303664343261616232333665666532323034343662653936326535353161353038306566633564333132613465326339326330653931646339363A313636323530313135303A37333730333736/regular/task
{
"submission_id": "7941751",
"output": "H4sIAD3BF2MC/+y9X8xl1ZUnRiZmXBnSEjQVgxCGQUJqWtaIns...",
"source": true,
"html": "H4sIAEbBF2MC/+y9a5PcOK4g+t2/Iscdc9vurkynlG972mdmz2...",
"state": null,
"last_data": true
}
Task #7370376 -
@support The short description :
INFO: 2022-09-06T21:52:30Z: pass started: 7962346
INFO: 2022-09-06T21:53:13Z: pass completed: 7962346
INFO: 2022-09-06T22:49:52Z: stats received light=false
INFO: 2022-09-06T22:49:53Z: progress: 1.0
INFO: 2022-09-06T22:49:53Z: checking: last pass
INFO: 2022-09-06T22:49:53Z: filter passed: source exists
INFO: 2022-09-06T22:49:53Z: filter passed: output html exists
INFO: 2022-09-06T22:49:53Z: filter passed: output exists
INFO: 2022-09-06T22:49:53Z: filter passed: strategy uses the last data
INFO: 2022-09-06T22:49:53Z: filter passed: liquidity
FAIL: 2022-09-06T22:49:53Z: filter failed: in sample period is too short:3417 < 3764 -
@dark-pidgeot ok, there are not enough trading days. Are you generating non-zero positions since 1 Jan 2006?