alpacahq / alpacahq/Alpaca-API

Rest API get_portfolio_history returns incorrect data beyond 1 day

Aperta
#223 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
173
Fork
17
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When requesting get_portfolio_history intraday equity appears to be calculated by profit_loss added to base_value. When requesting more than one day, intraday profit_loss returns are relative to their respective day base_value, however equity appears to be calculated by adding profit_loss to the initial day base_value. The result is incorrect equity values when requesting timeframes <1 day on periods >1 day.

**To Reproduce**
![image](https://user-images.githubusercontent.com/4991768/158005220-a065bb18-09c6-4ad2-b5d7-fecc204b3cd7.png)

Crude client side fix example below. Not sure if this comes from the raw api output or is isolated to the python rest api, but in either case there are probably more efficient ways to do it.

> data = api.get_portfolio_history(period='4D', timeframe='1Min')
> history = np.array(data.equity)
>
> base_values = np.array(api.get_portfolio_history(period='5D', timeframe='1D').equity)
> base_values = (base_values - base_values[0])[:-1]
>
> for bvd in range(len(base_values)):
> history[(bvd * 391):(bvd * 391)+391] = history[(bvd * 391):(bvd * 391)+391] + base_values[bvd]

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.