0

I would like to calculate the ADR for the last 5 days, but I have the problem that I don't know how to get the 5 days because I "only" have 1 minute Time Frame datas. So I would have to screw it up, but no matter what I try I never get the right result when I compare it with Tradingview Here is the code:

from backtesting import Backtest, Strategy
import pandas as pd

def getADR(highs,lows):
    high = highs.max()
    low = lows.min()
    return high-low
class MyStrategy(Strategy):

    def init(self):
        pass
    def next(self):
        high = self.data.High[-1]
        open = self.data.Open[-1]
        low = self.data.Low[-1]
        close = self.data.Close[-1]
        # And here I want to check the ADR of the last 5 days. So I have to somehow make 5 daily data out of the 1 minute data
        xx = getADR(self.data.High[""" :390? i dont know """],self.data.High[""" :390? i dont know """])

df = pd.read_csv('AAPL_Stock1m.csv',index_col='Timestamp',parse_dates=True)
bt = Backtest(df,MyStrategy,cash=50000)
print(bt.run())


My Index looks like this (shortened) https://pastebin.com/WaDvhGES

I hope that someone can help me with my problem :)

I tried to go through the index until I got 5 days out, e.g. [-390:] and then [-400] etc. but somehow the ADR result is not correct.

ADR = High(max)-Low(min)
  • Refrain from showing your dataframe as an image. Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Jul 14 '23 at 23:17
  • its just this: df = pd.read_csv('AAPL_Stock1m.csv',index_col='Timestamp',parse_dates=True) bt = Backtest(df,MyStrategy,cash=50000) print(bt.run()) – AnonymiumJsj82 Jul 15 '23 at 06:36
  • I updated the code It's not a complicated problem per se, but I've never done it and I just can't find an example of it Basically, I just want to make a day time frame out of the 1 minute time frame But ONLY for the last 5 days that I can check what the ADR of the last 5 days is – AnonymiumJsj82 Jul 15 '23 at 06:39
  • ***DO NOT*** post images of your index - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. For more information please see the Meta FAQ entry [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) – itprorh66 Jul 15 '23 at 14:51

0 Answers0