Caprikuarius2
Caprikuarius2

Reputation: 185

How to obtain split and dividend adjusted prices using alpaca_trade_api?

I am modelling the minute prices of stocks and I obtain the data using the alpaca_trade_api from Python:

api = tradeapi.REST(api_key, secret_key, 'https://paper-api.alpaca.markets')
data = api.get_barset('AAPL', 'minute', end=datetime.datetime(2020, 11, 5, 10, 00, 0, 0, 
                              timezone('US/Eastern')).isoformat(), limit=1)

However, the data is not adjusted on splits or dividends, and it will screw up the models if the splits or dividends occur (i.e. stock prices will have a very sharp increase or decrease). Is there a good way to obtain the adjusted price automatically?

Upvotes: 2

Views: 1489

Answers (2)

appancrp
appancrp

Reputation: 21

You can use the adjustment parameter, refer into the doc:

https://alpaca.markets/deprecated/docs/api-documentation/api-v2/market-data/alpaca-data-api-v2/historical/#:~:text=%2C%201Day.-,adjustment,-string

api.get_bars("AAPL", "1D", "2021-06-08", "2021-06-08", adjustment='split')

Upvotes: 1

Lewis
Lewis

Reputation: 789

Add the adjustment="split" to the api.get_barset.
It should look like this

api = tradeapi.REST(api_key, secret_key, 'https://paper-api.alpaca.markets')
data = api.get_barset('AAPL', 'minute', end=datetime.datetime(2020, 11, 5, 10, 00, 0, 0, 
              timezone('US/Eastern')).isoformat(), limit=1, adjustment="split")

Upvotes: 0

Related Questions