Learn R Programming

stocks (version 1.1.1)

stocks-package: Fast Functions for Stock Market Analysis

Description

Provides functions for analyzing historical performance of stocks or other investments. Functions are written in C++ to quickly calculate maximum draw-down, Sharpe ratio, risk return ratio, and other commonly used metrics of stock performance.

Arguments

Details

Package:
stocks
Type:
Package
Version:
1.1.1
Date:
2015-02-22
License:
GPL-2
The following functions are included:

convert.rate diffs pdiffs pchanges ratios balances final.balance prices.rate gains.rate positives negatives nonpositives nonnegatives mdd sharpe sortino rrr

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

NA

Examples

Run this code
# Load 10 years of daily closing prices for hypothetical stock ZZZ
data(zzz)

# Overall growth rate is about 0.846, or 84.6%
prices.rate(zzz)

# Average annual growth is about 6.3%
prices.rate(zzz, xday.rate = 251)

# Calculate ratio of closing prices for each day relative to the previous day
daily.ratios <- ratios(zzz)

# Figure out final balance if we had invested $10,000 on day 1
final.balance(daily.ratios)

# Calculate Sharpe ratio
sharpe(prices = zzz)

# Calculate Sortino ratio
sortino(prices = zzz)

# Calculate maximum drawdown
mdd(prices = zzz)

# Calculate risk-return ratio
rrr(prices = zzz)

Run the code above in your browser using DataLab