Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Ronan Dunham
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    R
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 9
    • Best 0
    • Groups 0

    Ronan Dunham

    @Ronan Dunham

    0
    Reputation
    17
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Ronan Dunham Unfollow Follow

    Latest posts made by Ronan Dunham

    • RE: api.polygon.historic_agg returns incorrect timestamp

      Hi @backtrader ,

      Thank you for the reply.

      api = alpaca_trade_api.REST(
          base_url=base_url,
          key_id=api_key_id,
          secret_key=api_secret)
      

      this is indeed alpaca_trade_api.REST(). How can I get only the last 6 data bars from the code? what changes would i have to make. Would you happen to know? Thanks in advance.

      @vladisld I did post in alpaca forum but havenot received any feedback for days. I seem to get help here more often. Sorry didnot mean to spam this forum.

      posted in General Code/Help
      R
      Ronan Dunham
    • api.polygon.historic_agg returns incorrect timestamp
      symbols="TSLA"
      minute_history ={}
      minute_history[symbols] = api.polygon.historic_agg(
          size="minute", symbol=symbols, limit=6,to='2020-01-03 14:59:00-0500'
      ).df
      df=minute_history[symbols]
      df
      

      the output seems as below:
      82ea676c-d2e3-4921-ae82-1fb90f766e4d-image.png

      i am only looking at last 6 data points (each every last 6 mins before 1-3 14:59 pm.

      What is wrong here. Please help

      posted in General Code/Help
      R
      Ronan Dunham
    • backtrader data same for 5days vs 50 days

      Hi All,

      cerebro = bt.Cerebro()
      cerebro.addstrategy(SmaCross)
      store = alpaca_backtrader_api.AlpacaStore(key_id=api_key_id,secret_key=api_secret,paper=base_url)
      
      days_to_cross = 5
      date_N_days_ago = datetime.now() - timedelta(days=days_to_cross)
      DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData
      
      data0 = DataFactory(
          dataname=stockSymbol,
          timeframe=bt.TimeFrame.TFrame("Minutes"),
          fromdate=pd.Timestamp(date_N_days_ago),compression =1, #compression =1 for 1 Min
      #         todate=pd.Timestamp('2018-11-17'),
          historical=True)
      cerebro.adddata(data0)
      
      cerebro.run()
      mktData = SmaCross.df
      mktData["Dates"]= mktData.index
      return mktData 
      

      On this code 5 days of data or 50 dys of data it returns the same data point.
      I would like to control # of data points with variable days_to_cross. How can this be corrected?
      Also please feedback if I should have asked to questions somewhat relevant on this topic already started or create a new thread.What would be an efficient way to keep this community questionings clean? I am a newbie.

      posted in General Code/Help
      R
      Ronan Dunham
    • RE: How to get the data as array of the sma1 and sma2

      Got it it works with SmaCross.df =df.

      Thank you

      posted in General Code/Help
      R
      Ronan Dunham
    • RE: How to get the data as array of the sma1 and sma2

      Hi All,

      Can you help me get the dataframe df from stop(self) to be used in a jupyter cell without having to write in a csv file? Any help is greatly appreciated.

      posted in General Code/Help
      R
      Ronan Dunham
    • RE: How to get the data as array of the sma1 and sma2

      @stochastick Thank you so much. I got the data that I wanted:

      ```
      
      Date Time	Close	SMA1	SMA2
      0	2019-11-15 13:15:00	351.8501	351.34751	350.981837
      1	2019-11-15 13:16:00	351.8500	351.44551	351.036837
      2	2019-11-15 13:18:00	351.6800	351.51351	351.091170
      3	2019-11-15 13:19:00	351.6000	351.57351	351.117837
      4	2019-11-15 13:20:00	351.7000	351.62351	351.181170
      ...	...	...	...	...
      15809	2019-12-28 00:50:00	430.7600	430.72199	430.634997
      15810	2019-12-28 00:53:00	430.5000	430.70199	430.634997
      15811	2019-12-28 00:56:00	430.3300	430.65499	430.635663
      15812	2019-12-28 00:57:00	430.8000	430.66499	430.648997
      15813	2019-12-28 00:59:00	430.7500	430.66999	430.654663
      15814 rows × 4 columns
      

      Now all i need is this data without a text file. Just as a dataframe to use it in Jupyter cell. I donot need to make any strategy at all (again all i need is data from this specific source, other source like api.get_barset was missing a lot of data for me and this seem to work.)

      Is there a way that is efficient to get this done without having to read from a csv file and directly use df in the cell?

      Thanks a lot again.

      posted in General Code/Help
      R
      Ronan Dunham
    • RE: How to get the data as array of the sma1 and sma2

      Hi @stochastick thank you so much for the reply. I am super new to object oriented programming. How do i combine in df after stop() and how to call this data in the main program outside the class? Also how about the stock closing price and date.
      Sorry for the silly ask but as you can tell I am embarrassingly new to OOP.

      posted in General Code/Help
      R
      Ronan Dunham
    • RE: How to get the data as array of the sma1 and sma2

      Below is the complete and correct code:

      The code works I am looking to get a dataframe with data as below: to_BT_forum.png

      class SmaCross(bt.SignalStrategy):
          def __init__(self):
              sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
              crossover = bt.ind.CrossOver(sma1, sma2)
              self.signal_add(bt.SIGNAL_LONG, crossover)
      
      cerebro = bt.Cerebro()
      cerebro.addstrategy(SmaCross)
      store = alpaca_backtrader_api.AlpacaStore(key_id=ALPACA_API_KEY,secret_key=ALPACA_SECRET_KEY,paper=ALPACA_PAPER)
      DataFactory = store.getdata
      
      data0 = DataFactory(
              dataname=symbol_to_check,
              timeframe=bt.TimeFrame.TFrame("Minutes"),
              fromdate=pd.Timestamp('2019-11-15'),compression =1,
      #         todate=pd.Timestamp('2018-11-17'),
              historical=True)
      
      cerebro.adddata(data0)
      
      cerebro.run()
      cerebro.plot()
      posted in General Code/Help
      R
      Ronan Dunham
    • How to get the data as array of the sma1 and sma2

      HI BT community,
      I need sma1 and sma2 and date and closing price of a stock. I tried all my best to extract this data from the code below but somehow could not get the final data in a dataframe. Can someone help with this please? All I need is a dataframe with columns: DateTime, Closing Price, SMA1(which is 10 SMA) and SMA2(which is 30SMA). Any help is much appreciated.

      import backtrader as bt
      
      class SmaCross(bt.SignalStrategy):
          def __init__(self):
              sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
              crossover = bt.ind.CrossOver(sma1, sma2)
              self.signal_add(bt.SIGNAL_LONG, crossover)
      
      cerebro = bt.Cerebro()
      cerebro.addstrategy(SmaCross)
      
      data0 = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1),
                                        todate=datetime(2012, 12, 31))
      cerebro.adddata(data0)
      
      cerebro.run()
      cerebro.plot()
      posted in General Code/Help
      R
      Ronan Dunham