{
  "id": 324180,
  "title": "9th Place Solution - Inference",
  "url": "/competitions/g-research-crypto-forecasting/writeups/bturan19-9th-place-solution-inference",
  "author_name": "",
  "post_date": "2022-05-10T13:00:21.343Z",
  "votes": 22,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Hello everyone,</p>\n<p>Firstly, I want to thank you everyone in this competition, it was a great journey for me and I'm very happy to win a gold medal for the first time.</p>\n<p>I actually shared my inference <a href=\"https://www.kaggle.com/code/bturan19/lgb-3fold-rollingagg-lagtarget-submissioninference/notebook\" target=\"_blank\">notebook</a> long ago. Now I want to give some information about it..</p>\n<p>My most precious feature was Hull moving average:</p>\n<pre><code>def moving_average(a, n=3) :\n    ret = np.cumsum(a, dtype=float)\n    ret[n:] = ret[n:] - ret[:-n]\n    return np.append(np.array([1]*n), ret[n - 1:] / n)[1:]\n\n#@jit(nopython=True)\ndef calcHullMA_inference(series, N=50):\n    SMA1 = moving_average(series, N)\n    SMA2 = moving_average(series, int(N/2))\n    res = (2 * SMA2 - SMA1)\n    return np.mean(res[-int(np.sqrt(N)):])\n\nrow[\"hull\"] = last_close - calcHullMA_inference(f[asset][\"all_close\"][-260:], 240)\n</code></pre>\n<p>Other important note about creating lag feature, is the window size. I choose my windows with a Fibonacci sequence: fibo_list = [55, 210, 340, 890, 3750]. You can see that in notebook.</p>\n<p>Last important explanation about my feature is using lag target. Firstly I tried to use the official calculation but then I just gave up and use this:</p>\n<p><code>row[\"target_return\"] = (last_close / f[asset][\"all_close\"][-16]) -1</code></p>\n<p>and for a market indicator, I collected new \"target_return\" for every batch, and get the average of last available list.</p>\n<p>Last important note for my work is models. I have 3 different LightGBM models that were trained for different market conditions. Up market, down market and relatively more stable market. Then I get the average of them.</p>\n<p>I thought about how could I improve my models. First thing is: I could do parameter optimization, I almost used default parameters. Then I could add different kind of models, I thing my submission time was around 6 hours. lastly, I had actually more feature in my mind.</p>\n<p>Well, thanks to everyone again.. See you in next competition.</p>",
  "messages": [
    {
      "id": "1783525",
      "postDate": "05/10/2022 12:59:25",
      "content": "<p>Hello everyone,</p>\n<p>Firstly, I want to thank you everyone in this competition, it was a great journey for me and I'm very happy to win a gold medal for the first time.</p>\n<p>I actually shared my inference <a href=\"https://www.kaggle.com/code/bturan19/lgb-3fold-rollingagg-lagtarget-submissioninference/notebook\" target=\"_blank\">notebook</a> long ago. Now I want to give some information about it..</p>\n<p>My most precious feature was Hull moving average:</p>\n<pre><code>def moving_average(a, n=3) :\n    ret = np.cumsum(a, dtype=float)\n    ret[n:] = ret[n:] - ret[:-n]\n    return np.append(np.array([1]*n), ret[n - 1:] / n)[1:]\n\n#@jit(nopython=True)\ndef calcHullMA_inference(series, N=50):\n    SMA1 = moving_average(series, N)\n    SMA2 = moving_average(series, int(N/2))\n    res = (2 * SMA2 - SMA1)\n    return np.mean(res[-int(np.sqrt(N)):])\n\nrow[\"hull\"] = last_close - calcHullMA_inference(f[asset][\"all_close\"][-260:], 240)\n</code></pre>\n<p>Other important note about creating lag feature, is the window size. I choose my windows with a Fibonacci sequence: fibo_list = [55, 210, 340, 890, 3750]. You can see that in notebook.</p>\n<p>Last important explanation about my feature is using lag target. Firstly I tried to use the official calculation but then I just gave up and use this:</p>\n<p><code>row[\"target_return\"] = (last_close / f[asset][\"all_close\"][-16]) -1</code></p>\n<p>and for a market indicator, I collected new \"target_return\" for every batch, and get the average of last available list.</p>\n<p>Last important note for my work is models. I have 3 different LightGBM models that were trained for different market conditions. Up market, down market and relatively more stable market. Then I get the average of them.</p>\n<p>I thought about how could I improve my models. First thing is: I could do parameter optimization, I almost used default parameters. Then I could add different kind of models, I thing my submission time was around 6 hours. lastly, I had actually more feature in my mind.</p>\n<p>Well, thanks to everyone again.. See you in next competition.</p>",
      "rawMarkdown": "Hello everyone,\n\nFirstly, I want to thank you everyone in this competition, it was a great journey for me and I'm very happy to win a gold medal for the first time.\n\nI actually shared my inference [notebook](https://www.kaggle.com/code/bturan19/lgb-3fold-rollingagg-lagtarget-submissioninference/notebook) long ago. Now I want to give some information about it..\n\nMy most precious feature was Hull moving average:\n\n```#@jit(nopython=True)\ndef moving_average(a, n=3) :\n    ret = np.cumsum(a, dtype=float)\n    ret[n:] = ret[n:] - ret[:-n]\n    return np.append(np.array([1]*n), ret[n - 1:] / n)[1:]\n\n#@jit(nopython=True)\ndef calcHullMA_inference(series, N=50):\n    SMA1 = moving_average(series, N)\n    SMA2 = moving_average(series, int(N/2))\n    res = (2 * SMA2 - SMA1)\n    return np.mean(res[-int(np.sqrt(N)):])\n\nrow[\"hull\"] = last_close - calcHullMA_inference(f[asset][\"all_close\"][-260:], 240)\n```\n\nOther important note about creating lag feature, is the window size. I choose my windows with a Fibonacci sequence: fibo_list = [55, 210, 340, 890, 3750]. You can see that in notebook.\n\nLast important explanation about my feature is using lag target. Firstly I tried to use the official calculation but then I just gave up and use this:\n\n```row[\"target_return\"] = (last_close / f[asset][\"all_close\"][-16]) -1```\n\nand for a market indicator, I collected new \"target_return\" for every batch, and get the average of last available list.\n\nLast important note for my work is models. I have 3 different LightGBM models that were trained for different market conditions. Up market, down market and relatively more stable market. Then I get the average of them.\n\nI thought about how could I improve my models. First thing is: I could do parameter optimization, I almost used default parameters. Then I could add different kind of models, I thing my submission time was around 6 hours. lastly, I had actually more feature in my mind.\n\nWell, thanks to everyone again.. See you in next competition.",
      "votes": null
    },
    {
      "id": "1784089",
      "postDate": "05/10/2022 23:36:36",
      "content": "<p>Well done on your 9th place finish! This is a great solution that makes use of some innovative features. I'm definitely going to have to try out the Hull moving average feature in my own models.</p>",
      "rawMarkdown": "Well done on your 9th place finish! This is a great solution that makes use of some innovative features. I'm definitely going to have to try out the Hull moving average feature in my own models.",
      "votes": null
    },
    {
      "id": "1784121",
      "postDate": "05/11/2022 00:19:10",
      "content": "<p><a href=\"https://www.kaggle.com/bturan19\" target=\"_blank\">@bturan19</a> congratulations on finishing in 9th place! What led you to choose your windows with a Fibonacci sequence?</p>",
      "rawMarkdown": "bturan19 congratulations on finishing in 9th place! What led you to choose your windows with a Fibonacci sequence?",
      "votes": null
    },
    {
      "id": "1784411",
      "postDate": "05/11/2022 06:55:19",
      "content": "<p>Actually it was something like a domain knowledge. Now, I'm not a trading expert or something but I know that, out there, people use this sequence very heavily, so, when I decide window sizes, I thought it would be better to use them instead of other random values.</p>",
      "rawMarkdown": "Actually it was something like a domain knowledge. Now, I'm not a trading expert or something but I know that, out there, people use this sequence very heavily, so, when I decide window sizes, I thought it would be better to use them instead of other random values.",
      "votes": null
    },
    {
      "id": "1790448",
      "postDate": "05/15/2022 00:25:41",
      "content": "<p>Congratulations! Your notebook is super helpful for me to learn how to create the lagged features in the real testing period when using the api, thank you so much!</p>",
      "rawMarkdown": "Congratulations! Your notebook is super helpful for me to learn how to create the lagged features in the real testing period when using the api, thank you so much!",
      "votes": null
    },
    {
      "id": "1790807",
      "postDate": "05/15/2022 11:05:49",
      "content": "<p>I'm glad if it helps</p>",
      "rawMarkdown": "I'm glad if it helps",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1784089,
      "author_name": "",
      "author_url": "",
      "post_date": "05/10/2022 23:36:36",
      "content": "<p>Well done on your 9th place finish! This is a great solution that makes use of some innovative features. I'm definitely going to have to try out the Hull moving average feature in my own models.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1784121,
      "author_name": "lachlangillian",
      "author_url": "",
      "post_date": "05/11/2022 00:19:10",
      "content": "<p><a href=\"https://www.kaggle.com/bturan19\" target=\"_blank\">@bturan19</a> congratulations on finishing in 9th place! What led you to choose your windows with a Fibonacci sequence?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1784411,
          "author_name": "bturan19",
          "author_url": "",
          "post_date": "05/11/2022 06:55:19",
          "content": "<p>Actually it was something like a domain knowledge. Now, I'm not a trading expert or something but I know that, out there, people use this sequence very heavily, so, when I decide window sizes, I thought it would be better to use them instead of other random values.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1790448,
      "author_name": "chiloiho",
      "author_url": "",
      "post_date": "05/15/2022 00:25:41",
      "content": "<p>Congratulations! Your notebook is super helpful for me to learn how to create the lagged features in the real testing period when using the api, thank you so much!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1790807,
          "author_name": "bturan19",
          "author_url": "",
          "post_date": "05/15/2022 11:05:49",
          "content": "<p>I'm glad if it helps</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1783525": "Hello everyone,\n\nFirstly, I want to thank you everyone in this competition, it was a great journey for me and I'm very happy to win a gold medal for the first time.\n\nI actually shared my inference [notebook](https://www.kaggle.com/code/bturan19/lgb-3fold-rollingagg-lagtarget-submissioninference/notebook) long ago. Now I want to give some information about it..\n\nMy most precious feature was Hull moving average:\n\n```#@jit(nopython=True)\ndef moving_average(a, n=3) :\n    ret = np.cumsum(a, dtype=float)\n    ret[n:] = ret[n:] - ret[:-n]\n    return np.append(np.array([1]*n), ret[n - 1:] / n)[1:]\n\n#@jit(nopython=True)\ndef calcHullMA_inference(series, N=50):\n    SMA1 = moving_average(series, N)\n    SMA2 = moving_average(series, int(N/2))\n    res = (2 * SMA2 - SMA1)\n    return np.mean(res[-int(np.sqrt(N)):])\n\nrow[\"hull\"] = last_close - calcHullMA_inference(f[asset][\"all_close\"][-260:], 240)\n```\n\nOther important note about creating lag feature, is the window size. I choose my windows with a Fibonacci sequence: fibo_list = [55, 210, 340, 890, 3750]. You can see that in notebook.\n\nLast important explanation about my feature is using lag target. Firstly I tried to use the official calculation but then I just gave up and use this:\n\n```row[\"target_return\"] = (last_close / f[asset][\"all_close\"][-16]) -1```\n\nand for a market indicator, I collected new \"target_return\" for every batch, and get the average of last available list.\n\nLast important note for my work is models. I have 3 different LightGBM models that were trained for different market conditions. Up market, down market and relatively more stable market. Then I get the average of them.\n\nI thought about how could I improve my models. First thing is: I could do parameter optimization, I almost used default parameters. Then I could add different kind of models, I thing my submission time was around 6 hours. lastly, I had actually more feature in my mind.\n\nWell, thanks to everyone again.. See you in next competition.",
    "1784089": "Well done on your 9th place finish! This is a great solution that makes use of some innovative features. I'm definitely going to have to try out the Hull moving average feature in my own models.",
    "1784121": "bturan19 congratulations on finishing in 9th place! What led you to choose your windows with a Fibonacci sequence?",
    "1784411": "Actually it was something like a domain knowledge. Now, I'm not a trading expert or something but I know that, out there, people use this sequence very heavily, so, when I decide window sizes, I thought it would be better to use them instead of other random values.",
    "1790448": "Congratulations! Your notebook is super helpful for me to learn how to create the lagged features in the real testing period when using the api, thank you so much!",
    "1790807": "I'm glad if it helps"
  },
  "source": "existing_discussion",
  "complete": true,
  "competition_id": 30894,
  "competition_slug": "g-research-crypto-forecasting",
  "team_id": 7659570,
  "solution_url": "/competitions/g-research-crypto-forecasting/writeups/bturan19-9th-place-solution-inference"
}