panoptic-labs / research

At Panoptic, we recognize the power of open source code in promoting research integrity and collaboration. We strive to maintain a transparent work environment that allows us all to learn from each other's findings by sharing our coding projects through GitHub - creating an enriched experience for everyone involved!
https://www.panoptic.xyz/
70 stars 10 forks source link

Definition of '1 day' #24

Open BrandonL20 opened 1 year ago

BrandonL20 commented 1 year ago

Currently, code computes '1 day' as longer than a day, and also assumes an open price equal to the last close price (which is technically fine, but I think it makes more sense to have open price be the start of the next day).

For example, the code starts out as follows: Day 1 open: 2021-05-05 08:35:47+0000 Day 1 close: 2021-05-06 09:00:52+0000 Day 2 open: 2021-05-06 09:00:52+0000 Day 2 close: 2021-05-07 09:12:53+0000 ... Day 623 open: 2023-01-25 12:08:35+0000

Recommended changes:

https://github.com/panoptic-labs/research/blob/4e463cd9e8d421a067d25f1b2fbf1f39b3edac03/_research-bites/20230112/ResearchBites-20230112-Autoroll.ipynb?short_path=c0c4987#L121 startDay = t.replace(hour=0, minute=0, second=0)

https://github.com/panoptic-labs/research/blob/4e463cd9e8d421a067d25f1b2fbf1f39b3edac03/_research-bites/20230112/ResearchBites-20230112-Autoroll.ipynb?short_path=c0c4987#L515 if i+1 == len(timestamp30) or (timestamp30[i+1]-startDay).total_seconds()>=nSecs:

https://github.com/panoptic-labs/research/blob/4e463cd9e8d421a067d25f1b2fbf1f39b3edac03/_research-bites/20230112/ResearchBites-20230112-Autoroll.ipynb?short_path=c0c4987#L530-L537

if i+1 < len(timestamp30):
    startDay = timestamp30[i+1].replace(hour=0, minute=0, second=0)
    startTick = ticks30[i+1]
    startSqrtPrice = sqrtPrice30[i+1]
    startPrice = sqrtPrice30[i+1]**2
    # print("time: ", t)
    startLiq = positionSize / (np.sqrt(startPrice) - np.sqrt(startPrice/r))
    startX = X(startPrice, startPrice, r, startLiq)
    startY = Y(startPrice, startPrice, r, startLiq)
    positionRange = range(startTick - w, startTick + w)

However, please note that changing this will result in nSecs=24*3600 only working for discrete intervals of exactly 1 day (24*3600) due to .replace(hour=0, minute=0, second=0).