{
«cells»: [
{

«cell_type»: «markdown», «metadata»: {}, «source»: [

«# Technical Analysis Template: sRoC = WMA + RoC»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«Follow the trend the using smooth Rate of Change. The smooth function is WMA.»

]

}, {

«cell_type»: «code», «execution_count»: 1, «metadata»: {}, «outputs»: [

{
«data»: {
«text/html»: [

» <script type="text/javascript">n», » window.PlotlyConfig = {MathJaxConfig: „local“};n», » if (window.MathJax) {MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}n», » if (typeof require !== „undefined“) {n», » require.undef("plotly");n», » requirejs.config({n», » paths: {n», » „plotly“: [“https://cdn.plot.ly/plotly-latest.min“]n», » }n», » });n», » require([„plotly“], function(Plotly) {n», » window._Plotly = Plotly;n», » });n», » }n», » </script>n», » «

]

}, «metadata»: {}, «output_type»: «display_data»

}

], «source»: [

«import qnt.data as qndatan», «import qnt.stats as qnstatsn», «import qnt.xr_talib as qnxrtalibn», «import qnt.graph as qngraphn», «#import qnt.forward_looking as qnfln», «import datetime as dt»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«## Data»

]

}, {

«cell_type»: «code», «execution_count»: 2, «metadata»: {

«scrolled»: true

}, «outputs»: [

{

«name»: «stdout», «output_type»: «stream», «text»: [

«fetched chunk 1/5 1sn», «fetched chunk 2/5 3sn», «fetched chunk 3/5 4sn», «fetched chunk 4/5 6sn», «fetched chunk 5/5 7sn», «Data loaded 7sn»

]

}

], «source»: [

«data = qndata.load_data(n», » tail = dt.timedelta(days=4*365),n», » forward_order=True, n», » dims=("time", "field", "asset")n», «)»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«## Calc output»

]

}, {

«cell_type»: «code», «execution_count»: 3, «metadata»: {

«scrolled»: false

}, «outputs»: [], «source»: [

«SROC_POSITIVE_TREND_LEVEL = 0.0125n», «n», «wma = qnxrtalib.WMA(data.sel(field=“close“), 290)n», «sroc = qnxrtalib.ROCP(wma, 35)n», «n», «is_liquid = data.sel(field="is_liquid")n», «weights = is_liquid.where(sroc > SROC_POSITIVE_TREND_LEVEL)n», «n», «weights = weights / weights.sum("asset", skipna=True)n», «n», «output = weights.fillna(0.0)»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«## Stats»

]

}, {

«cell_type»: «code», «execution_count»: 4, «metadata»: {}, «outputs»: [

{
«data»: {
«text/html»: [

«<div>n», «<style scoped>n», » .dataframe tbody tr th:only-of-type {n», » vertical-align: middle;n», » }n», «n», » .dataframe tbody tr th {n», » vertical-align: top;n», » }n», «n», » .dataframe thead th {n», » text-align: right;n», » }n», «</style>n», «<table border="1" class="dataframe">n», » <thead>n», » <tr style="text-align: right;">n», » <th>field</th>n», » <th>equity</th>n», » <th>relative_return</th>n», » <th>volatility</th>n», » <th>underwater</th>n», » <th>max_drawdown</th>n», » <th>sharpe_ratio</th>n», » <th>mean_return</th>n», » <th>bias</th>n», » <th>instruments</th>n», » <th>avg_turnover</th>n», » <th>avg_holding_time</th>n», » </tr>n», » <tr>n», » <th>time</th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » </tr>n», » </thead>n», » <tbody>n», » <tr>n», » <th>2020-08-13</th>n», » <td>1.366697</td>n», » <td>0.007825</td>n», » <td>0.222443</td>n», » <td>-0.015243</td>n», » <td>-0.345248</td>n», » <td>0.493373</td>n», » <td>0.109747</td>n», » <td>1.0</td>n», » <td>774.0</td>n», » <td>0.042115</td>n», » <td>51.985576</td>n», » </tr>n», » <tr>n», » <th>2020-08-14</th>n», » <td>1.361325</td>n», » <td>-0.003931</td>n», » <td>0.222457</td>n», » <td>-0.019114</td>n», » <td>-0.345248</td>n», » <td>0.486796</td>n», » <td>0.108291</td>n», » <td>1.0</td>n», » <td>774.0</td>n», » <td>0.042175</td>n», » <td>51.979797</td>n», » </tr>n», » <tr>n», » <th>2020-08-17</th>n», » <td>1.378683</td>n», » <td>0.012751</td>n», » <td>0.222569</td>n», » <td>-0.006607</td>n», » <td>-0.345248</td>n», » <td>0.507626</td>n», » <td>0.112982</td>n», » <td>1.0</td>n», » <td>774.0</td>n», » <td>0.042198</td>n», » <td>51.978443</td>n», » </tr>n», » <tr>n», » <th>2020-08-18</th>n», » <td>1.379124</td>n», » <td>0.000320</td>n», » <td>0.222569</td>n», » <td>-0.006289</td>n», » <td>-0.345248</td>n», » <td>0.508160</td>n», » <td>0.113101</td>n», » <td>1.0</td>n», » <td>774.0</td>n», » <td>0.042232</td>n», » <td>51.962735</td>n», » </tr>n», » <tr>n», » <th>2020-08-19</th>n», » <td>1.371947</td>n», » <td>-0.005204</td>n», » <td>0.222593</td>n», » <td>-0.011460</td>n», » <td>-0.345248</td>n», » <td>0.499415</td>n», » <td>0.111166</td>n», » <td>1.0</td>n», » <td>774.0</td>n», » <td>0.042263</td>n», » <td>51.779884</td>n», » </tr>n», » </tbody>n», «</table>n», «</div>»

], «text/plain»: [

«field equity relative_return volatility underwater max_drawdown \n», «time n», «2020-08-13 1.366697 0.007825 0.222443 -0.015243 -0.345248 n», «2020-08-14 1.361325 -0.003931 0.222457 -0.019114 -0.345248 n», «2020-08-17 1.378683 0.012751 0.222569 -0.006607 -0.345248 n», «2020-08-18 1.379124 0.000320 0.222569 -0.006289 -0.345248 n», «2020-08-19 1.371947 -0.005204 0.222593 -0.011460 -0.345248 n», «n», «field sharpe_ratio mean_return bias instruments avg_turnover \n», «time n», «2020-08-13 0.493373 0.109747 1.0 774.0 0.042115 n», «2020-08-14 0.486796 0.108291 1.0 774.0 0.042175 n», «2020-08-17 0.507626 0.112982 1.0 774.0 0.042198 n», «2020-08-18 0.508160 0.113101 1.0 774.0 0.042232 n», «2020-08-19 0.499415 0.111166 1.0 774.0 0.042263 n», «n», «field avg_holding_time n», «time n», «2020-08-13 51.985576 n», «2020-08-14 51.979797 n», «2020-08-17 51.978443 n», «2020-08-18 51.962735 n», «2020-08-19 51.779884 «

]

}, «metadata»: {}, «output_type»: «display_data»

}

], «source»: [

«stat = qnstats.calc_stat(data, output)n», «display(stat.to_pandas().tail())»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«## Improvement»

]

}, {

«cell_type»: «code», «execution_count»: 5, «metadata»: {}, «outputs»: [

{
«data»: {
«text/html»: [

«<div>n», «<style scoped>n», » .dataframe tbody tr th:only-of-type {n», » vertical-align: middle;n», » }n», «n», » .dataframe tbody tr th {n», » vertical-align: top;n», » }n», «n», » .dataframe thead th {n», » text-align: right;n», » }n», «</style>n», «<table border="1" class="dataframe">n», » <thead>n», » <tr style="text-align: right;">n», » <th>field</th>n», » <th>equity</th>n», » <th>relative_return</th>n», » <th>volatility</th>n», » <th>underwater</th>n», » <th>max_drawdown</th>n», » <th>sharpe_ratio</th>n», » <th>mean_return</th>n», » <th>bias</th>n», » <th>instruments</th>n», » <th>avg_turnover</th>n», » <th>avg_holding_time</th>n», » </tr>n», » <tr>n», » <th>time</th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » <th></th>n», » </tr>n», » </thead>n», » <tbody>n», » <tr>n», » <th>2020-08-13</th>n», » <td>1.156059</td>n», » <td>0.006719</td>n», » <td>0.125964</td>n», » <td>-0.006555</td>n», » <td>-0.21593</td>n», » <td>0.393177</td>n», » <td>0.049526</td>n», » <td>1.0</td>n», » <td>634.0</td>n», » <td>0.034092</td>n», » <td>34.989310</td>n», » </tr>n», » <tr>n», » <th>2020-08-14</th>n», » <td>1.153334</td>n», » <td>-0.002356</td>n», » <td>0.125973</td>n», » <td>-0.008896</td>n», » <td>-0.21593</td>n», » <td>0.386600</td>n», » <td>0.048701</td>n», » <td>1.0</td>n», » <td>634.0</td>n», » <td>0.034130</td>n», » <td>34.993657</td>n», » </tr>n», » <tr>n», » <th>2020-08-17</th>n», » <td>1.165349</td>n», » <td>0.010417</td>n», » <td>0.126110</td>n», » <td>0.000000</td>n», » <td>-0.21593</td>n», » <td>0.414956</td>n», » <td>0.052330</td>n», » <td>1.0</td>n», » <td>634.0</td>n», » <td>0.034161</td>n», » <td>34.970347</td>n», » </tr>n», » <tr>n», » <th>2020-08-18</th>n», » <td>1.166406</td>n», » <td>0.000907</td>n», » <td>0.126111</td>n», » <td>0.000000</td>n», » <td>-0.21593</td>n», » <td>0.417477</td>n», » <td>0.052648</td>n», » <td>1.0</td>n», » <td>635.0</td>n», » <td>0.034182</td>n», » <td>34.961335</td>n», » </tr>n», » <tr>n», » <th>2020-08-19</th>n», » <td>1.162703</td>n», » <td>-0.003175</td>n», » <td>0.126126</td>n», » <td>-0.003175</td>n», » <td>-0.21593</td>n», » <td>0.408585</td>n», » <td>0.051533</td>n», » <td>1.0</td>n», » <td>635.0</td>n», » <td>0.034211</td>n», » <td>35.396290</td>n», » </tr>n», » </tbody>n», «</table>n», «</div>»

], «text/plain»: [

«field equity relative_return volatility underwater max_drawdown \n», «time n», «2020-08-13 1.156059 0.006719 0.125964 -0.006555 -0.21593 n», «2020-08-14 1.153334 -0.002356 0.125973 -0.008896 -0.21593 n», «2020-08-17 1.165349 0.010417 0.126110 0.000000 -0.21593 n», «2020-08-18 1.166406 0.000907 0.126111 0.000000 -0.21593 n», «2020-08-19 1.162703 -0.003175 0.126126 -0.003175 -0.21593 n», «n», «field sharpe_ratio mean_return bias instruments avg_turnover \n», «time n», «2020-08-13 0.393177 0.049526 1.0 634.0 0.034092 n», «2020-08-14 0.386600 0.048701 1.0 634.0 0.034130 n», «2020-08-17 0.414956 0.052330 1.0 634.0 0.034161 n», «2020-08-18 0.417477 0.052648 1.0 635.0 0.034182 n», «2020-08-19 0.408585 0.051533 1.0 635.0 0.034211 n», «n», «field avg_holding_time n», «time n», «2020-08-13 34.989310 n», «2020-08-14 34.993657 n», «2020-08-17 34.970347 n», «2020-08-18 34.961335 n», «2020-08-19 35.396290 «

]

}, «execution_count»: 5, «metadata»: {}, «output_type»: «execute_result»

}

], «source»: [

«stat_per_asset = qnstats.calc_stat(data, output, max_periods=40, per_asset = True)n», «improved_output = output.where(n», » stat_per_asset.sel(field=“sharpe_ratio“).rolling(time=20).mean() > 0n», «)n», «stat = qnstats.calc_stat(data, improved_output, max_periods=252 * 3)n», «stat.to_pandas().tail()»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«## Checks»

]

}, {

«cell_type»: «code», «execution_count»: 6, «metadata»: {}, «outputs»: [

{

«name»: «stdout», «output_type»: «stream», «text»: [

«n», «WARNING! This strategy correlates with other strategies.n», «The number of systems with a larger Sharpe ratio and correlation larger than 0.8: 4n», «The max correlation value (with systems with a larger Sharpe ratio): 0.9938369419614559n», «Current sharpe ratio(3y): 0.49941489646205245n», «n»

]

}

], «source»: [

«# correlation checkn», «# your strategy should not correlate with other strategies before submissionn», «qnstats.print_correlation(output, data)»

]

}, {

«cell_type»: «markdown», «metadata»: {}, «source»: [

«## Save output»

]

}, {

«cell_type»: «code», «execution_count»: 7, «metadata»: {}, «outputs»: [

{

«name»: «stdout», «output_type»: «stream», «text»: [

«write output: /root/fractions.nc.gzn»

]

}

], «source»: [

«qndata.write_output(output)»

]

}

], «metadata»: {

«kernelspec»: {

«display_name»: «Python 3», «language»: «python», «name»: «python3»

}, «language_info»: {

«codemirror_mode»: {

«name»: «ipython», «version»: 3

}, «file_extension»: «.py», «mimetype»: «text/x-python», «name»: «python», «nbconvert_exporter»: «python», «pygments_lexer»: «ipython3», «version»: «3.7.7»

}

}, «nbformat»: 4, «nbformat_minor»: 2

}