EVOLUTION-MANAGER
Edit File: to.period.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Convert time series data to an OHLC series</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for to.period {xts}"><tr><td>to.period {xts}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Convert time series data to an OHLC series </h2> <h3>Description</h3> <p>Convert an OHLC or univariate object to a specified periodicity lower than the given data object. For example, convert a daily series to a monthly series, or a monthly series to a yearly one, or a one minute series to an hourly series. </p> <p>The result will contain the open and close for the given period, as well as the maximum and minimum over the new period, reflected in the new high and low, respectively. </p> <p>If volume for a period was available, the new volume will also be calculated. </p> <h3>Usage</h3> <pre> to.minutes(x,k,name,...) to.minutes3(x,name,...) to.minutes5(x,name,...) to.minutes10(x,name,...) to.minutes15(x,name,...) to.minutes30(x,name,...) to.hourly(x,name,...) to.daily(x,drop.time=TRUE,name,...) to.weekly(x,drop.time=TRUE,name,...) to.monthly(x,indexAt='yearmon',drop.time=TRUE,name,...) to.quarterly(x,indexAt='yearqtr',drop.time=TRUE,name,...) to.yearly(x,drop.time=TRUE,name,...) to.period(x, period = 'months', k = 1, indexAt, name=NULL, OHLC = TRUE, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p> a univariate or OHLC type time-series object </p> </td></tr> <tr valign="top"><td><code>period</code></td> <td> <p> period to convert to. See details. </p> </td></tr> <tr valign="top"><td><code>indexAt</code></td> <td> <p> convert final index to new class or date. See details </p> </td></tr> <tr valign="top"><td><code>drop.time</code></td> <td> <p> remove time component of POSIX datestamp (if any) </p> </td></tr> <tr valign="top"><td><code>k</code></td> <td> <p> number of sub periods to aggregate on (only for minutes and seconds) </p> </td></tr> <tr valign="top"><td><code>name</code></td> <td> <p> override column names </p> </td></tr> <tr valign="top"><td><code>OHLC</code></td> <td> <p> should an OHLC object be returned? (only <code>OHLC=TRUE</code> currently supported) </p> </td></tr> </table> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p> additional arguments </p> </td></tr> </table> <h3>Details</h3> <p>Essentially an easy and reliable way to convert one periodicity of data into any new periodicity. It is important to note that all dates will be aligned to the <em>end</em> of each period by default - with the exception of <code>to.monthly</code> and <code>to.quarterly</code>, which index by ‘yearmon’ and ‘yearqtr’ from the <span class="pkg">zoo</span> package, respectively. </p> <p>Valid period character strings include: <code>"seconds"</code>, <code>"minutes"</code>, <code>"hours"</code>, <code>"days"</code>, <code>"weeks"</code>, <code>"months"</code>, <code>"quarters"</code>, and <code>"years"</code>. These are calculated internally via <code>endpoints</code>. See that function's help page for further details. </p> <p>To adjust the final indexing style, it is possible to set <code>indexAt</code> to one of the following: ‘yearmon’, ‘yearqtr’, ‘firstof’, ‘lastof’, ‘startof’, or ‘endof’. The final index will then be <code>yearmon</code>, <code>yearqtr</code>, the first time of the period, the last time of the period, the starting time in the data for that period, or the ending time in the data for that period, respectively. </p> <p>It is also possible to pass a single time series, such as a univariate exchange rate, and return an OHLC object of lower frequency - e.g. the weekly OHLC of the daily series. </p> <p>Setting <code>drop.time</code> to <code>TRUE</code> (the default) will convert a series that includes a time component into one with just a date index, as the time index is often of little value in lower frequency series. </p> <p>It is not possible to convert a series from a lower periodicity to a higher periodicity - e.g. weekly to daily or daily to 5 minute bars, as that would require magic. </p> <h3>Value</h3> <p>An object of the original type, with new periodicity. </p> <h3>Note</h3> <p>In order for this function to work properly on OHLC data, it is necessary that the Open, High, Low and Close columns be names as such; including the first letter capitalized and the full spelling found. Internally a call is made to reorder the data into the correct column order, and then a verification step to make sure that this ordering and naming has succeeded. All other data formats must be aggregated with functions such as <code>aggregate</code> and <code>period.apply</code>. </p> <p>This method should work on almost all time-series-like objects. Including ‘timeSeries’, ‘zoo’, ‘ts’, and ‘irts’. It is even likely to work well for other data structures - including ‘data.frames’ and ‘matrix’ objects. </p> <p>Internally a call to <code>as.xts</code> converts the original <code>x</code> into the universal <code>xts</code> format, and then re-converts back to the original type. </p> <p>A special note with respect to ‘ts’ objects. As these are strictly regular they may include <code>NA</code> values. These are stripped for aggregation purposes, though replaced before returning. This inevitably leads to many, many additional ‘NA’ values in the data. It is more beneficial to consider using an ‘xts’ object originally, or converting to one in the function call by means of <code>as.xts</code>. </p> <h3>Author(s)</h3> <p> Jeffrey A. Ryan </p> <h3>Examples</h3> <pre> data(sample_matrix) samplexts <- as.xts(sample_matrix) to.monthly(samplexts) to.monthly(sample_matrix) str(to.monthly(samplexts)) str(to.monthly(sample_matrix)) </pre> <hr /><div style="text-align: center;">[Package <em>xts</em> version 0.12.2 <a href="00Index.html">Index</a>]</div> </body></html>