account_portfolio: Account Portfolio History

View source: R/Account.R

account_portfolioR Documentation

Account Portfolio History

Description

The portfolio history endpoint returns a timeseries of equity and profit/loss summaries for the account over a period previous aggregated by a given timeframe.

Usage

account_portfolio(
  period = NULL,
  timeframe = NULL,
  date_end = NULL,
  extended_hours = FALSE,
  live = get_live()
)

Arguments

period

(character/Duration/Period) Optional The period of time previous starting at date_end in number + unit format over which data will be provided. Such as one day "1D".

  • `"D"` day

  • `"W"` week

  • `"M"` month

  • `"A/Y"` year

Defaults to "1M". Accepts any number for the multiplier. Non case-sensitive. Also accepts period & duration objects.

timeframe

(character) Optional The timeframe of the returned data in "MT" format where M is a multiplier and T is the timeframe from one of the following (non case-sensitive): #'

  • 'm'/'min'/'minute' (multiplier can be 1/5/15)

  • 'h'/'hour' multiplier will be 1.

  • 'd'/'day' (multiplier will be 1)

If omitted, "⁠1Min⁠" for less than 7 days period, "⁠15Min⁠" for less than 30 days, or otherwise "1D".

date_end

(Date/POSIXlt/Datetime(POSIXct)/character) Optional See Details for formatting guidelines. The end date of the returned data. Defaults to the current market date (rolls over at the market open if extended_hours = FALSE, otherwise at 7am ET). Note that when ⁠period = 1D⁠ and date_end is supplied, the API returns no data.

extended_hours

(logical) Optional If true, include extended hours in the result. This is effective only for timeframes less than 1D. Default FALSE

live

(logical) TRUE / FALSE if you are connecting to a live account. Default to FALSE, so it will use the paper url if nothing was provided.

Details

All (Date/POSIXlt) will parse correctly if in YYYY-MM-DD RFC 3339 format or (Datetime/POSIXct), ⁠YYYY-MM-DD HH:MM⁠ ISO8601 format. Other formats will often work, but are not guaranteed to parse correctly.

Value

A PortfolioHistory (tibble) Object with R amenable data types. Note that base value & timeframe can be accessed by calling attr(out, "info") on the returned tibble.

  • timestamp (Date/POSIXlt/Datetime(POSIXct)/character) time of each data element, with the first element being the beginning of the time window.

  • equity (numeric) equity value of the account in dollar amount as of the end of each time window

  • profit_loss (numeric) profit/loss in dollar from the base value

  • profit_loss_pct (numeric) profit/loss in percentage from the base value

  • base_value (numeric) basis in dollar of the profit loss calculation

  • timeframe (character) time window size of each data element

See Also

Other Account: account_activities(), account_config(), account()

Examples

# Get the previous year's returns for the paper account
account_portfolio("1y")
# Get portfolio history when the COVID-19 pandemic overtook the US
account_portfolio("3m", date_end = "2020-05-20")

jagg19/AlpacaforR documentation built on July 3, 2023, 12:14 p.m.