Please fix JNUG data. Does not match yahoo data
The IEX data which Alpaca uses for the
get_barset method is NOT split adjusted. The Yahoo data is split adjusted. That is why the two appear to not match. The IEX data is the actual price on a specific day while the Yahoo data is backwards ‘adjusted’ to account for subsequent stock splits. Sometimes the actual prices are desired (eg that is what one would have actually paid for a stock) and sometimes the split adjusted prices are more appropriate (eg to calculate returns).
There were two reverse splits during the timeframe in the Yahoo screenshot which Yahoo ‘adjusts for’ (06/28/2019 1:5 and 04/23/2020 1:10).
To get split adjusted prices use Polygon data and the associated APIs. Something like this will fetch the split adjusted close prices from 1-1-2019 through 9-12-2020.
poly_jnug_bars = api.polygon.historic_agg_v2(symbol= 'JNUG', multiplier=1, timespan='day', _from='2019-1-1', to='2020-9-12').df poly_jnug_bars.close.plot()
This results is a plot more similar to the Yahoo data.
Note that both the Polygon and Yahoo data are adjusted as of the day they are viewed. So saving data from one day to the next can result in incorrectly adjusted data. Also note that Polygon data is only adjusted for splits and NOT dividends (Yahoo is similar) so, depending upon the use case, the total returns may not be entirely reflected in the data.
Hope that helps.