title: How can I obtain this specific series data to calculate time-to-funding-weighted average of premium index?
body: <p>I'm looking to calculate and plot the funding rate of Binance BTCUSDT Perpetual and have come across the following documentation page: <a href="https://www.binance.com/en/support/faq/360033525031" rel="nofollow noreferrer">https://www.binance.com/en/support/faq/360033525031</a></p>
  <p>It states:</p>
  <p>The Funding Rate formula:</p>
  <p>&quot;Funding Rate (F) = Average Premium Index (P) + clamp (interest rate - Premium Index (P), 0.05%, -0.05%)&quot;</p>
  <p>I'm obtaining the &quot;Premium Index&quot; just fine, just with &quot;p = request.security(&quot;BINANCE:BTCUSDT_PREMIUM&quot;, &quot;&quot;, close)*100&quot;</p>
  <p>However I'm currently struggling with how to obtain the:</p>
  <p>&quot;Time-to-funding weighted Average of Premium Index &quot; which apparently is calculated with</p>
  <p>&quot;Average Premium Index (P) = (1 * Premium_Index_1 + 2 * Premium_Index_2 + 3 * Premium_Index_3 +···+·480 * Premium_index_480)/(1+2+3+···+480)&quot;</p>
  <p>(the funding period for Binance is 8 hours hence the average over 480 minutes)</p>
  <p>My exact question is, how do I backtrack to the last funding timestamp of 00:00 / 08:00 / 16:00, then obtain an array / series data of the premium index at each of the last 480 minutes, so that I can then iterate over it to use the above formula for the time weighted average?</p>
  <p>Thank you very much for any advice in advance. My apologies if the answer is obvious I'm very new to Pine Script.</p>