{
  "id": 286491,
  "title": "How VWAP is obtained/calculated?",
  "url": "/competitions/g-research-crypto-forecasting/discussion/286491",
  "author_name": "",
  "post_date": "2021-11-09T12:10:30.556505800Z",
  "votes": 9,
  "comment_count": 7,
  "views": 0,
  "content": "<p>I want to try to fill the gaps in the training data by collecting the information that it's missing (edit1: which is almost done: <a href=\"https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/285913)\" target=\"_blank\">https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/285913)</a>, but first I want to understand all the features. </p>\n<p>There is an ongoing notebook that is trying to <a href=\"https://www.kaggle.com/alexfir/recreating-target/notebook\" target=\"_blank\">recreate Target </a> as best as possible. </p>\n<p>I don't understand how VWAP is obtained/calculated.</p>\n<p>Here is some information. We have all this data in the train: </p>\n<p>train.csv - The training set </p>\n<ul>\n<li>timestamp - A timestamp for the minute covered by the row.</li>\n<li>Asset_ID - An ID code for the cryptoasset.</li>\n<li>Count - The number of trades that took place this minute.</li>\n<li>Open - The USD price at the beginning of the minute.</li>\n<li>High - The highest USD price during the minute.</li>\n<li>Low - The lowest USD price during the minute.</li>\n<li>Close - The USD price at the end of the minute.</li>\n<li>Volume - The number of cryptoasset units traded during the minute.</li>\n<li>VWAP - The volume weighted average price for the minute.</li>\n<li>Target - 15 minute residualized returns. See the 'Prediction and Evaluation' section of this notebook for details of how the target is calculated.</li>\n</ul>\n<p>Edit2: In this <a href=\"https://www.kaggle.com/ajpass/strict-trying-to-understand-vwap/notebook\" target=\"_blank\">notebook </a>I'm trying to answer these questions.</p>\n<p>Here some information about VWAP and how it's calculated:</p>\n<ul>\n<li><a href=\"https://www.investopedia.com/terms/v/vwap.asp\" target=\"_blank\">Article</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=ZMp-nvV5Kw0\" target=\"_blank\">Youtube Video</a></li>\n</ul>\n<p>Feel free to correct me if I'm wrong or point out if I'm missing something. </p>",
  "messages": [
    {
      "id": "1576717",
      "postDate": "11/09/2021 12:10:30",
      "content": "<p>I want to try to fill the gaps in the training data by collecting the information that it's missing (edit1: which is almost done: <a href=\"https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/285913)\" target=\"_blank\">https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/285913)</a>, but first I want to understand all the features. </p>\n<p>There is an ongoing notebook that is trying to <a href=\"https://www.kaggle.com/alexfir/recreating-target/notebook\" target=\"_blank\">recreate Target </a> as best as possible. </p>\n<p>I don't understand how VWAP is obtained/calculated.</p>\n<p>Here is some information. We have all this data in the train: </p>\n<p>train.csv - The training set </p>\n<ul>\n<li>timestamp - A timestamp for the minute covered by the row.</li>\n<li>Asset_ID - An ID code for the cryptoasset.</li>\n<li>Count - The number of trades that took place this minute.</li>\n<li>Open - The USD price at the beginning of the minute.</li>\n<li>High - The highest USD price during the minute.</li>\n<li>Low - The lowest USD price during the minute.</li>\n<li>Close - The USD price at the end of the minute.</li>\n<li>Volume - The number of cryptoasset units traded during the minute.</li>\n<li>VWAP - The volume weighted average price for the minute.</li>\n<li>Target - 15 minute residualized returns. See the 'Prediction and Evaluation' section of this notebook for details of how the target is calculated.</li>\n</ul>\n<p>Edit2: In this <a href=\"https://www.kaggle.com/ajpass/strict-trying-to-understand-vwap/notebook\" target=\"_blank\">notebook </a>I'm trying to answer these questions.</p>\n<p>Here some information about VWAP and how it's calculated:</p>\n<ul>\n<li><a href=\"https://www.investopedia.com/terms/v/vwap.asp\" target=\"_blank\">Article</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=ZMp-nvV5Kw0\" target=\"_blank\">Youtube Video</a></li>\n</ul>\n<p>Feel free to correct me if I'm wrong or point out if I'm missing something. </p>",
      "rawMarkdown": "I want to try to fill the gaps in the training data by collecting the information that it's missing (edit1: which is almost done: https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/285913), but first I want to understand all the features. \n\nThere is an ongoing notebook that is trying to [recreate Target ](https://www.kaggle.com/alexfir/recreating-target/notebook) as best as possible. \n\nI don't understand how VWAP is obtained/calculated.\n\nHere is some information. We have all this data in the train: \n\ntrain.csv - The training set \n- timestamp - A timestamp for the minute covered by the row.\n- Asset_ID - An ID code for the cryptoasset.\n- Count - The number of trades that took place this minute.\n- Open - The USD price at the beginning of the minute.\n- High - The highest USD price during the minute.\n- Low - The lowest USD price during the minute.\n- Close - The USD price at the end of the minute.\n- Volume - The number of cryptoasset units traded during the minute.\n- VWAP - The volume weighted average price for the minute.\n- Target - 15 minute residualized returns. See the 'Prediction and Evaluation' section of this notebook for details of how the target is calculated.\n\n\nEdit2: In this [notebook ](https://www.kaggle.com/ajpass/strict-trying-to-understand-vwap/notebook)I'm trying to answer these questions.\n\nHere some information about VWAP and how it's calculated:\n- [Article](https://www.investopedia.com/terms/v/vwap.asp)\n- [Youtube Video](https://www.youtube.com/watch?v=ZMp-nvV5Kw0)\n\n\n\nFeel free to correct me if I'm wrong or point out if I'm missing something.",
      "votes": null
    },
    {
      "id": "1576793",
      "postDate": "11/09/2021 13:16:33",
      "content": "<p><code>VWAP</code> measures the average trading price for the minute. I'm sharing the code to better understand how it's computed:</p>\n<pre><code>def VWAP(df, period=1):\n    df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']\n    df['VWAP_Source'] = pd.Series(df['VWAP_Pre'].rolling(period,min_periods=period).mean())\n    df['VolumeSMA'] = pd.Series(df['Volume'].rolling(period, min_periods=period).mean())\n    df['VWAP'] =  df['VWAP_Source']/df['VolumeSMA']\n    return df['VWAP']\n</code></pre>",
      "rawMarkdown": "`VWAP` measures the average trading price for the minute. I'm sharing the code to better understand how it's computed:\n```\ndef VWAP(df, period=1):\n    df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']\n    df['VWAP_Source'] = pd.Series(df['VWAP_Pre'].rolling(period,min_periods=period).mean())\n    df['VolumeSMA'] = pd.Series(df['Volume'].rolling(period, min_periods=period).mean())\n    df['VWAP'] =  df['VWAP_Source']/df['VolumeSMA']\n    return df['VWAP']\n```",
      "votes": null
    },
    {
      "id": "1576921",
      "postDate": "11/09/2021 14:58:18",
      "content": "<p>Thank you for your comment <a href=\"https://www.kaggle.com/abdelghanibelgaid\" target=\"_blank\">@abdelghanibelgaid</a>. I tried calculting VWAP with your function with asset=bitcoin, and there is quite big difference between VWAP feature from data and your function output. I shared my notebook to you, so you can see what I'm talking about. </p>",
      "rawMarkdown": "Thank you for your comment @abdelghanibelgaid. I tried calculting VWAP with your function with asset=bitcoin, and there is quite big difference between VWAP feature from data and your function output. I shared my notebook to you, so you can see what I'm talking about.",
      "votes": null
    },
    {
      "id": "1576949",
      "postDate": "11/09/2021 15:32:36",
      "content": "<p>Indeed, there is a small difference between the <code>VWAP</code> feature from data and this function output. In the case of <code>Bitcoin</code>, the mean absolute deviation is about ~2.65. That might be the result of rounding numbers during computing the <code>VWAP</code>.</p>",
      "rawMarkdown": "Indeed, there is a small difference between the `VWAP` feature from data and this function output. In the case of `Bitcoin`, the mean absolute deviation is about ~2.65. That might be the result of rounding numbers during computing the `VWAP`.",
      "votes": null
    },
    {
      "id": "1577034",
      "postDate": "11/09/2021 17:39:52",
      "content": "<p>It can be. One thing I tried is modifying the first line of the function</p>\n<p><code>df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']</code><br>\nto<br>\n<code>df['VWAP_Pre'] = ((df['Open']+df['High']+df['Low']+ df['Close'])/4) * df['Volume']</code> and the MAE reduced. </p>\n<p>Edit: Which makes no sense for calculating VWAP.</p>",
      "rawMarkdown": "It can be. One thing I tried is modifying the first line of the function\n\n`df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']`\nto\n`df['VWAP_Pre'] = ((df['Open']+df['High']+df['Low']+ df['Close'])/4) * df['Volume']` and the MAE reduced. \n\nEdit: Which makes no sense for calculating VWAP.",
      "votes": null
    },
    {
      "id": "1577652",
      "postDate": "11/10/2021 09:23:58",
      "content": "<p>I updated my notebook to visualize this:</p>\n<p>If the period=1, the VWAP value it's the same with function VWAP you provided and the next line:</p>\n<p>bitcoin['VWAP3'] = (df['High']+df['Low']+ df['Close'])/3</p>",
      "rawMarkdown": "I updated my notebook to visualize this:\n\nIf the period=1, the VWAP value it's the same with function VWAP you provided and the next line:\n\nbitcoin['VWAP3'] = (df['High']+df['Low']+ df['Close'])/3",
      "votes": null
    },
    {
      "id": "1578604",
      "postDate": "11/11/2021 07:52:25",
      "content": "<p>In the last competition(<a href=\"https://www.kaggle.com/c/optiver-realized-volatility-prediction/data)\" target=\"_blank\">https://www.kaggle.com/c/optiver-realized-volatility-prediction/data)</a>, optiver revealed the size/price of bid/ask, and it was able to figure out the VWAP value.<br>\nPerhaps the reason for including VWAP itself in the dataset in this competition is to prevent overfitting due to excessive feature engineering? My very personal opinion :)</p>",
      "rawMarkdown": "In the last competition(https://www.kaggle.com/c/optiver-realized-volatility-prediction/data), optiver revealed the size/price of bid/ask, and it was able to figure out the VWAP value.\nPerhaps the reason for including VWAP itself in the dataset in this competition is to prevent overfitting due to excessive feature engineering? My very personal opinion :)",
      "votes": null
    },
    {
      "id": "1578719",
      "postDate": "11/11/2021 09:35:50",
      "content": "<p>Thanks <a href=\"https://www.kaggle.com/yuuniekiri\" target=\"_blank\">@yuuniekiri</a> for your answer, makes sense to me. </p>",
      "rawMarkdown": "Thanks @yuuniekiri for your answer, makes sense to me.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1576793,
      "author_name": "abdelghanibelgaid",
      "author_url": "",
      "post_date": "11/09/2021 13:16:33",
      "content": "<p><code>VWAP</code> measures the average trading price for the minute. I'm sharing the code to better understand how it's computed:</p>\n<pre><code>def VWAP(df, period=1):\n    df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']\n    df['VWAP_Source'] = pd.Series(df['VWAP_Pre'].rolling(period,min_periods=period).mean())\n    df['VolumeSMA'] = pd.Series(df['Volume'].rolling(period, min_periods=period).mean())\n    df['VWAP'] =  df['VWAP_Source']/df['VolumeSMA']\n    return df['VWAP']\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 1576921,
          "author_name": "ajpass",
          "author_url": "",
          "post_date": "11/09/2021 14:58:18",
          "content": "<p>Thank you for your comment <a href=\"https://www.kaggle.com/abdelghanibelgaid\" target=\"_blank\">@abdelghanibelgaid</a>. I tried calculting VWAP with your function with asset=bitcoin, and there is quite big difference between VWAP feature from data and your function output. I shared my notebook to you, so you can see what I'm talking about. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1576949,
          "author_name": "abdelghanibelgaid",
          "author_url": "",
          "post_date": "11/09/2021 15:32:36",
          "content": "<p>Indeed, there is a small difference between the <code>VWAP</code> feature from data and this function output. In the case of <code>Bitcoin</code>, the mean absolute deviation is about ~2.65. That might be the result of rounding numbers during computing the <code>VWAP</code>.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1577034,
          "author_name": "ajpass",
          "author_url": "",
          "post_date": "11/09/2021 17:39:52",
          "content": "<p>It can be. One thing I tried is modifying the first line of the function</p>\n<p><code>df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']</code><br>\nto<br>\n<code>df['VWAP_Pre'] = ((df['Open']+df['High']+df['Low']+ df['Close'])/4) * df['Volume']</code> and the MAE reduced. </p>\n<p>Edit: Which makes no sense for calculating VWAP.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1577652,
          "author_name": "ajpass",
          "author_url": "",
          "post_date": "11/10/2021 09:23:58",
          "content": "<p>I updated my notebook to visualize this:</p>\n<p>If the period=1, the VWAP value it's the same with function VWAP you provided and the next line:</p>\n<p>bitcoin['VWAP3'] = (df['High']+df['Low']+ df['Close'])/3</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1578604,
      "author_name": "yuuniekiri",
      "author_url": "",
      "post_date": "11/11/2021 07:52:25",
      "content": "<p>In the last competition(<a href=\"https://www.kaggle.com/c/optiver-realized-volatility-prediction/data)\" target=\"_blank\">https://www.kaggle.com/c/optiver-realized-volatility-prediction/data)</a>, optiver revealed the size/price of bid/ask, and it was able to figure out the VWAP value.<br>\nPerhaps the reason for including VWAP itself in the dataset in this competition is to prevent overfitting due to excessive feature engineering? My very personal opinion :)</p>",
      "votes": null,
      "replies": [
        {
          "id": 1578719,
          "author_name": "ajpass",
          "author_url": "",
          "post_date": "11/11/2021 09:35:50",
          "content": "<p>Thanks <a href=\"https://www.kaggle.com/yuuniekiri\" target=\"_blank\">@yuuniekiri</a> for your answer, makes sense to me. </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1576717": "I want to try to fill the gaps in the training data by collecting the information that it's missing (edit1: which is almost done: https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/285913), but first I want to understand all the features. \n\nThere is an ongoing notebook that is trying to [recreate Target ](https://www.kaggle.com/alexfir/recreating-target/notebook) as best as possible. \n\nI don't understand how VWAP is obtained/calculated.\n\nHere is some information. We have all this data in the train: \n\ntrain.csv - The training set \n- timestamp - A timestamp for the minute covered by the row.\n- Asset_ID - An ID code for the cryptoasset.\n- Count - The number of trades that took place this minute.\n- Open - The USD price at the beginning of the minute.\n- High - The highest USD price during the minute.\n- Low - The lowest USD price during the minute.\n- Close - The USD price at the end of the minute.\n- Volume - The number of cryptoasset units traded during the minute.\n- VWAP - The volume weighted average price for the minute.\n- Target - 15 minute residualized returns. See the 'Prediction and Evaluation' section of this notebook for details of how the target is calculated.\n\n\nEdit2: In this [notebook ](https://www.kaggle.com/ajpass/strict-trying-to-understand-vwap/notebook)I'm trying to answer these questions.\n\nHere some information about VWAP and how it's calculated:\n- [Article](https://www.investopedia.com/terms/v/vwap.asp)\n- [Youtube Video](https://www.youtube.com/watch?v=ZMp-nvV5Kw0)\n\n\n\nFeel free to correct me if I'm wrong or point out if I'm missing something.",
    "1576793": "`VWAP` measures the average trading price for the minute. I'm sharing the code to better understand how it's computed:\n```\ndef VWAP(df, period=1):\n    df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']\n    df['VWAP_Source'] = pd.Series(df['VWAP_Pre'].rolling(period,min_periods=period).mean())\n    df['VolumeSMA'] = pd.Series(df['Volume'].rolling(period, min_periods=period).mean())\n    df['VWAP'] =  df['VWAP_Source']/df['VolumeSMA']\n    return df['VWAP']\n```",
    "1576921": "Thank you for your comment @abdelghanibelgaid. I tried calculting VWAP with your function with asset=bitcoin, and there is quite big difference between VWAP feature from data and your function output. I shared my notebook to you, so you can see what I'm talking about.",
    "1576949": "Indeed, there is a small difference between the `VWAP` feature from data and this function output. In the case of `Bitcoin`, the mean absolute deviation is about ~2.65. That might be the result of rounding numbers during computing the `VWAP`.",
    "1577034": "It can be. One thing I tried is modifying the first line of the function\n\n`df['VWAP_Pre'] = ((df['High']+df['Low']+ df['Close'])/3) * df['Volume']`\nto\n`df['VWAP_Pre'] = ((df['Open']+df['High']+df['Low']+ df['Close'])/4) * df['Volume']` and the MAE reduced. \n\nEdit: Which makes no sense for calculating VWAP.",
    "1577652": "I updated my notebook to visualize this:\n\nIf the period=1, the VWAP value it's the same with function VWAP you provided and the next line:\n\nbitcoin['VWAP3'] = (df['High']+df['Low']+ df['Close'])/3",
    "1578604": "In the last competition(https://www.kaggle.com/c/optiver-realized-volatility-prediction/data), optiver revealed the size/price of bid/ask, and it was able to figure out the VWAP value.\nPerhaps the reason for including VWAP itself in the dataset in this competition is to prevent overfitting due to excessive feature engineering? My very personal opinion :)",
    "1578719": "Thanks @yuuniekiri for your answer, makes sense to me."
  },
  "source": "meta"
}