├── .gitattributes ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── NEWS ├── R ├── EIR.R ├── EPS.R ├── SFRatio.R ├── Sharpe.ratio.R ├── bdy.R ├── bdy2mmy.R ├── candlestickChart.R ├── cash.ratio.R ├── coefficient.variation.R ├── cogs.R ├── current.ratio.R ├── ddb.R ├── debt.ratio.R ├── diluted.EPS.R ├── discount.rate.R ├── ear.R ├── ear.continuous.R ├── ear2bey.R ├── ear2hpr.R ├── financial.leverage.R ├── fv.R ├── fv.annuity.R ├── fv.simple.R ├── fv.uneven.R ├── geometric.mean.R ├── get.ohlc.google.R ├── get.ohlc.yahoo.R ├── get.ohlcs.google.R ├── get.ohlcs.yahoo.R ├── gpm.R ├── harmonic.mean.R ├── hpr.R ├── hpr2bey.R ├── hpr2ear.R ├── hpr2mmy.R ├── irr.R ├── irr2.R ├── iss.R ├── lineChart.R ├── lineChartMult.R ├── lt.d2e.R ├── mmy2hpr.R ├── n.period.R ├── npm.R ├── npv.R ├── pmt.R ├── pv.R ├── pv.annuity.R ├── pv.perpetuity.R ├── pv.simple.R ├── pv.uneven.R ├── quick.ratio.R ├── r.continuous.R ├── r.norminal.R ├── r.perpetuity.R ├── sampling.error.R ├── slde.R ├── total.d2e.R ├── twrr.R ├── volumeChart.R ├── was.R └── wpr.R ├── README.md └── man ├── EIR.Rd ├── EPS.Rd ├── SFRatio.Rd ├── Sharpe.ratio.Rd ├── bdy.Rd ├── bdy2mmy.Rd ├── candlestickChart.Rd ├── cash.ratio.Rd ├── coefficient.variation.Rd ├── cogs.Rd ├── current.ratio.Rd ├── ddb.Rd ├── debt.ratio.Rd ├── diluted.EPS.Rd ├── discount.rate.Rd ├── ear.Rd ├── ear.continuous.Rd ├── ear2bey.Rd ├── ear2hpr.Rd ├── financial.leverage.Rd ├── fv.Rd ├── fv.annuity.Rd ├── fv.simple.Rd ├── fv.uneven.Rd ├── geometric.mean.Rd ├── get.ohlc.google.Rd ├── get.ohlc.yahoo.Rd ├── get.ohlcs.google.Rd ├── get.ohlcs.yahoo.Rd ├── gpm.Rd ├── harmonic.mean.Rd ├── hpr.Rd ├── hpr2bey.Rd ├── hpr2ear.Rd ├── hpr2mmy.Rd ├── irr.Rd ├── irr2.Rd ├── iss.Rd ├── lineChart.Rd ├── lineChartMult.Rd ├── lt.d2e.Rd ├── mmy2hpr.Rd ├── n.period.Rd ├── npm.Rd ├── npv.Rd ├── pmt.Rd ├── pv.Rd ├── pv.annuity.Rd ├── pv.perpetuity.Rd ├── pv.simple.Rd ├── pv.uneven.Rd ├── quick.ratio.Rd ├── r.continuous.Rd ├── r.norminal.Rd ├── r.perpetuity.Rd ├── sampling.error.Rd ├── slde.Rd ├── total.d2e.Rd ├── twrr.Rd ├── volumeChart.Rd ├── was.Rd └── wpr.Rd /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: FinCal 2 | Title: Time Value of Money, Time Series Analysis and Computational Finance 3 | Description: Package for time value of money calculation, time series analysis and computational finance. 4 | Version: 0.6.4 5 | Date: 2017-04-12 6 | Author: Felix Yanhui Fan 7 | Imports: 8 | ggplot2, 9 | reshape2, 10 | RCurl 11 | Maintainer: Felix Yanhui Fan 12 | License: GPL (>= 2) 13 | URL: http://felixfan.github.io/FinCal/ 14 | RoxygenNote: 6.0.1 15 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(EIR) 4 | export(EPS) 5 | export(SFRatio) 6 | export(Sharpe.ratio) 7 | export(bdy) 8 | export(bdy2mmy) 9 | export(candlestickChart) 10 | export(cash.ratio) 11 | export(coefficient.variation) 12 | export(cogs) 13 | export(current.ratio) 14 | export(ddb) 15 | export(debt.ratio) 16 | export(diluted.EPS) 17 | export(discount.rate) 18 | export(ear) 19 | export(ear.continuous) 20 | export(ear2bey) 21 | export(ear2hpr) 22 | export(financial.leverage) 23 | export(fv) 24 | export(fv.annuity) 25 | export(fv.simple) 26 | export(fv.uneven) 27 | export(geometric.mean) 28 | export(get.ohlc.google) 29 | export(get.ohlc.yahoo) 30 | export(get.ohlcs.google) 31 | export(get.ohlcs.yahoo) 32 | export(gpm) 33 | export(harmonic.mean) 34 | export(hpr) 35 | export(hpr2bey) 36 | export(hpr2ear) 37 | export(hpr2mmy) 38 | export(irr) 39 | export(irr2) 40 | export(iss) 41 | export(lineChart) 42 | export(lineChartMult) 43 | export(lt.d2e) 44 | export(mmy2hpr) 45 | export(n.period) 46 | export(npm) 47 | export(npv) 48 | export(pmt) 49 | export(pv) 50 | export(pv.annuity) 51 | export(pv.perpetuity) 52 | export(pv.simple) 53 | export(pv.uneven) 54 | export(quick.ratio) 55 | export(r.continuous) 56 | export(r.norminal) 57 | export(r.perpetuity) 58 | export(sampling.error) 59 | export(slde) 60 | export(total.d2e) 61 | export(twrr) 62 | export(volumeChart) 63 | export(was) 64 | export(wpr) 65 | importFrom(RCurl,getURL) 66 | importFrom(ggplot2,aes_string) 67 | importFrom(ggplot2,element_blank) 68 | importFrom(ggplot2,element_text) 69 | importFrom(ggplot2,geom_bar) 70 | importFrom(ggplot2,geom_boxplot) 71 | importFrom(ggplot2,geom_line) 72 | importFrom(ggplot2,ggplot) 73 | importFrom(ggplot2,labs) 74 | importFrom(ggplot2,scale_fill_manual) 75 | importFrom(ggplot2,scale_y_continuous) 76 | importFrom(ggplot2,theme) 77 | importFrom(ggplot2,theme_bw) 78 | importFrom(reshape2,melt) 79 | importFrom(stats,uniroot) 80 | importFrom(utils,read.csv) 81 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | FinCal 0.6.4 2 | ================================================================ 3 | add 'lower' and 'upper' to discount.rate, when uniroot return 'NA', change these two parameters to search smaller interval 4 | 5 | FinCal 0.6.3 6 | ================================================================ 7 | can calculate negative irr now 8 | 9 | 10 | FinCal 0.6.2 11 | ================================================================ 12 | change import to importFrom 13 | 14 | FinCal 0.6.1 15 | ================================================================ 16 | optimize functions: discount.rate and irr ("uniroot" function was used, run fast now) 17 | optimize functions: lineChart, lineChartMult, volumeChart, candlestickChart (parameter "breaks" was added to control the width between breaks, "date.breaks" function was deleted) 18 | 19 | FinCal 0.6 20 | ================================================================ 21 | Released 2014-Feb-02 22 | 23 | Equivalent/proportional Interest Rates 24 | * add EIR 25 | 26 | FinCal 0.5 27 | ================================================================ 28 | Released 2013-Sept-25 29 | 30 | Depreciation Expense Recognition Methods 31 | * add slde 32 | * add ddb 33 | 34 | Earnings Per Share (EPS) Methods 35 | * add EPS 36 | * add diluted.EPS 37 | * add was 38 | * add iss 39 | 40 | Evaluate a company's financial performance 41 | * add gpm 42 | * add npm 43 | 44 | Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 45 | * add current.ratio 46 | * add cash.ratio 47 | * add quick.ratio 48 | 49 | Solvency ratios measure the firm's ability to satisfy its long-term obligations. 50 | * add lt.d2e 51 | * add total.d2e 52 | * add debt.ratio 53 | * add financial.leverage 54 | 55 | FinCal 0.4 56 | ================================================================ 57 | Released 2013-Sept-04 58 | 59 | revised @examples, so multiple examples for some functions call be displayed 60 | 61 | Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average) 62 | * add cogs 63 | 64 | FinCal 0.3 65 | ================================================================ 66 | Released 2013-Aug-13 67 | 68 | Methods for downloading historical stock prices from Yahoo finance and Google finance, technical analysis. 69 | 70 | Methods 71 | * add wpr, 72 | * add geometric.mean 73 | * add harmonic.mean 74 | * add SFRatio 75 | * add Sharpe.ratio 76 | * add coefficient.variation 77 | * add sampling.error 78 | * add get.ohlc.yahoo 79 | * add get.ohlc.google 80 | * add get.ohlcs.yahoo 81 | * add get.ohlcs.google 82 | * add date.breaks 83 | * add lineChart 84 | * add lineChartMult 85 | * add volumeChart 86 | * add candlestickChart 87 | 88 | FinCal 0.2 89 | ================================================================ 90 | Released 2013-Aug-01 91 | 92 | Revised function manual to roxygen2 format. 93 | 94 | Methods 95 | * add r.perpetuity 96 | * add discount.rate 97 | * add npv 98 | * add irr 99 | * add hpr 100 | * add twrr 101 | * add hpr2ear 102 | * add hpr2mmy 103 | * add bdy 104 | * add bdy2mmy 105 | * add mmy2hpr 106 | * add ear2hpr 107 | * add hpr2bey 108 | * add ear2bey 109 | 110 | FinCal 0.1 111 | ================================================================ 112 | Released 2013-July-16 113 | 114 | First official release of the FinCal R package. 115 | Financial calculator for time value money. 116 | Tools for computational finance. 117 | 118 | Methods: 119 | * pv.simple 120 | * fv.simple 121 | * pv.annuity 122 | * fv.annuity 123 | * pv.perpetuity 124 | * pv 125 | * fv 126 | * fv.uneven 127 | * pv.uneven 128 | * pmt 129 | * n.period 130 | * r.continuous 131 | * r.norminal 132 | * ear 133 | * ear.continuous 134 | -------------------------------------------------------------------------------- /R/EIR.R: -------------------------------------------------------------------------------- 1 | #' Equivalent/proportional Interest Rates 2 | #' @description An interest rate to be applied n times p.a. can be converted to an equivalent rate to be applied p times p.a. 3 | #' @param r interest rate to be applied n times per year (r is annual rate!) 4 | #' @param n times that the interest rate r were compounded per year 5 | #' @param p times that the equivalent rate were compounded per year 6 | #' @param type equivalent interest rates ('e',default) or proportional interest rates ('p') 7 | #' @export 8 | #' @examples 9 | #' # monthly interest rat equivalent to 5% compounded per year 10 | #' EIR(r=0.05,n=1,p=12) 11 | #' 12 | #' # monthly interest rat equivalent to 5% compounded per half year 13 | #' EIR(r=0.05,n=2,p=12) 14 | #' 15 | #' # monthly interest rat equivalent to 5% compounded per quarter 16 | #' EIR(r=0.05,n=4,p=12) 17 | #' 18 | #' # annual interest rate equivalent to 5% compounded per month 19 | #' EIR(r=0.05,n=12,p=1) 20 | #' # this is equivalent to 21 | #' ear(r=0.05,m=12) 22 | #' 23 | #' # quarter interest rate equivalent to 5% compounded per year 24 | #' EIR(r=0.05,n=1,p=4) 25 | #' 26 | #' # quarter interest rate equivalent to 5% compounded per month 27 | #' EIR(r=0.05,n=12,p=4) 28 | #' 29 | #' # monthly proportional interest rate which is equivalent to a simple annual interest 30 | #' EIR(r=0.05,p=12,type='p') 31 | EIR <- function(r,n=1,p=12,type=c("e", "p")){ 32 | type = match.arg(type) 33 | if(type == "e"){ 34 | eir=(1+r/n)^(n/p)-1 35 | }else if(type == "p"){ 36 | eir=r/p 37 | }else{ 38 | stop("type must be 'e' or 'p'") 39 | } 40 | return(eir) 41 | } -------------------------------------------------------------------------------- /R/EPS.R: -------------------------------------------------------------------------------- 1 | #' Basic Earnings Per Share 2 | #' 3 | #' @param ni net income 4 | #' @param pd preferred dividends 5 | #' @param w weighted average number of common shares outstanding 6 | #' @seealso \code{\link{diluted.EPS}} 7 | #' @seealso \code{\link{was}} 8 | #' @export 9 | #' @examples 10 | #' EPS(ni=10000,pd=1000,w=11000) 11 | EPS <- function(ni, pd, w){ 12 | return((ni-pd)/w) 13 | } 14 | -------------------------------------------------------------------------------- /R/SFRatio.R: -------------------------------------------------------------------------------- 1 | #' Computing Roy's safety-first ratio 2 | #' 3 | #' @param rp portfolio return 4 | #' @param rl threshold level return 5 | #' @param sd standard deviation of portfolio retwns 6 | #' @seealso \code{\link{Sharpe.ratio}} 7 | #' @export 8 | #' @examples 9 | #' SFRatio(rp=0.09,rl=0.03,sd=0.12) 10 | SFRatio <- function(rp, rl ,sd){ 11 | return((rp-rl)/sd) 12 | } 13 | -------------------------------------------------------------------------------- /R/Sharpe.ratio.R: -------------------------------------------------------------------------------- 1 | #' Computing Sharpe Ratio 2 | #' 3 | #' @param rp portfolio return 4 | #' @param rf risk-free return 5 | #' @param sd standard deviation of portfolio retwns 6 | #' @seealso \code{\link{coefficient.variation}} 7 | #' @seealso \code{\link{SFRatio}} 8 | #' @export 9 | #' @examples 10 | #' Sharpe.ratio(rp=0.038,rf=0.015,sd=0.07) 11 | Sharpe.ratio <- function(rp,rf,sd){ 12 | return((rp-rf)/sd) 13 | } 14 | -------------------------------------------------------------------------------- /R/bdy.R: -------------------------------------------------------------------------------- 1 | #' Computing bank discount yield (BDY) for a T-bill 2 | #' 3 | #' @param d the dollar discount, which is equal to the difference between the face value of the bill and the purchase price 4 | #' @param f the face value (par value) of the bill 5 | #' @param t number of days remaining until maturity 6 | #' @seealso \code{\link{bdy2mmy}} 7 | #' @export 8 | #' @examples 9 | #' bdy(d=1500,f=100000,t=120) 10 | bdy <- function(d,f,t){ 11 | return(360 * d / f / t) 12 | } 13 | 14 | -------------------------------------------------------------------------------- /R/bdy2mmy.R: -------------------------------------------------------------------------------- 1 | #' Computing money market yield (MMY) for a T-bill 2 | #' 3 | #' @param bdy bank discount yield 4 | #' @param t number of days remaining until maturity 5 | #' @seealso \code{\link{bdy}} 6 | #' @export 7 | #' @examples 8 | #' bdy2mmy(bdy=0.045,t=120) 9 | bdy2mmy <- function(bdy,t){ 10 | return(360 * bdy /(360 - t * bdy)) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/candlestickChart.R: -------------------------------------------------------------------------------- 1 | #' Technical analysts - Candlestick chart: show prices for each period as a continuous line. The box is clear if the closing price is higher than the opening price, or filled red if the closing is lower than the opening price. 2 | #' 3 | #' @param ohlc output from get.ohlc.yahoo or get.ohlc.google 4 | #' @param start start date to plot, if not specified, all date in ohlc will be included 5 | #' @param end end date to plot 6 | #' @param main an overall title for the plot 7 | #' @param ... Arguments to be passed to ggplot 8 | #' @seealso \code{\link{get.ohlc.yahoo}} 9 | #' @seealso \code{\link{get.ohlc.google}} 10 | #' @importFrom ggplot2 ggplot geom_boxplot theme theme_bw scale_fill_manual labs aes_string element_text 11 | #' @export 12 | #' @examples 13 | #' # google <- get.ohlc.yahoo("GOOG",start="2013-07-01",end="2013-08-01"); candlestickChart(google) 14 | #' # apple <- get.ohlc.google("AAPL",start="2013-07-01",end="2013-08-01"); candlestickChart(apple) 15 | candlestickChart <- function(ohlc, start=NULL, end=NULL, main="", ...){ 16 | options(warn=-1) 17 | date <- as.Date(ohlc$date) 18 | open <- as.vector(ohlc$open) 19 | high <- as.vector(ohlc$high) 20 | low <- as.vector(ohlc$low) 21 | close <- as.vector(ohlc$close) 22 | 23 | xSubset <-data.frame('date'=date,'open'=open,'high'= high,'low'=low,'close'=close) 24 | 25 | xSubset$candleLower <- pmin(xSubset$open, xSubset$close) 26 | xSubset$candleUpper <- pmax(xSubset$open, xSubset$close) 27 | xSubset$candleMiddle = (xSubset$candleLower+xSubset$candleUpper)/2 28 | xSubset$fill <- 'red' 29 | xSubset$fill[xSubset$open < xSubset$close] = '' 30 | 31 | if(!is.null(start) & !is.null(end)){ 32 | start=as.Date(start) 33 | end=as.Date(end) 34 | xSubset <-subset(xSubset, xSubset$date > start & xSubset$date < end) 35 | } 36 | 37 | g <- ggplot(xSubset, aes_string(x='date', lower='candleLower', middle='candleMiddle', upper='candleUpper', ymin='low', ymax='high',na.rm=TRUE),...) + 38 | geom_boxplot(stat='identity', aes_string(group='date', fill='fill')) + theme_bw() + 39 | scale_fill_manual(name = "", values = c("red", "green")) + labs( title =main ) + labs(x="") + 40 | theme(legend.position="none") + theme(axis.text.x=element_text(angle=90)) 41 | return(g) 42 | } 43 | -------------------------------------------------------------------------------- /R/cash.ratio.R: -------------------------------------------------------------------------------- 1 | #' cash ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 2 | #' 3 | #' @param cash cash 4 | #' @param ms marketable securities 5 | #' @param cl current liabilities 6 | #' @seealso \code{\link{current.ratio}} 7 | #' @seealso \code{\link{quick.ratio}} 8 | #' @export 9 | #' @examples 10 | #' cash.ratio(cash=3000,ms=2000,cl=2000) 11 | cash.ratio <- function(cash,ms,cl){ 12 | return((cash+ms)/cl) 13 | } 14 | -------------------------------------------------------------------------------- /R/coefficient.variation.R: -------------------------------------------------------------------------------- 1 | #' Computing Coefficient of variation 2 | #' 3 | #' @param sd standard deviation 4 | #' @param avg average value 5 | #' @seealso \code{\link{Sharpe.ratio}} 6 | #' @export 7 | #' @examples 8 | #' coefficient.variation(sd=0.15,avg=0.39) 9 | coefficient.variation <- function(sd, avg){ 10 | return(sd/avg) 11 | } 12 | -------------------------------------------------------------------------------- /R/cogs.R: -------------------------------------------------------------------------------- 1 | #' Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average) 2 | #' 3 | #' @param uinv units of beginning inventory 4 | #' @param pinv prince of beginning inventory 5 | #' @param units nx1 vector of inventory units. inventory purchased ordered by time (from first to last) 6 | #' @param price nx1 vector of inventory price. same order as units 7 | #' @param sinv units of sold inventory 8 | #' @param method inventory methods: FIFO (first in first out, permitted under both US and IFRS), LIFO (late in first out, US only), WAC (weighted average cost,US and IFRS) 9 | #' @export 10 | #' @examples 11 | #' cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="FIFO") 12 | #' 13 | #' cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="LIFO") 14 | #' 15 | #' cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="WAC") 16 | cogs <- function(uinv,pinv,units,price,sinv,method="FIFO"){ 17 | n=length(units) 18 | m=length(price) 19 | costOfGoods=0 20 | endingInventory=0 21 | if(m!=n){ 22 | stop("length of units and price are not the same\n") 23 | }else{ 24 | if(method=="FIFO"){ 25 | if(sinv <= uinv){ 26 | costOfGoods = sinv * pinv 27 | endingInventory = (uinv - sinv) * pinv 28 | for(i in 1:n){ 29 | endingInventory = endingInventory + units[i] * price[i] 30 | } 31 | }else{ 32 | costOfGoods = uinv * pinv 33 | sinv = sinv - uinv 34 | for(i in 1:n){ 35 | if(sinv <= units[i]){ 36 | costOfGoods = costOfGoods +sinv * price[i] 37 | endingInventory = (units[i] - sinv) * price[i] 38 | if(i < n){ 39 | temp=i + 1 40 | for(j in temp:n){ 41 | endingInventory = endingInventory + units[j] * price[j] 42 | } 43 | } 44 | sinv=0 45 | next 46 | }else{ 47 | costOfGoods = costOfGoods +units[i] * price[i] 48 | sinv = sinv -units[i] 49 | } 50 | } 51 | if(sinv >0){ 52 | stop("Inventory is not enough to sell\n") 53 | } 54 | } 55 | }else if(method=="WAC"){ 56 | endingInventory = uinv * pinv 57 | tu = uinv 58 | for(i in 1:n){ 59 | endingInventory = endingInventory + units[i] * price[i] 60 | tu = tu + units[i] 61 | } 62 | if(tu >= sinv){ 63 | costOfGoods = endingInventory/tu*sinv 64 | endingInventory = endingInventory/tu*(tu-sinv) 65 | }else{ 66 | stop("Inventory is not enough to sell\n") 67 | } 68 | 69 | }else if(method=="LIFO"){ 70 | for(i in n:1){ 71 | if(sinv <= units[i]){ 72 | costOfGoods = costOfGoods +sinv * price[i] 73 | endingInventory = (units[i] - sinv) * price[i] 74 | if(i > 1){ 75 | temp=i - 1 76 | for(j in temp:1){ 77 | endingInventory = endingInventory + units[j] * price[j] 78 | } 79 | } 80 | endingInventory = endingInventory + uinv * pinv 81 | sinv=0 82 | next 83 | }else{ 84 | costOfGoods = costOfGoods +units[i] * price[i] 85 | sinv = sinv -units[i] 86 | } 87 | } 88 | if(sinv > 0){ 89 | if(sinv <= uinv){ 90 | costOfGoods = costOfGoods + sinv * pinv 91 | endingInventory = endingInventory + (uinv - sinv) * pinv 92 | } 93 | else{ 94 | stop("Inventory is not enough to sell\n") 95 | } 96 | } 97 | } 98 | 99 | } 100 | return(list("costOfGoods"=costOfGoods,"endingInventory"=endingInventory)) 101 | } 102 | -------------------------------------------------------------------------------- /R/current.ratio.R: -------------------------------------------------------------------------------- 1 | #' current ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 2 | #' 3 | #' @param ca current assets 4 | #' @param cl current liabilities 5 | #' @seealso \code{\link{cash.ratio}} 6 | #' @seealso \code{\link{quick.ratio}} 7 | #' @export 8 | #' @examples 9 | #' current.ratio(ca=8000,cl=2000) 10 | current.ratio <- function(ca,cl){ 11 | return(ca/cl) 12 | } 13 | -------------------------------------------------------------------------------- /R/ddb.R: -------------------------------------------------------------------------------- 1 | #' Depreciation Expense Recognition -- double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance. 2 | #' 3 | #' @param cost cost of long-lived assets 4 | #' @param rv residual value of the long-lived assets at the end of its useful life. DDB does not explicitly use the asset's residual value in the calculations, but depreciation ends once the estimated residual value has been reached. If the asset is expected to have no residual value, the DB method will never fully depreciate it, so the DB method is typically changed to straight-line at some point in the asset's life. 5 | #' @param t length of the useful life 6 | #' @seealso \code{\link{slde}} 7 | #' @export 8 | #' @examples 9 | #' ddb(cost=1200,rv=200,t=5) 10 | ddb <- function(cost,rv,t){ 11 | if(t<2){ 12 | stop("t should be larger than 1") 13 | } 14 | ddb=rep(0,t) 15 | ddb[1]=2*cost/t 16 | if(cost - ddb[1] <= rv){ 17 | ddb[1]=cost-rv 18 | }else{ 19 | cost=cost-ddb[1] 20 | for(i in 2:t){ 21 | ddb[i]=2*cost/t 22 | if(cost - ddb[i] <= rv){ 23 | ddb[i]=cost-rv 24 | break 25 | }else{ 26 | cost = cost - ddb[i] 27 | } 28 | } 29 | } 30 | cbind(t=1:t,ddb=ddb) 31 | } 32 | -------------------------------------------------------------------------------- /R/debt.ratio.R: -------------------------------------------------------------------------------- 1 | #' debt ratio -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 2 | #' 3 | #' @param td total debt 4 | #' @param ta total assets 5 | #' @seealso \code{\link{total.d2e}} 6 | #' @seealso \code{\link{lt.d2e}} 7 | #' @seealso \code{\link{financial.leverage}} 8 | #' @export 9 | #' @examples 10 | #' debt.ratio(td=6000,ta=20000) 11 | debt.ratio <- function(td,ta){ 12 | return(td/ta) 13 | } 14 | -------------------------------------------------------------------------------- /R/diluted.EPS.R: -------------------------------------------------------------------------------- 1 | #' diluted Earnings Per Share 2 | #' 3 | #' @param ni net income 4 | #' @param pd preferred dividends 5 | #' @param cpd dividends on convertible preferred stock 6 | #' @param cdi interest on convertible debt 7 | #' @param tax tax rate 8 | #' @param w weighted average number of common shares outstanding 9 | #' @param cps shares from conversion of convertible preferred stock 10 | #' @param cds shares from conversion of convertible debt 11 | #' @param iss shares issuable from stock options 12 | #' @seealso \code{\link{EPS}} 13 | #' @seealso \code{\link{iss}} 14 | #' @seealso \code{\link{was}} 15 | #' @export 16 | #' @examples 17 | #' diluted.EPS(ni=115600,pd=10000,cdi=42000,tax=0.4,w=200000,cds=60000) 18 | #' 19 | #' diluted.EPS(ni=115600,pd=10000,cpd=10000,w=200000,cps=40000) 20 | #' 21 | #' diluted.EPS(ni=115600,pd=10000,w=200000,iss=2500) 22 | #' 23 | #' diluted.EPS(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000,cps=40000,cds=60000,iss=2500) 24 | diluted.EPS <- function(ni, pd, cpd=0,cdi=0,tax=0,w,cps=0,cds=0,iss=0){ 25 | basic = (ni-pd)/w 26 | diluted = (ni-pd+cpd+cdi*(1-tax))/(w+cps+cds+iss) 27 | if(diluted > basic){ 28 | diluted = (ni-pd+cpd)/(w+cps+iss) 29 | } 30 | return(diluted) 31 | } 32 | -------------------------------------------------------------------------------- /R/discount.rate.R: -------------------------------------------------------------------------------- 1 | #' Computing the rate of return for each period 2 | #' 3 | #' @param n number of periods 4 | #' @param pv present value 5 | #' @param fv future value 6 | #' @param pmt payment per period 7 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 8 | #' @param lower the lower end points of the rate of return to be searched. 9 | #' @param upper the upper end points of the rate of return to be searched. 10 | #' @seealso \code{\link{fv.simple}} 11 | #' @seealso \code{\link{fv.annuity}} 12 | #' @seealso \code{\link{fv}} 13 | #' @seealso \code{\link{pv}} 14 | #' @seealso \code{\link{pmt}} 15 | #' @seealso \code{\link{n.period}} 16 | #' @importFrom stats uniroot 17 | #' @export 18 | #' @examples 19 | #' discount.rate(n=5,pv=0,fv=600,pmt=-100,type=0) 20 | discount.rate <- function(n,pv,fv,pmt,type=0,lower=0.0001,upper=100){ 21 | uniroot(function(r) fv.simple(r,n,pv) + fv.annuity(r,n,pmt,type)-fv, lower=lower, upper = upper)$root 22 | } 23 | 24 | -------------------------------------------------------------------------------- /R/ear.R: -------------------------------------------------------------------------------- 1 | #' Convert stated annual rate to the effective annual rate 2 | #' 3 | #' @param r stated annual rate 4 | #' @param m number of compounding periods per year 5 | #' @seealso \code{\link{ear.continuous}} 6 | #' @seealso \code{\link{hpr2ear}} 7 | #' @seealso \code{\link{ear2bey}} 8 | #' @seealso \code{\link{ear2hpr}} 9 | #' @export 10 | #' @examples 11 | #' ear(r=0.12,m=12) 12 | #' 13 | #' ear(0.04,365) 14 | ear <- function(r,m){ 15 | return((1 + r / m)^m - 1) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /R/ear.continuous.R: -------------------------------------------------------------------------------- 1 | #' Convert stated annual rate to the effective annual rate with continuous compounding 2 | #' 3 | #' @param r stated annual rate 4 | #' @seealso \code{\link{ear}} 5 | #' @seealso \code{\link{r.norminal}} 6 | #' @export 7 | #' @examples 8 | #' ear.continuous(r=0.1) 9 | #' 10 | #' ear.continuous(0.03) 11 | ear.continuous <- function(r){ 12 | return(exp(r) - 1) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/ear2bey.R: -------------------------------------------------------------------------------- 1 | #' bond-equivalent yield (BEY), 2 x the semiannual discount rate 2 | #' 3 | #' @param ear effective annual rate 4 | #' @seealso \code{\link{ear}} 5 | #' @export 6 | #' @examples 7 | #' ear2bey(ear=0.08) 8 | ear2bey <- function(ear){ 9 | return(((1 + ear)^0.5 - 1)*2) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /R/ear2hpr.R: -------------------------------------------------------------------------------- 1 | #' Computing HPR, the holding period return 2 | #' 3 | #' @param ear effective annual rate 4 | #' @param t number of days remaining until maturity 5 | #' @seealso \code{\link{hpr2ear}} 6 | #' @seealso \code{\link{ear}} 7 | #' @seealso \code{\link{hpr}} 8 | #' @export 9 | #' @examples 10 | #' ear2hpr(ear=0.05039,t=150) 11 | ear2hpr <- function(ear, t){ 12 | return((1 + ear)^(t/365) - 1) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/financial.leverage.R: -------------------------------------------------------------------------------- 1 | #' financial leverage -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 2 | #' 3 | #' @param te total equity 4 | #' @param ta total assets 5 | #' @seealso \code{\link{total.d2e}} 6 | #' @seealso \code{\link{lt.d2e}} 7 | #' @seealso \code{\link{debt.ratio}} 8 | #' @export 9 | #' @examples 10 | #' financial.leverage(te=16000,ta=20000) 11 | financial.leverage <- function(te,ta){ 12 | return(ta/te) 13 | } 14 | -------------------------------------------------------------------------------- /R/fv.R: -------------------------------------------------------------------------------- 1 | #' Estimate future value (fv) 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param pv present value 6 | #' @param pmt payment per period 7 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 8 | #' @seealso \code{\link{fv.simple}} 9 | #' @seealso \code{\link{fv.annuity}} 10 | #' @seealso \code{\link{pv}} 11 | #' @seealso \code{\link{pmt}} 12 | #' @seealso \code{\link{n.period}} 13 | #' @seealso \code{\link{discount.rate}} 14 | #' @export 15 | #' @examples 16 | #' fv(0.07,10,1000,10) 17 | fv <- function(r,n,pv=0,pmt=0,type=0){ 18 | if(type != 0 && type !=1){ 19 | print("Error: type should be 0 or 1!") 20 | }else{ 21 | return(fv.simple(r,n,pv) + fv.annuity(r,n,pmt,type)) 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /R/fv.annuity.R: -------------------------------------------------------------------------------- 1 | #' Estimate future value of an annuity 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param pmt payment per period 6 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 7 | #' @seealso \code{\link{fv}} 8 | #' @export 9 | #' @examples 10 | #' fv.annuity(0.03,12,-1000) 11 | #' 12 | #' fv.annuity(r=0.03,n=12,pmt=-1000,type=1) 13 | fv.annuity <- function(r,n,pmt,type=0) { 14 | if(type != 0 && type !=1){ 15 | print("Error: type should be 0 or 1!") 16 | }else{ 17 | fv = (pmt / r * ((1 + r)^n - 1))*(1+r)^type * (-1) 18 | return(fv) 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /R/fv.simple.R: -------------------------------------------------------------------------------- 1 | #' Estimate future value (fv) of a single sum 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param pv present value 6 | #' @seealso \code{\link{fv}} 7 | #' @export 8 | #' @examples 9 | #' fv.simple(0.08,10,-300) 10 | #' 11 | #' fv.simple(r=0.04,n=20,pv=-50000) 12 | fv.simple <- function(r,n,pv){ 13 | return((pv * (1 + r)^n)*(-1)) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/fv.uneven.R: -------------------------------------------------------------------------------- 1 | #' Computing the future value of an uneven cash flow series 2 | #' 3 | #' @param r stated annual rate 4 | #' @param cf uneven cash flow 5 | #' @seealso \code{\link{fv.simple}} 6 | #' @export 7 | #' @examples 8 | #' fv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000)) 9 | fv.uneven <- function(r,cf){ 10 | m <- length(cf) 11 | sum <- 0 12 | for(i in 1:m){ 13 | n <- m - i 14 | sum <- sum + fv.simple(r,n,cf[i]) 15 | } 16 | return(sum) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /R/geometric.mean.R: -------------------------------------------------------------------------------- 1 | #' Geometric mean return 2 | #' 3 | #' @param r returns over multiple periods 4 | #' @export 5 | #' @examples 6 | #' geometric.mean(r=c(-0.0934, 0.2345, 0.0892)) 7 | geometric.mean <- function(r){ 8 | rs <- r + 1 9 | return(prod(rs)^(1/length(rs))-1) 10 | } 11 | -------------------------------------------------------------------------------- /R/get.ohlc.google.R: -------------------------------------------------------------------------------- 1 | #' Download stock prices from Google Finance (open, high, low, close, volume) 2 | #' 3 | #' @param symbol symbol of stock, e.g. AAPL, GOOG, SPX 4 | #' @param start start date, e.g., 2013-07-31 5 | #' @param end end date, e.g., 2013-08-06 6 | #' @seealso \code{\link{get.ohlc.yahoo}} 7 | #' @seealso \code{\link{get.ohlcs.google}} 8 | #' @importFrom RCurl getURL 9 | #' @importFrom utils read.csv 10 | #' @export 11 | #' @examples 12 | #' # get.ohlc.google(symbol="AAPL") 13 | #' # get.ohlc.google(symbol="AAPL",start="2013-08-01") 14 | #' # get.ohlc.google(symbol="AAPL",start="2013-07-01",end="2013-08-01") 15 | get.ohlc.google <- function(symbol,start="2013-01-01",end="today"){ 16 | temp <- strsplit(start,"-") 17 | a=month.abb[as.numeric(temp[[1]][2])] 18 | b=temp[[1]][3] 19 | c=temp[[1]][1] 20 | if(end != "today"){ 21 | temp <- strsplit(end,"-") 22 | d=month.abb[as.numeric(temp[[1]][2])] 23 | e=temp[[1]][3] 24 | f=temp[[1]][1] 25 | }else{ 26 | end=as.character(Sys.Date()) 27 | temp <- strsplit(end,"-") 28 | d=month.abb[as.numeric(temp[[1]][2])] 29 | e=temp[[1]][3] 30 | f=temp[[1]][1] 31 | } 32 | URL=paste("https://www.google.com/finance/historical?q=",symbol,"&output=csv","&startdate=",a,"+",b,"+",c,"&enddate=",d,"+",e,"+",f, sep="") 33 | myCsv <- getURL(URL, ssl.verifypeer = FALSE) 34 | dat <- read.csv(textConnection(myCsv)) 35 | colnames(dat) <- c("date", "open", "high", "low", "close", "volume") 36 | dates=as.character(dat$date) 37 | for(i in 1:length(dates)){ 38 | tempdates=strsplit(dates[i],"-") 39 | tempdates[[1]][2]=match(tempdates[[1]][2],month.abb) 40 | tempd=paste(tempdates[[1]][1],tempdates[[1]][2],tempdates[[1]][3],sep="-") 41 | dates[i]=format(as.Date(tempd,"%d-%m-%y"),"%Y-%m-%d") 42 | } 43 | dat$date=dates 44 | dat=dat[order(dat$date),] 45 | return(dat) 46 | } 47 | -------------------------------------------------------------------------------- /R/get.ohlc.yahoo.R: -------------------------------------------------------------------------------- 1 | #' Download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted) 2 | #' 3 | #' @param symbol symbol of stock, e.g. AAPL, GOOG, SPX 4 | #' @param start start date, e.g., 2013-07-31 5 | #' @param end end date, e.g., 2013-08-06 6 | #' @param freq time interval, e.g., d:daily, w:weekly, m:monthly 7 | #' @seealso \code{\link{get.ohlcs.yahoo}} 8 | #' @seealso \code{\link{get.ohlc.google}} 9 | #' @importFrom utils read.csv 10 | #' @export 11 | #' @examples 12 | #' # get.ohlc.yahoo(symbol="AAPL") 13 | #' # get.ohlc.yahoo(symbol="AAPL",start="2013-08-01",freq="d") 14 | #' # get.ohlc.yahoo(symbol="AAPL",start="2013-07-01",end="2013-08-01",freq="w") 15 | get.ohlc.yahoo <- function(symbol,start="firstDay",end="today",freq="d"){ 16 | if(start == "firstDay"){ 17 | URL=paste("http://ichart.finance.yahoo.com/table.csv?s=", symbol, sep="") 18 | dat <- read.csv(URL) 19 | dat=dat[order(dat$Date),] 20 | }else{ 21 | temp <- strsplit(start,"-") 22 | a=sprintf('%.2d',as.integer(temp[[1]][2])-1) 23 | b=temp[[1]][3] 24 | c=temp[[1]][1] 25 | if(end != "today"){ 26 | temp <- strsplit(end,"-") 27 | d=sprintf('%.2d',as.integer(temp[[1]][2])-1) 28 | e=temp[[1]][3] 29 | f=temp[[1]][1] 30 | }else{ 31 | end=as.character(Sys.Date()) 32 | temp <- strsplit(end,"-") 33 | d=sprintf('%.2d',as.integer(temp[[1]][2])-1) 34 | e=temp[[1]][3] 35 | f=temp[[1]][1] 36 | } 37 | URL=paste("http://ichart.finance.yahoo.com/table.csv?s=",symbol,"&a=",a,"&b=",b,"&c=",c,"&d=",d,"&e=",e,"&f=",f,"&g=",freq, sep="") 38 | dat <- read.csv(URL) 39 | dat=dat[order(dat$Date),] 40 | } 41 | colnames(dat) <- c("date", "open", "high", "low", "close", "volume", "adjusted") 42 | return(dat) 43 | } 44 | -------------------------------------------------------------------------------- /R/get.ohlcs.google.R: -------------------------------------------------------------------------------- 1 | #' Batch download stock prices from Google Finance (open, high, low, close, volume) 2 | #' 3 | #' @param symbols symbols of stock, e.g. AAPL, GOOG, SPX 4 | #' @param start start date, e.g., 2013-07-31 5 | #' @param end end date, e.g., 2013-08-06 6 | #' @seealso \code{\link{get.ohlc.google}} 7 | #' @seealso \code{\link{get.ohlcs.yahoo}} 8 | #' @importFrom RCurl getURL 9 | #' @importFrom utils read.csv 10 | #' @export 11 | #' @examples 12 | #' # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY")) 13 | #' # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01") 14 | #' # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",end="2013-07-31") 15 | get.ohlcs.google <- function(symbols,start="2013-01-01",end="today"){ 16 | n <- length(symbols) 17 | ohlc=list() 18 | temp <- strsplit(start,"-") 19 | a=month.abb[as.numeric(temp[[1]][2])] 20 | b=temp[[1]][3] 21 | c=temp[[1]][1] 22 | if(end != "today"){ 23 | temp <- strsplit(end,"-") 24 | d=month.abb[as.numeric(temp[[1]][2])] 25 | e=temp[[1]][3] 26 | f=temp[[1]][1] 27 | }else{ 28 | end=as.character(Sys.Date()) 29 | temp <- strsplit(end,"-") 30 | d=month.abb[as.numeric(temp[[1]][2])] 31 | e=temp[[1]][3] 32 | f=temp[[1]][1] 33 | } 34 | for(i in 1:n){ 35 | URL=paste("https://www.google.com/finance/historical?q=",symbols[i],"&output=csv","&startdate=",a,"+",b,"+",c,"&enddate=",d,"+",e,"+",f, sep="") 36 | myCsv <- getURL(URL, ssl.verifypeer = FALSE) 37 | dat <- read.csv(textConnection(myCsv)) 38 | colnames(dat) <- c("date", "open", "high", "low", "close", "volume") 39 | dates=as.character(dat$date) 40 | for(j in 1:length(dates)){ 41 | tempdates=strsplit(dates[j],"-") 42 | tempdates[[1]][2]=match(tempdates[[1]][2],month.abb) 43 | tempd=paste(tempdates[[1]][1],tempdates[[1]][2],tempdates[[1]][3],sep="-") 44 | dates[j]=format(as.Date(tempd,"%d-%m-%y"),"%Y-%m-%d") 45 | } 46 | dat$date=dates 47 | dat=dat[order(dat$date),] 48 | ohlc[[symbols[i]]]=dat 49 | } 50 | return(ohlc) 51 | } 52 | -------------------------------------------------------------------------------- /R/get.ohlcs.yahoo.R: -------------------------------------------------------------------------------- 1 | #' Batch download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted) 2 | #' 3 | #' @param symbols symbols of stock, e.g. AAPL, GOOG, SPX 4 | #' @param start start date, e.g., 2013-07-31 5 | #' @param end end date, e.g., 2013-08-06 6 | #' @param freq time interval, e.g., d:daily, w:weekly, m:monthly 7 | #' @seealso \code{\link{get.ohlc.yahoo}} 8 | #' @seealso \code{\link{get.ohlcs.google}} 9 | #' @importFrom utils read.csv 10 | #' @export 11 | #' @examples 12 | #' # get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),freq="d") 13 | #' # get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",freq="m") 14 | get.ohlcs.yahoo <- function(symbols,start="firstDay",end="today",freq="d"){ 15 | n <- length(symbols) 16 | ohlc=list() 17 | if(start == "firstDay"){ 18 | for(i in 1:n){ 19 | URL=paste("http://ichart.finance.yahoo.com/table.csv?s=", symbols[i], sep="") 20 | dat <- read.csv(URL) 21 | dat=dat[order(dat$Date),] 22 | colnames(dat) <- c("date", "open", "high", "low", "close", "volume", "adjusted") 23 | ohlc[[symbols[i]]]=dat 24 | } 25 | }else{ 26 | temp <- strsplit(start,"-") 27 | a=sprintf('%.2d',as.integer(temp[[1]][2])-1) 28 | b=temp[[1]][3] 29 | c=temp[[1]][1] 30 | if(end != "today"){ 31 | temp <- strsplit(end,"-") 32 | d=sprintf('%.2d',as.integer(temp[[1]][2])-1) 33 | e=temp[[1]][3] 34 | f=temp[[1]][1] 35 | }else{ 36 | end=as.character(Sys.Date()) 37 | temp <- strsplit(end,"-") 38 | d=sprintf('%.2d',as.integer(temp[[1]][2])-1) 39 | e=temp[[1]][3] 40 | f=temp[[1]][1] 41 | } 42 | 43 | for(i in 1:n){ 44 | URL=paste("http://ichart.finance.yahoo.com/table.csv?s=",symbols[i],"&a=",a,"&b=",b,"&c=",c,"&d=",d,"&e=",e,"&f=",f,"&g=",freq, sep="") 45 | dat <- read.csv(URL) 46 | dat=dat[order(dat$Date),] 47 | colnames(dat) <- c("date", "open", "high", "low", "close", "volume", "adjusted") 48 | ohlc[[symbols[i]]]=dat 49 | } 50 | } 51 | return(ohlc) 52 | } 53 | -------------------------------------------------------------------------------- /R/gpm.R: -------------------------------------------------------------------------------- 1 | #' gross profit margin -- Evaluate a company's financial performance 2 | #' 3 | #' @param gp gross profit, equal to revenue minus cost of goods sold (cogs) 4 | #' @param rv revenue (sales) 5 | #' @seealso \code{\link{npm}} 6 | #' @export 7 | #' @examples 8 | #' gpm(gp=1000,rv=20000) 9 | gpm <- function(gp,rv){ 10 | return(gp/rv) 11 | } 12 | -------------------------------------------------------------------------------- /R/harmonic.mean.R: -------------------------------------------------------------------------------- 1 | #' harmonic mean, average price 2 | #' @param p price over multiple periods 3 | #' @export 4 | #' @examples 5 | #' harmonic.mean(p=c(8,9,10)) 6 | harmonic.mean <- function(p){ 7 | return(1/mean(1/p)) 8 | } 9 | -------------------------------------------------------------------------------- /R/hpr.R: -------------------------------------------------------------------------------- 1 | #' Computing HPR, the holding period return 2 | #' 3 | #' @param ev ending value 4 | #' @param bv beginning value 5 | #' @param cfr cash flow received 6 | #' @seealso \code{\link{twrr}} 7 | #' @seealso \code{\link{hpr2ear}} 8 | #' @seealso \code{\link{hpr2mmy}} 9 | #' @export 10 | #' @examples 11 | #' hpr(ev=33,bv=30,cfr=0.5) 12 | hpr <- function(ev,bv,cfr=0){ 13 | return((ev-bv+cfr)/bv) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/hpr2bey.R: -------------------------------------------------------------------------------- 1 | #' bond-equivalent yield (BEY), 2 x the semiannual discount rate 2 | #' 3 | #' @param hpr holding period return 4 | #' @param t number of month remaining until maturity 5 | #' @seealso \code{\link{hpr}} 6 | #' @export 7 | #' @examples 8 | #' hpr2bey(hpr=0.02,t=3) 9 | hpr2bey <- function(hpr,t){ 10 | return(((1 + hpr)^(6/t) -1)*2) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/hpr2ear.R: -------------------------------------------------------------------------------- 1 | #' Convert holding period return to the effective annual rate 2 | #' 3 | #' @param hpr holding period return 4 | #' @param t number of days remaining until maturity 5 | #' @seealso \code{\link{ear}} 6 | #' @seealso \code{\link{hpr}} 7 | #' @seealso \code{\link{ear2hpr}} 8 | #' @export 9 | #' @examples 10 | #' hpr2ear(hpr=0.015228,t=120) 11 | hpr2ear <- function(hpr,t){ 12 | return((1 + hpr)^(365/t) - 1) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/hpr2mmy.R: -------------------------------------------------------------------------------- 1 | #' Computing money market yield (MMY) for a T-bill 2 | #' 3 | #' @param hpr holding period return 4 | #' @param t number of days remaining until maturity 5 | #' @seealso \code{\link{hpr}} 6 | #' @seealso \code{\link{mmy2hpr}} 7 | #' @export 8 | #' @examples 9 | #' hpr2mmy(hpr=0.01523,t=120) 10 | hpr2mmy <- function(hpr,t){ 11 | return(360 * hpr / t) 12 | } 13 | 14 | -------------------------------------------------------------------------------- /R/irr.R: -------------------------------------------------------------------------------- 1 | #' Computing IRR, the internal rate of return 2 | #' 3 | #' @param cf cash flow,the first cash flow is the initial outlay 4 | #' @seealso \code{\link{pv.uneven}} 5 | #' @seealso \code{\link{npv}} 6 | #' @importFrom stats uniroot 7 | #' @export 8 | #' @examples 9 | #' # irr(cf=c(-5, 1.6, 2.4, 2.8)) 10 | irr <- function(cf){ 11 | n <- length(cf) 12 | subcf <- cf[2:n] 13 | uniroot(function(r) -1 * pv.uneven(r, subcf) + cf[1], interval=c(1e-10,1e10),extendInt="yes")$root 14 | } 15 | -------------------------------------------------------------------------------- /R/irr2.R: -------------------------------------------------------------------------------- 1 | #' Computing IRR, the internal rate of return 2 | #' @description This function is the same as irr but can calculate negative value. This function may take a very long time. You can use larger cutoff and larger step to get a less precision irr first. Then based on the result, change from and to, to narrow down the interval, and use a smaller step to get a more precision irr. 3 | #' @param cf cash flow,the first cash flow is the initial outlay 4 | #' @param cutoff threshold to take npv as zero 5 | #' @param from smallest irr to try 6 | #' @param to largest irr to try 7 | #' @param step increment of the irr 8 | #' @seealso \code{\link{irr}} 9 | #' @export 10 | #' @examples 11 | #' # irr2(cf=c(-5, 1.6, 2.4, 2.8)) 12 | #' # irr2(cf=c(-200, 50, 60, -70, 30, 20)) 13 | irr2 <- function(cf,cutoff=0.1,from=-1, to=10, step=0.000001){ 14 | r0 <- NA 15 | n <- length(cf) 16 | for(r in seq(from, to, step)){ 17 | npv = cf[1] 18 | for(i in 2:n){ 19 | npv = npv + cf[i]/(1+r)**(i-1) 20 | } 21 | if (! is.na(npv)){ 22 | if(abs(npv) < cutoff){ 23 | r0 <- r 24 | break 25 | } 26 | } 27 | } 28 | 29 | if(is.na(r0)){ 30 | stop("can not find irr in the given interval, you can try smaller step, and/or larger to, and/or larger cutoff") 31 | } 32 | return(r0) 33 | } -------------------------------------------------------------------------------- /R/iss.R: -------------------------------------------------------------------------------- 1 | #' calculate the net increase in common shares from the potential exercise of stock options or warrants 2 | #' 3 | #' @param amp average market price over the year 4 | #' @param ep exercise price of the options or warrants 5 | #' @param n number of common shares that the options and warrants can be convened into 6 | #' @seealso \code{\link{diluted.EPS}} 7 | #' @export 8 | #' @examples 9 | #' iss(amp=20,ep=15,n=10000) 10 | iss <- function(amp,ep,n){ 11 | if(amp > ep){ 12 | return((amp-ep)*n/amp) 13 | }else{ 14 | stop("amp must larger than ep") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /R/lineChart.R: -------------------------------------------------------------------------------- 1 | #' Technical analysts - Line charts: show prices for each period as a continuous line 2 | #' 3 | #' @param ohlc output from get.ohlc.yahoo or get.ohlc.google 4 | #' @param y y coordinates: close, open, high, low or adjusted (yahoo data only) 5 | #' @param main an overall title for the plot 6 | #' @param ... Arguments to be passed to ggplot 7 | #' @seealso \code{\link{get.ohlc.yahoo}} 8 | #' @seealso \code{\link{get.ohlc.google}} 9 | #' @importFrom ggplot2 ggplot geom_line theme labs aes_string element_text 10 | #' @export 11 | #' @examples 12 | #' # google <- get.ohlc.yahoo("GOOG"); lineChart(google) 13 | #' # apple <- get.ohlc.google("AAPL"); lineChart(apple) 14 | lineChart <- function(ohlc,y="close",main="",...){ 15 | options(warn=-1) 16 | ohlc$date <- as.Date(ohlc$date,"%Y-%m-%d") 17 | if(y == "close"){ 18 | ggplot(ohlc, aes_string(x='date',y='close'),...) + geom_line() + labs( title =main ) + labs(x="") + 19 | theme(axis.text.x=element_text(angle=90)) 20 | }else if(y == "open"){ 21 | ggplot(ohlc, aes_string(x='date',y='open'),...) + geom_line() + labs( title =main ) + labs(x="") + 22 | theme(axis.text.x=element_text(angle=90)) 23 | }else if(y == "high"){ 24 | ggplot(ohlc, aes_string(x='date',y='high'),...) + geom_line() + labs( title =main ) + labs(x="") + 25 | theme(axis.text.x=element_text(angle=90)) 26 | }else if(y == "low"){ 27 | ggplot(ohlc, aes_string(x='date','y=low'),...) + geom_line() + labs( title =main ) + labs(x="") + 28 | theme(axis.text.x=element_text(angle=90)) 29 | }else if(y == "adjusted"){ 30 | ggplot(ohlc, aes_string(x='date',y='adjusted'),...) + geom_line() + labs( title =main ) + labs(x="") + 31 | theme(axis.text.x=element_text(angle=90)) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /R/lineChartMult.R: -------------------------------------------------------------------------------- 1 | #' Technical analysts - Line charts: show prices for each period as a continuous line for multiple stocks 2 | #' 3 | #' @param ohlcs output from get.ohlc.yahoo.mult or get.ohlc.google.mult 4 | #' @param y y coordinates: close, open, high, low or adjusted (yahoo data only) 5 | #' @param main an overall title for the plot 6 | #' @param ... Arguments to be passed to ggplot 7 | #' @seealso \code{\link{get.ohlcs.yahoo}} 8 | #' @seealso \code{\link{get.ohlcs.google}} 9 | #' @seealso \code{\link{lineChart}} 10 | #' @importFrom ggplot2 ggplot geom_line theme scale_y_continuous labs aes_string element_text element_blank 11 | #' @importFrom reshape2 melt 12 | #' @export 13 | #' @examples 14 | #' # googapple <- get.ohlcs.yahoo(c("GOOG","AAPL"),start="2013-01-01"); 15 | #' # lineChartMult(googapple) 16 | #' # googapple <- get.ohlcs.google(c("GOOG","AAPL"),start="2013-01-01"); 17 | #' # lineChartMult(googapple) 18 | lineChartMult <- function(ohlcs,y="close",main="",...){ 19 | options(warn=-1) 20 | sname=names(ohlcs) 21 | n=length(sname) 22 | Date=ohlcs[[sname[1]]]$date <- as.Date(ohlcs[[sname[1]]]$date,"%Y-%m-%d") 23 | z=data.frame(Date) 24 | colname=c("Date") 25 | for(i in 1:n){ 26 | colname=append(colname,sname[i]) 27 | if(y == "close"){ 28 | z[,i+1] = ohlcs[[sname[i]]]$close 29 | }else if(y == "open"){ 30 | z[,i+1] = ohlcs[[sname[i]]]$open 31 | }else if(y == "high"){ 32 | z[,i+1] = ohlcs[[sname[i]]]$high 33 | }else if(y == "low"){ 34 | z[,i+1] = ohlcs[[sname[i]]]$low 35 | }else if(y == "adjusted"){ 36 | z[,i+1] = ohlcs[[sname[i]]]$adjusted 37 | } 38 | } 39 | colnames(z) <- colname 40 | pdf <- melt(z, id="Date") 41 | ggplot(data=pdf, aes_string(x='Date', y='value', colour='variable'),...) + geom_line() + 42 | labs( title =main ) + labs(x="") + scale_y_continuous(name=y) + 43 | theme(axis.text.x=element_text(angle=90)) + theme(legend.title=element_blank()) 44 | } 45 | -------------------------------------------------------------------------------- /R/lt.d2e.R: -------------------------------------------------------------------------------- 1 | #' long-term debt-to-equity -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 2 | #' 3 | #' @param ltd long-term debt 4 | #' @param te total equity 5 | #' @seealso \code{\link{total.d2e}} 6 | #' @seealso \code{\link{debt.ratio}} 7 | #' @seealso \code{\link{financial.leverage}} 8 | #' @export 9 | #' @examples 10 | #' lt.d2e(ltd=8000,te=20000) 11 | lt.d2e <- function(ltd,te){ 12 | return(ltd/te) 13 | } 14 | -------------------------------------------------------------------------------- /R/mmy2hpr.R: -------------------------------------------------------------------------------- 1 | #' Computing HPR, the holding period return 2 | #' 3 | #' @param mmy money market yield 4 | #' @param t number of days remaining until maturity 5 | #' @seealso \code{\link{bdy2mmy}} 6 | #' @seealso \code{\link{hpr2mmy}} 7 | #' @seealso \code{\link{hpr}} 8 | #' @export 9 | #' @examples 10 | #' mmy2hpr(mmy=0.04898,t=150) 11 | mmy2hpr <- function(mmy, t){ 12 | return(mmy * t / 360) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/n.period.R: -------------------------------------------------------------------------------- 1 | #' Estimate the number of periods 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param pv present value 5 | #' @param fv future value 6 | #' @param pmt payment per period 7 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 8 | #' @seealso \code{\link{pv}} 9 | #' @seealso \code{\link{fv}} 10 | #' @seealso \code{\link{pmt}} 11 | #' @seealso \code{\link{discount.rate}} 12 | #' @export 13 | #' @examples 14 | #' n.period(0.1,-10000,60000000,-50000,0) 15 | #' 16 | #' n.period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1) 17 | n.period <- function(r,pv,fv,pmt,type=0){ 18 | if(type != 0 && type !=1){ 19 | print("Error: type should be 0 or 1!") 20 | }else{ 21 | n <- log(-1 * (fv*r-pmt* (1+r)^type)/(pv*r+pmt* (1+r)^type))/log(1+r) 22 | return(n) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /R/npm.R: -------------------------------------------------------------------------------- 1 | #' net profit margin -- Evaluate a company's financial performance 2 | #' 3 | #' @param ni net income 4 | #' @param rv revenue (sales) 5 | #' @seealso \code{\link{gpm}} 6 | #' @export 7 | #' @examples 8 | #' npm(ni=8000,rv=20000) 9 | npm <- function(ni,rv){ 10 | return(ni/rv) 11 | } 12 | -------------------------------------------------------------------------------- /R/npv.R: -------------------------------------------------------------------------------- 1 | #' Computing NPV, the PV of the cash flows less the initial (time = 0) outlay 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param cf cash flow,the first cash flow is the initial outlay 5 | #' @seealso \code{\link{pv.simple}} 6 | #' @seealso \code{\link{pv.uneven}} 7 | #' @seealso \code{\link{irr}} 8 | #' @export 9 | #' @examples 10 | #' npv(r=0.12, cf=c(-5, 1.6, 2.4, 2.8)) 11 | npv <- function(r,cf){ 12 | n <- length(cf) 13 | subcf <- cf[2:n] 14 | return(-1 * pv.uneven(r, subcf) + cf[1]) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /R/pmt.R: -------------------------------------------------------------------------------- 1 | #' Estimate period payment 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param pv present value 6 | #' @param fv future value 7 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 8 | #' @seealso \code{\link{pv}} 9 | #' @seealso \code{\link{fv}} 10 | #' @seealso \code{\link{n.period}} 11 | #' @export 12 | #' @examples 13 | #' pmt(0.08,10,-1000,10) 14 | #' 15 | #' pmt(r=0.08,n=10,pv=-1000,fv=0) 16 | #' 17 | #' pmt(0.08,10,-1000,10,1) 18 | pmt <- function(r,n,pv,fv,type=0){ 19 | if(type != 0 && type !=1){ 20 | print("Error: type should be 0 or 1!") 21 | }else{ 22 | pmt <- (pv+fv/(1+r)^n)*r/(1-1/(1+r)^n) * (-1) * (1+r)^(-1 * type) 23 | return(pmt) 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/pv.R: -------------------------------------------------------------------------------- 1 | #' Estimate present value (pv) 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param fv future value 6 | #' @param pmt payment per period 7 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 8 | #' @seealso \code{\link{pv.simple}} 9 | #' @seealso \code{\link{pv.annuity}} 10 | #' @seealso \code{\link{fv}} 11 | #' @seealso \code{\link{pmt}} 12 | #' @seealso \code{\link{n.period}} 13 | #' @seealso \code{\link{discount.rate}} 14 | #' @export 15 | #' @examples 16 | #' pv(0.07,10,1000,10) 17 | #' 18 | #' pv(r=0.05,n=20,fv=1000,pmt=10,type=1) 19 | pv <- function(r,n,fv=0,pmt=0,type=0){ 20 | if(type != 0 && type !=1){ 21 | print("Error: type should be 0 or 1!") 22 | }else{ 23 | pv <- pv.simple(r,n,fv) + pv.annuity(r,n,pmt,type) 24 | return(pv) 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/pv.annuity.R: -------------------------------------------------------------------------------- 1 | #' Estimate present value (pv) of an annuity 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param pmt payment per period 6 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 7 | #' @seealso \code{\link{pv}} 8 | #' @export 9 | #' @examples 10 | #' pv.annuity(0.03,12,1000) 11 | #' 12 | #' pv.annuity(r=0.0425,n=3,pmt=30000) 13 | pv.annuity <- function(r, n, pmt, type=0) { 14 | if(type != 0 && type !=1){ 15 | print("Error: type should be 0 or 1!") 16 | }else{ 17 | pv = (pmt / r * (1 - 1 / (1 + r)^n))*(1 + r)^type * (-1) 18 | return(pv) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /R/pv.perpetuity.R: -------------------------------------------------------------------------------- 1 | #' Estimate present value of a perpetuity 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param g growth rate of perpetuity 5 | #' @param pmt payment per period 6 | #' @param type payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) 7 | #' @seealso \code{\link{r.perpetuity}} 8 | #' @export 9 | #' @examples 10 | #' pv.perpetuity(r=0.1,pmt=1000,g=0.02) 11 | #' 12 | #' pv.perpetuity(r=0.1,pmt=1000,type=1) 13 | #' 14 | #' pv.perpetuity(r=0.1,pmt=1000) 15 | pv.perpetuity <- function(r, pmt, g=0, type=0){ 16 | if(type != 0 && type !=1){ 17 | print("Error: type should be 0 or 1!") 18 | }else{ 19 | if(g >= r){ 20 | print("Error: g is not smaller than r!") 21 | }else{ 22 | pv <- (pmt / (r - g)) * ((1 + r)^type) * (-1) 23 | return(pv) 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/pv.simple.R: -------------------------------------------------------------------------------- 1 | #' Estimate present value (pv) of a single sum 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param n number of periods 5 | #' @param fv future value 6 | #' @seealso \code{\link{pv}} 7 | #' @export 8 | #' @examples 9 | #' pv.simple(0.07,10,100) 10 | #' 11 | #' pv.simple(r=0.03,n=3,fv=1000) 12 | pv.simple <- function(r,n,fv){ 13 | return((fv/(1+r)^n)*(-1)) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/pv.uneven.R: -------------------------------------------------------------------------------- 1 | #' Computing the present value of an uneven cash flow series 2 | #' 3 | #' @param r discount rate, or the interest rate at which the amount will be compounded each period 4 | #' @param cf uneven cash flow 5 | #' @seealso \code{\link{pv.simple}} 6 | #' @seealso \code{\link{npv}} 7 | #' @export 8 | #' @examples 9 | #' pv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000)) 10 | pv.uneven <- function(r,cf){ 11 | n <- length(cf) 12 | sum <- 0 13 | for(i in 1:n){ 14 | sum <- sum + pv.simple(r,i,cf[i]) 15 | } 16 | return(sum) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /R/quick.ratio.R: -------------------------------------------------------------------------------- 1 | #' quick ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 2 | #' 3 | #' @param cash cash 4 | #' @param ms marketable securities 5 | #' @param rc receivables 6 | #' @param cl current liabilities 7 | #' @seealso \code{\link{current.ratio}} 8 | #' @seealso \code{\link{cash.ratio}} 9 | #' @export 10 | #' @examples 11 | #' quick.ratio(cash=3000,ms=2000,rc=1000,cl=2000) 12 | quick.ratio <- function(cash,ms,rc,cl){ 13 | return((cash+ms+rc)/cl) 14 | } 15 | -------------------------------------------------------------------------------- /R/r.continuous.R: -------------------------------------------------------------------------------- 1 | #' Convert a given norminal rate to a continuous compounded rate 2 | #' 3 | #' @param r norminal rate 4 | #' @param m number of times compounded each year 5 | #' @seealso \code{\link{r.norminal}} 6 | #' @export 7 | #' @examples 8 | #' r.continuous(0.03,4) 9 | r.continuous <- function(r,m) { 10 | return(m*log(1+r/m)) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/r.norminal.R: -------------------------------------------------------------------------------- 1 | #' Convert a given continuous compounded rate to a norminal rate 2 | #' 3 | #' @param rc continuous compounded rate 4 | #' @param m number of desired times compounded each year 5 | #' @seealso \code{\link{r.continuous}} 6 | #' @seealso \code{\link{ear.continuous}} 7 | #' @export 8 | #' @examples 9 | #' r.norminal(0.03,1) 10 | #' 11 | #' r.norminal(0.03,4) 12 | r.norminal <- function(rc,m) { 13 | return(m*(exp(rc/m)-1)) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/r.perpetuity.R: -------------------------------------------------------------------------------- 1 | #' Rate of return for a perpetuity 2 | #' 3 | #' @param pmt payment per period 4 | #' @param pv present value 5 | #' @seealso \code{\link{pv.perpetuity}} 6 | #' @export 7 | #' @examples 8 | #' r.perpetuity(pmt=4.5,pv=-75) 9 | r.perpetuity <- function(pmt, pv){ 10 | return(-1 * pmt / pv) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/sampling.error.R: -------------------------------------------------------------------------------- 1 | #' Computing Sampling error 2 | #' 3 | #' @param sm sample mean 4 | #' @param mu population mean 5 | #' @export 6 | #' @examples 7 | #' sampling.error(sm=0.45, mu=0.5) 8 | sampling.error <- function(sm,mu){ 9 | return(sm-mu) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /R/slde.R: -------------------------------------------------------------------------------- 1 | #' Depreciation Expense Recognition -- Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life 2 | #' 3 | #' @param cost cost of long-lived assets 4 | #' @param rv residual value of the long-lived assets at the end of its useful life 5 | #' @param t length of the useful life 6 | #' @seealso \code{\link{ddb}} 7 | #' @export 8 | #' @examples 9 | #' slde(cost=1200,rv=200,t=5) 10 | slde <- function(cost,rv,t){ 11 | return((cost-rv)/t) 12 | } 13 | -------------------------------------------------------------------------------- /R/total.d2e.R: -------------------------------------------------------------------------------- 1 | #' total debt-to-equity -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 2 | #' 3 | #' @param td total debt 4 | #' @param te total equity 5 | #' @seealso \code{\link{total.d2e}} 6 | #' @seealso \code{\link{debt.ratio}} 7 | #' @seealso \code{\link{financial.leverage}} 8 | #' @export 9 | #' @examples 10 | #' total.d2e(td=6000,te=20000) 11 | total.d2e <- function(td,te){ 12 | return(td/te) 13 | } 14 | -------------------------------------------------------------------------------- /R/twrr.R: -------------------------------------------------------------------------------- 1 | #' Computing TWRR, the time-weighted rate of return 2 | #' 3 | #' @param ev ordered ending value list 4 | #' @param bv ordered beginning value list 5 | #' @param cfr ordered cash flow received list 6 | #' @seealso \code{\link{hpr}} 7 | #' @export 8 | #' @examples 9 | #' twrr(ev=c(120,260),bv=c(100,240),cfr=c(2,4)) 10 | twrr <- function(ev,bv,cfr){ 11 | r=length(ev) 12 | s=length(bv) 13 | t=length(cfr) 14 | wr=1 15 | if(r != s || r != t || s != t){ 16 | stop("Different number of values!") 17 | }else{ 18 | for(i in 1:r){ 19 | wr = wr * (hpr(ev[i],bv[i],cfr[i]) + 1) 20 | } 21 | return(wr^(1/r) - 1) 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /R/volumeChart.R: -------------------------------------------------------------------------------- 1 | #' Technical analysts - Volume charts: show each period's volume as a vertical line 2 | #' 3 | #' @param ohlc output from get.ohlc.yahoo or get.ohlc.google 4 | #' @param main an overall title for the plot 5 | #' @param ... Arguments to be passed to ggplot 6 | #' @seealso \code{\link{get.ohlc.yahoo}} 7 | #' @seealso \code{\link{get.ohlc.google}} 8 | #' @importFrom ggplot2 ggplot geom_bar theme labs aes_string element_text 9 | #' @export 10 | #' @examples 11 | #' # google <- get.ohlc.yahoo("GOOG"); 12 | #' # volumeChart(google) 13 | #' # apple <- get.ohlc.google("AAPL"); 14 | #' # volumeChart(apple) 15 | volumeChart <- function(ohlc,main="",...){ 16 | options(warn=-1) 17 | ohlc$date <- as.Date(ohlc$date,"%Y-%m-%d") 18 | g=ggplot(ohlc, aes_string(x='date',y='volume')) + geom_bar(stat="identity") + labs( title =main ) + labs(x="") + 19 | theme(axis.text.x=element_text(angle=90)) 20 | return(g) 21 | } 22 | -------------------------------------------------------------------------------- /R/was.R: -------------------------------------------------------------------------------- 1 | #' calculate weighted average shares -- weighted average number of common shares 2 | #' 3 | #' @param ns n x 1 vector vector of number of shares 4 | #' @param nm n x 1 vector vector of number of months relate to ns 5 | #' @seealso \code{\link{EPS}} 6 | #' @seealso \code{\link{diluted.EPS}} 7 | #' @export 8 | #' @examples 9 | #' s=c(10000,2000);m=c(12,6);was(ns=s,nm=m) 10 | #' 11 | #' s=c(11000,4400,-3000);m=c(12,9,4);was(ns=s,nm=m) 12 | was <- function(ns,nm){ 13 | m=length(ns) 14 | n=length(nm) 15 | sum=0 16 | if(m==n){ 17 | for(i in 1:m){ 18 | sum=sum+ns[i]*nm[i] 19 | } 20 | }else{ 21 | stop("length of ns and nm must be equal") 22 | } 23 | sum=sum/12 24 | return(sum) 25 | } 26 | -------------------------------------------------------------------------------- /R/wpr.R: -------------------------------------------------------------------------------- 1 | #' Weighted mean as a portfolio return 2 | #' 3 | #' @param r returns of the individual assets in the portfolio 4 | #' @param w corresponding weights associated with each of the individual assets 5 | #' @export 6 | #' @examples 7 | #' wpr(r=c(0.12, 0.07, 0.03),w=c(0.5,0.4,0.1)) 8 | wpr <- function(r,w){ 9 | if(sum(w) != 1){ 10 | warning("sum of weights is NOT equal to 1!") 11 | return(sum(r*w)) 12 | }else{ 13 | return(sum(r*w)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badge/) 2 | [![GPL Licence](https://badges.frapsoft.com/os/gpl/gpl.svg?v=103)](https://opensource.org/licenses/GPL-3.0/) 3 | [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) 4 | 5 | 6 | Examples of using FinCal 7 | ======================================================== 8 | Created on Fri Jul 19 2013 9 | Updated on Mon May 12 15:57:11 2014 10 | 11 | 12 | FinCal -- Time Value of Money, time series analysis and Computational Finance 13 | -------------------------------------------------------------------------------- 14 | FinCal is available on [CRAN] (http://cran.r-project.org/web/packages/FinCal/) and [GitHub](http://felixfan.github.io/FinCal/) 15 | 16 | ``` 17 | install.packages("FinCal",dependencies=TRUE) # from CRAN 18 | ``` 19 | or 20 | 21 | ``` 22 | library("devtools") 23 | install_github("felixfan/FinCal") # from GitHub 24 | ``` 25 | 26 | 27 | ```r 28 | library(FinCal) 29 | ``` 30 | 31 | 32 | Functions available: 33 | 34 | ```r 35 | ls("package:FinCal") 36 | ``` 37 | 38 | ``` 39 | [1] "bdy" "bdy2mmy" 40 | [3] "candlestickChart" "cash.ratio" 41 | [5] "coefficient.variation" "cogs" 42 | [7] "current.ratio" "ddb" 43 | [9] "debt.ratio" "diluted.EPS" 44 | [11] "discount.rate" "ear" 45 | [13] "ear.continuous" "ear2bey" 46 | [15] "ear2hpr" "EIR" 47 | [17] "EPS" "financial.leverage" 48 | [19] "fv" "fv.annuity" 49 | [21] "fv.simple" "fv.uneven" 50 | [23] "geometric.mean" "get.ohlc.google" 51 | [25] "get.ohlc.yahoo" "get.ohlcs.google" 52 | [27] "get.ohlcs.yahoo" "gpm" 53 | [29] "harmonic.mean" "hpr" 54 | [31] "hpr2bey" "hpr2ear" 55 | [33] "hpr2mmy" "irr" 56 | [35] "iss" "lineChart" 57 | [37] "lineChartMult" "lt.d2e" 58 | [39] "mmy2hpr" "n.period" 59 | [41] "npm" "npv" 60 | [43] "pmt" "pv" 61 | [45] "pv.annuity" "pv.perpetuity" 62 | [47] "pv.simple" "pv.uneven" 63 | [49] "quick.ratio" "r.continuous" 64 | [51] "r.norminal" "r.perpetuity" 65 | [53] "sampling.error" "SFRatio" 66 | [55] "Sharpe.ratio" "slde" 67 | [57] "total.d2e" "twrr" 68 | [59] "volumeChart" "was" 69 | [61] "wpr" 70 | ``` 71 | 72 | 73 | Getting help on a function (e.g., pv) 74 | ``` 75 | help{pv} # display the documentation for the function 76 | args{pv} # see arguments of the function 77 | example{pv} # see example of using the function 78 | ``` 79 | 80 | * [Examples for version 0.1 -0.6](http://felixfan.github.io/FinCal-example-0.6/) 81 | 82 | 83 | # Citations 84 | 85 | * Yanhui Fan. (2016) FinCal: package for time value of money calculation, time series analysis and computational finance. Zenodo. [![DOI](https://zenodo.org/badge/5810/felixfan/FinCal.svg)](https://zenodo.org/badge/latestdoi/5810/felixfan/FinCal) 86 | -------------------------------------------------------------------------------- /man/EIR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EIR.R 3 | \name{EIR} 4 | \alias{EIR} 5 | \title{Equivalent/proportional Interest Rates} 6 | \usage{ 7 | EIR(r, n = 1, p = 12, type = c("e", "p")) 8 | } 9 | \arguments{ 10 | \item{r}{interest rate to be applied n times per year (r is annual rate!)} 11 | 12 | \item{n}{times that the interest rate r were compounded per year} 13 | 14 | \item{p}{times that the equivalent rate were compounded per year} 15 | 16 | \item{type}{equivalent interest rates ('e',default) or proportional interest rates ('p')} 17 | } 18 | \description{ 19 | An interest rate to be applied n times p.a. can be converted to an equivalent rate to be applied p times p.a. 20 | } 21 | \examples{ 22 | # monthly interest rat equivalent to 5\% compounded per year 23 | EIR(r=0.05,n=1,p=12) 24 | 25 | # monthly interest rat equivalent to 5\% compounded per half year 26 | EIR(r=0.05,n=2,p=12) 27 | 28 | # monthly interest rat equivalent to 5\% compounded per quarter 29 | EIR(r=0.05,n=4,p=12) 30 | 31 | # annual interest rate equivalent to 5\% compounded per month 32 | EIR(r=0.05,n=12,p=1) 33 | # this is equivalent to 34 | ear(r=0.05,m=12) 35 | 36 | # quarter interest rate equivalent to 5\% compounded per year 37 | EIR(r=0.05,n=1,p=4) 38 | 39 | # quarter interest rate equivalent to 5\% compounded per month 40 | EIR(r=0.05,n=12,p=4) 41 | 42 | # monthly proportional interest rate which is equivalent to a simple annual interest 43 | EIR(r=0.05,p=12,type='p') 44 | } 45 | -------------------------------------------------------------------------------- /man/EPS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EPS.R 3 | \name{EPS} 4 | \alias{EPS} 5 | \title{Basic Earnings Per Share} 6 | \usage{ 7 | EPS(ni, pd, w) 8 | } 9 | \arguments{ 10 | \item{ni}{net income} 11 | 12 | \item{pd}{preferred dividends} 13 | 14 | \item{w}{weighted average number of common shares outstanding} 15 | } 16 | \description{ 17 | Basic Earnings Per Share 18 | } 19 | \examples{ 20 | EPS(ni=10000,pd=1000,w=11000) 21 | } 22 | \seealso{ 23 | \code{\link{diluted.EPS}} 24 | 25 | \code{\link{was}} 26 | } 27 | -------------------------------------------------------------------------------- /man/SFRatio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SFRatio.R 3 | \name{SFRatio} 4 | \alias{SFRatio} 5 | \title{Computing Roy's safety-first ratio} 6 | \usage{ 7 | SFRatio(rp, rl, sd) 8 | } 9 | \arguments{ 10 | \item{rp}{portfolio return} 11 | 12 | \item{rl}{threshold level return} 13 | 14 | \item{sd}{standard deviation of portfolio retwns} 15 | } 16 | \description{ 17 | Computing Roy's safety-first ratio 18 | } 19 | \examples{ 20 | SFRatio(rp=0.09,rl=0.03,sd=0.12) 21 | } 22 | \seealso{ 23 | \code{\link{Sharpe.ratio}} 24 | } 25 | -------------------------------------------------------------------------------- /man/Sharpe.ratio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Sharpe.ratio.R 3 | \name{Sharpe.ratio} 4 | \alias{Sharpe.ratio} 5 | \title{Computing Sharpe Ratio} 6 | \usage{ 7 | Sharpe.ratio(rp, rf, sd) 8 | } 9 | \arguments{ 10 | \item{rp}{portfolio return} 11 | 12 | \item{rf}{risk-free return} 13 | 14 | \item{sd}{standard deviation of portfolio retwns} 15 | } 16 | \description{ 17 | Computing Sharpe Ratio 18 | } 19 | \examples{ 20 | Sharpe.ratio(rp=0.038,rf=0.015,sd=0.07) 21 | } 22 | \seealso{ 23 | \code{\link{coefficient.variation}} 24 | 25 | \code{\link{SFRatio}} 26 | } 27 | -------------------------------------------------------------------------------- /man/bdy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bdy.R 3 | \name{bdy} 4 | \alias{bdy} 5 | \title{Computing bank discount yield (BDY) for a T-bill} 6 | \usage{ 7 | bdy(d, f, t) 8 | } 9 | \arguments{ 10 | \item{d}{the dollar discount, which is equal to the difference between the face value of the bill and the purchase price} 11 | 12 | \item{f}{the face value (par value) of the bill} 13 | 14 | \item{t}{number of days remaining until maturity} 15 | } 16 | \description{ 17 | Computing bank discount yield (BDY) for a T-bill 18 | } 19 | \examples{ 20 | bdy(d=1500,f=100000,t=120) 21 | } 22 | \seealso{ 23 | \code{\link{bdy2mmy}} 24 | } 25 | -------------------------------------------------------------------------------- /man/bdy2mmy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bdy2mmy.R 3 | \name{bdy2mmy} 4 | \alias{bdy2mmy} 5 | \title{Computing money market yield (MMY) for a T-bill} 6 | \usage{ 7 | bdy2mmy(bdy, t) 8 | } 9 | \arguments{ 10 | \item{bdy}{bank discount yield} 11 | 12 | \item{t}{number of days remaining until maturity} 13 | } 14 | \description{ 15 | Computing money market yield (MMY) for a T-bill 16 | } 17 | \examples{ 18 | bdy2mmy(bdy=0.045,t=120) 19 | } 20 | \seealso{ 21 | \code{\link{bdy}} 22 | } 23 | -------------------------------------------------------------------------------- /man/candlestickChart.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/candlestickChart.R 3 | \name{candlestickChart} 4 | \alias{candlestickChart} 5 | \title{Technical analysts - Candlestick chart: show prices for each period as a continuous line. The box is clear if the closing price is higher than the opening price, or filled red if the closing is lower than the opening price.} 6 | \usage{ 7 | candlestickChart(ohlc, start = NULL, end = NULL, main = "", ...) 8 | } 9 | \arguments{ 10 | \item{ohlc}{output from get.ohlc.yahoo or get.ohlc.google} 11 | 12 | \item{start}{start date to plot, if not specified, all date in ohlc will be included} 13 | 14 | \item{end}{end date to plot} 15 | 16 | \item{main}{an overall title for the plot} 17 | 18 | \item{...}{Arguments to be passed to ggplot} 19 | } 20 | \description{ 21 | Technical analysts - Candlestick chart: show prices for each period as a continuous line. The box is clear if the closing price is higher than the opening price, or filled red if the closing is lower than the opening price. 22 | } 23 | \examples{ 24 | # google <- get.ohlc.yahoo("GOOG",start="2013-07-01",end="2013-08-01"); candlestickChart(google) 25 | # apple <- get.ohlc.google("AAPL",start="2013-07-01",end="2013-08-01"); candlestickChart(apple) 26 | } 27 | \seealso{ 28 | \code{\link{get.ohlc.yahoo}} 29 | 30 | \code{\link{get.ohlc.google}} 31 | } 32 | -------------------------------------------------------------------------------- /man/cash.ratio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cash.ratio.R 3 | \name{cash.ratio} 4 | \alias{cash.ratio} 5 | \title{cash ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.} 6 | \usage{ 7 | cash.ratio(cash, ms, cl) 8 | } 9 | \arguments{ 10 | \item{cash}{cash} 11 | 12 | \item{ms}{marketable securities} 13 | 14 | \item{cl}{current liabilities} 15 | } 16 | \description{ 17 | cash ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 18 | } 19 | \examples{ 20 | cash.ratio(cash=3000,ms=2000,cl=2000) 21 | } 22 | \seealso{ 23 | \code{\link{current.ratio}} 24 | 25 | \code{\link{quick.ratio}} 26 | } 27 | -------------------------------------------------------------------------------- /man/coefficient.variation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coefficient.variation.R 3 | \name{coefficient.variation} 4 | \alias{coefficient.variation} 5 | \title{Computing Coefficient of variation} 6 | \usage{ 7 | coefficient.variation(sd, avg) 8 | } 9 | \arguments{ 10 | \item{sd}{standard deviation} 11 | 12 | \item{avg}{average value} 13 | } 14 | \description{ 15 | Computing Coefficient of variation 16 | } 17 | \examples{ 18 | coefficient.variation(sd=0.15,avg=0.39) 19 | } 20 | \seealso{ 21 | \code{\link{Sharpe.ratio}} 22 | } 23 | -------------------------------------------------------------------------------- /man/cogs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cogs.R 3 | \name{cogs} 4 | \alias{cogs} 5 | \title{Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average)} 6 | \usage{ 7 | cogs(uinv, pinv, units, price, sinv, method = "FIFO") 8 | } 9 | \arguments{ 10 | \item{uinv}{units of beginning inventory} 11 | 12 | \item{pinv}{prince of beginning inventory} 13 | 14 | \item{units}{nx1 vector of inventory units. inventory purchased ordered by time (from first to last)} 15 | 16 | \item{price}{nx1 vector of inventory price. same order as units} 17 | 18 | \item{sinv}{units of sold inventory} 19 | 20 | \item{method}{inventory methods: FIFO (first in first out, permitted under both US and IFRS), LIFO (late in first out, US only), WAC (weighted average cost,US and IFRS)} 21 | } 22 | \description{ 23 | Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average) 24 | } 25 | \examples{ 26 | cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="FIFO") 27 | 28 | cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="LIFO") 29 | 30 | cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="WAC") 31 | } 32 | -------------------------------------------------------------------------------- /man/current.ratio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/current.ratio.R 3 | \name{current.ratio} 4 | \alias{current.ratio} 5 | \title{current ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.} 6 | \usage{ 7 | current.ratio(ca, cl) 8 | } 9 | \arguments{ 10 | \item{ca}{current assets} 11 | 12 | \item{cl}{current liabilities} 13 | } 14 | \description{ 15 | current ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 16 | } 17 | \examples{ 18 | current.ratio(ca=8000,cl=2000) 19 | } 20 | \seealso{ 21 | \code{\link{cash.ratio}} 22 | 23 | \code{\link{quick.ratio}} 24 | } 25 | -------------------------------------------------------------------------------- /man/ddb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ddb.R 3 | \name{ddb} 4 | \alias{ddb} 5 | \title{Depreciation Expense Recognition -- double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance.} 6 | \usage{ 7 | ddb(cost, rv, t) 8 | } 9 | \arguments{ 10 | \item{cost}{cost of long-lived assets} 11 | 12 | \item{rv}{residual value of the long-lived assets at the end of its useful life. DDB does not explicitly use the asset's residual value in the calculations, but depreciation ends once the estimated residual value has been reached. If the asset is expected to have no residual value, the DB method will never fully depreciate it, so the DB method is typically changed to straight-line at some point in the asset's life.} 13 | 14 | \item{t}{length of the useful life} 15 | } 16 | \description{ 17 | Depreciation Expense Recognition -- double-declining balance (DDB), the most common declining balance method, which applies two times the straight-line rate to the declining balance. 18 | } 19 | \examples{ 20 | ddb(cost=1200,rv=200,t=5) 21 | } 22 | \seealso{ 23 | \code{\link{slde}} 24 | } 25 | -------------------------------------------------------------------------------- /man/debt.ratio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/debt.ratio.R 3 | \name{debt.ratio} 4 | \alias{debt.ratio} 5 | \title{debt ratio -- Solvency ratios measure the firm's ability to satisfy its long-term obligations.} 6 | \usage{ 7 | debt.ratio(td, ta) 8 | } 9 | \arguments{ 10 | \item{td}{total debt} 11 | 12 | \item{ta}{total assets} 13 | } 14 | \description{ 15 | debt ratio -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 16 | } 17 | \examples{ 18 | debt.ratio(td=6000,ta=20000) 19 | } 20 | \seealso{ 21 | \code{\link{total.d2e}} 22 | 23 | \code{\link{lt.d2e}} 24 | 25 | \code{\link{financial.leverage}} 26 | } 27 | -------------------------------------------------------------------------------- /man/diluted.EPS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/diluted.EPS.R 3 | \name{diluted.EPS} 4 | \alias{diluted.EPS} 5 | \title{diluted Earnings Per Share} 6 | \usage{ 7 | diluted.EPS(ni, pd, cpd = 0, cdi = 0, tax = 0, w, cps = 0, cds = 0, 8 | iss = 0) 9 | } 10 | \arguments{ 11 | \item{ni}{net income} 12 | 13 | \item{pd}{preferred dividends} 14 | 15 | \item{cpd}{dividends on convertible preferred stock} 16 | 17 | \item{cdi}{interest on convertible debt} 18 | 19 | \item{tax}{tax rate} 20 | 21 | \item{w}{weighted average number of common shares outstanding} 22 | 23 | \item{cps}{shares from conversion of convertible preferred stock} 24 | 25 | \item{cds}{shares from conversion of convertible debt} 26 | 27 | \item{iss}{shares issuable from stock options} 28 | } 29 | \description{ 30 | diluted Earnings Per Share 31 | } 32 | \examples{ 33 | diluted.EPS(ni=115600,pd=10000,cdi=42000,tax=0.4,w=200000,cds=60000) 34 | 35 | diluted.EPS(ni=115600,pd=10000,cpd=10000,w=200000,cps=40000) 36 | 37 | diluted.EPS(ni=115600,pd=10000,w=200000,iss=2500) 38 | 39 | diluted.EPS(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000,cps=40000,cds=60000,iss=2500) 40 | } 41 | \seealso{ 42 | \code{\link{EPS}} 43 | 44 | \code{\link{iss}} 45 | 46 | \code{\link{was}} 47 | } 48 | -------------------------------------------------------------------------------- /man/discount.rate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/discount.rate.R 3 | \name{discount.rate} 4 | \alias{discount.rate} 5 | \title{Computing the rate of return for each period} 6 | \usage{ 7 | discount.rate(n, pv, fv, pmt, type = 0, lower = 1e-04, upper = 100) 8 | } 9 | \arguments{ 10 | \item{n}{number of periods} 11 | 12 | \item{pv}{present value} 13 | 14 | \item{fv}{future value} 15 | 16 | \item{pmt}{payment per period} 17 | 18 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 19 | 20 | \item{lower}{the lower end points of the rate of return to be searched.} 21 | 22 | \item{upper}{the upper end points of the rate of return to be searched.} 23 | } 24 | \description{ 25 | Computing the rate of return for each period 26 | } 27 | \examples{ 28 | discount.rate(n=5,pv=0,fv=600,pmt=-100,type=0) 29 | } 30 | \seealso{ 31 | \code{\link{fv.simple}} 32 | 33 | \code{\link{fv.annuity}} 34 | 35 | \code{\link{fv}} 36 | 37 | \code{\link{pv}} 38 | 39 | \code{\link{pmt}} 40 | 41 | \code{\link{n.period}} 42 | } 43 | -------------------------------------------------------------------------------- /man/ear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ear.R 3 | \name{ear} 4 | \alias{ear} 5 | \title{Convert stated annual rate to the effective annual rate} 6 | \usage{ 7 | ear(r, m) 8 | } 9 | \arguments{ 10 | \item{r}{stated annual rate} 11 | 12 | \item{m}{number of compounding periods per year} 13 | } 14 | \description{ 15 | Convert stated annual rate to the effective annual rate 16 | } 17 | \examples{ 18 | ear(r=0.12,m=12) 19 | 20 | ear(0.04,365) 21 | } 22 | \seealso{ 23 | \code{\link{ear.continuous}} 24 | 25 | \code{\link{hpr2ear}} 26 | 27 | \code{\link{ear2bey}} 28 | 29 | \code{\link{ear2hpr}} 30 | } 31 | -------------------------------------------------------------------------------- /man/ear.continuous.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ear.continuous.R 3 | \name{ear.continuous} 4 | \alias{ear.continuous} 5 | \title{Convert stated annual rate to the effective annual rate with continuous compounding} 6 | \usage{ 7 | ear.continuous(r) 8 | } 9 | \arguments{ 10 | \item{r}{stated annual rate} 11 | } 12 | \description{ 13 | Convert stated annual rate to the effective annual rate with continuous compounding 14 | } 15 | \examples{ 16 | ear.continuous(r=0.1) 17 | 18 | ear.continuous(0.03) 19 | } 20 | \seealso{ 21 | \code{\link{ear}} 22 | 23 | \code{\link{r.norminal}} 24 | } 25 | -------------------------------------------------------------------------------- /man/ear2bey.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ear2bey.R 3 | \name{ear2bey} 4 | \alias{ear2bey} 5 | \title{bond-equivalent yield (BEY), 2 x the semiannual discount rate} 6 | \usage{ 7 | ear2bey(ear) 8 | } 9 | \arguments{ 10 | \item{ear}{effective annual rate} 11 | } 12 | \description{ 13 | bond-equivalent yield (BEY), 2 x the semiannual discount rate 14 | } 15 | \examples{ 16 | ear2bey(ear=0.08) 17 | } 18 | \seealso{ 19 | \code{\link{ear}} 20 | } 21 | -------------------------------------------------------------------------------- /man/ear2hpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ear2hpr.R 3 | \name{ear2hpr} 4 | \alias{ear2hpr} 5 | \title{Computing HPR, the holding period return} 6 | \usage{ 7 | ear2hpr(ear, t) 8 | } 9 | \arguments{ 10 | \item{ear}{effective annual rate} 11 | 12 | \item{t}{number of days remaining until maturity} 13 | } 14 | \description{ 15 | Computing HPR, the holding period return 16 | } 17 | \examples{ 18 | ear2hpr(ear=0.05039,t=150) 19 | } 20 | \seealso{ 21 | \code{\link{hpr2ear}} 22 | 23 | \code{\link{ear}} 24 | 25 | \code{\link{hpr}} 26 | } 27 | -------------------------------------------------------------------------------- /man/financial.leverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/financial.leverage.R 3 | \name{financial.leverage} 4 | \alias{financial.leverage} 5 | \title{financial leverage -- Solvency ratios measure the firm's ability to satisfy its long-term obligations.} 6 | \usage{ 7 | financial.leverage(te, ta) 8 | } 9 | \arguments{ 10 | \item{te}{total equity} 11 | 12 | \item{ta}{total assets} 13 | } 14 | \description{ 15 | financial leverage -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 16 | } 17 | \examples{ 18 | financial.leverage(te=16000,ta=20000) 19 | } 20 | \seealso{ 21 | \code{\link{total.d2e}} 22 | 23 | \code{\link{lt.d2e}} 24 | 25 | \code{\link{debt.ratio}} 26 | } 27 | -------------------------------------------------------------------------------- /man/fv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fv.R 3 | \name{fv} 4 | \alias{fv} 5 | \title{Estimate future value (fv)} 6 | \usage{ 7 | fv(r, n, pv = 0, pmt = 0, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{pv}{present value} 15 | 16 | \item{pmt}{payment per period} 17 | 18 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 19 | } 20 | \description{ 21 | Estimate future value (fv) 22 | } 23 | \examples{ 24 | fv(0.07,10,1000,10) 25 | } 26 | \seealso{ 27 | \code{\link{fv.simple}} 28 | 29 | \code{\link{fv.annuity}} 30 | 31 | \code{\link{pv}} 32 | 33 | \code{\link{pmt}} 34 | 35 | \code{\link{n.period}} 36 | 37 | \code{\link{discount.rate}} 38 | } 39 | -------------------------------------------------------------------------------- /man/fv.annuity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fv.annuity.R 3 | \name{fv.annuity} 4 | \alias{fv.annuity} 5 | \title{Estimate future value of an annuity} 6 | \usage{ 7 | fv.annuity(r, n, pmt, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{pmt}{payment per period} 15 | 16 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 17 | } 18 | \description{ 19 | Estimate future value of an annuity 20 | } 21 | \examples{ 22 | fv.annuity(0.03,12,-1000) 23 | 24 | fv.annuity(r=0.03,n=12,pmt=-1000,type=1) 25 | } 26 | \seealso{ 27 | \code{\link{fv}} 28 | } 29 | -------------------------------------------------------------------------------- /man/fv.simple.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fv.simple.R 3 | \name{fv.simple} 4 | \alias{fv.simple} 5 | \title{Estimate future value (fv) of a single sum} 6 | \usage{ 7 | fv.simple(r, n, pv) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{pv}{present value} 15 | } 16 | \description{ 17 | Estimate future value (fv) of a single sum 18 | } 19 | \examples{ 20 | fv.simple(0.08,10,-300) 21 | 22 | fv.simple(r=0.04,n=20,pv=-50000) 23 | } 24 | \seealso{ 25 | \code{\link{fv}} 26 | } 27 | -------------------------------------------------------------------------------- /man/fv.uneven.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fv.uneven.R 3 | \name{fv.uneven} 4 | \alias{fv.uneven} 5 | \title{Computing the future value of an uneven cash flow series} 6 | \usage{ 7 | fv.uneven(r, cf) 8 | } 9 | \arguments{ 10 | \item{r}{stated annual rate} 11 | 12 | \item{cf}{uneven cash flow} 13 | } 14 | \description{ 15 | Computing the future value of an uneven cash flow series 16 | } 17 | \examples{ 18 | fv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000)) 19 | } 20 | \seealso{ 21 | \code{\link{fv.simple}} 22 | } 23 | -------------------------------------------------------------------------------- /man/geometric.mean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/geometric.mean.R 3 | \name{geometric.mean} 4 | \alias{geometric.mean} 5 | \title{Geometric mean return} 6 | \usage{ 7 | geometric.mean(r) 8 | } 9 | \arguments{ 10 | \item{r}{returns over multiple periods} 11 | } 12 | \description{ 13 | Geometric mean return 14 | } 15 | \examples{ 16 | geometric.mean(r=c(-0.0934, 0.2345, 0.0892)) 17 | } 18 | -------------------------------------------------------------------------------- /man/get.ohlc.google.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get.ohlc.google.R 3 | \name{get.ohlc.google} 4 | \alias{get.ohlc.google} 5 | \title{Download stock prices from Google Finance (open, high, low, close, volume)} 6 | \usage{ 7 | get.ohlc.google(symbol, start = "2013-01-01", end = "today") 8 | } 9 | \arguments{ 10 | \item{symbol}{symbol of stock, e.g. AAPL, GOOG, SPX} 11 | 12 | \item{start}{start date, e.g., 2013-07-31} 13 | 14 | \item{end}{end date, e.g., 2013-08-06} 15 | } 16 | \description{ 17 | Download stock prices from Google Finance (open, high, low, close, volume) 18 | } 19 | \examples{ 20 | # get.ohlc.google(symbol="AAPL") 21 | # get.ohlc.google(symbol="AAPL",start="2013-08-01") 22 | # get.ohlc.google(symbol="AAPL",start="2013-07-01",end="2013-08-01") 23 | } 24 | \seealso{ 25 | \code{\link{get.ohlc.yahoo}} 26 | 27 | \code{\link{get.ohlcs.google}} 28 | } 29 | -------------------------------------------------------------------------------- /man/get.ohlc.yahoo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get.ohlc.yahoo.R 3 | \name{get.ohlc.yahoo} 4 | \alias{get.ohlc.yahoo} 5 | \title{Download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted)} 6 | \usage{ 7 | get.ohlc.yahoo(symbol, start = "firstDay", end = "today", freq = "d") 8 | } 9 | \arguments{ 10 | \item{symbol}{symbol of stock, e.g. AAPL, GOOG, SPX} 11 | 12 | \item{start}{start date, e.g., 2013-07-31} 13 | 14 | \item{end}{end date, e.g., 2013-08-06} 15 | 16 | \item{freq}{time interval, e.g., d:daily, w:weekly, m:monthly} 17 | } 18 | \description{ 19 | Download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted) 20 | } 21 | \examples{ 22 | # get.ohlc.yahoo(symbol="AAPL") 23 | # get.ohlc.yahoo(symbol="AAPL",start="2013-08-01",freq="d") 24 | # get.ohlc.yahoo(symbol="AAPL",start="2013-07-01",end="2013-08-01",freq="w") 25 | } 26 | \seealso{ 27 | \code{\link{get.ohlcs.yahoo}} 28 | 29 | \code{\link{get.ohlc.google}} 30 | } 31 | -------------------------------------------------------------------------------- /man/get.ohlcs.google.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get.ohlcs.google.R 3 | \name{get.ohlcs.google} 4 | \alias{get.ohlcs.google} 5 | \title{Batch download stock prices from Google Finance (open, high, low, close, volume)} 6 | \usage{ 7 | get.ohlcs.google(symbols, start = "2013-01-01", end = "today") 8 | } 9 | \arguments{ 10 | \item{symbols}{symbols of stock, e.g. AAPL, GOOG, SPX} 11 | 12 | \item{start}{start date, e.g., 2013-07-31} 13 | 14 | \item{end}{end date, e.g., 2013-08-06} 15 | } 16 | \description{ 17 | Batch download stock prices from Google Finance (open, high, low, close, volume) 18 | } 19 | \examples{ 20 | # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY")) 21 | # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01") 22 | # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",end="2013-07-31") 23 | } 24 | \seealso{ 25 | \code{\link{get.ohlc.google}} 26 | 27 | \code{\link{get.ohlcs.yahoo}} 28 | } 29 | -------------------------------------------------------------------------------- /man/get.ohlcs.yahoo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get.ohlcs.yahoo.R 3 | \name{get.ohlcs.yahoo} 4 | \alias{get.ohlcs.yahoo} 5 | \title{Batch download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted)} 6 | \usage{ 7 | get.ohlcs.yahoo(symbols, start = "firstDay", end = "today", freq = "d") 8 | } 9 | \arguments{ 10 | \item{symbols}{symbols of stock, e.g. AAPL, GOOG, SPX} 11 | 12 | \item{start}{start date, e.g., 2013-07-31} 13 | 14 | \item{end}{end date, e.g., 2013-08-06} 15 | 16 | \item{freq}{time interval, e.g., d:daily, w:weekly, m:monthly} 17 | } 18 | \description{ 19 | Batch download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted) 20 | } 21 | \examples{ 22 | # get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),freq="d") 23 | # get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",freq="m") 24 | } 25 | \seealso{ 26 | \code{\link{get.ohlc.yahoo}} 27 | 28 | \code{\link{get.ohlcs.google}} 29 | } 30 | -------------------------------------------------------------------------------- /man/gpm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gpm.R 3 | \name{gpm} 4 | \alias{gpm} 5 | \title{gross profit margin -- Evaluate a company's financial performance} 6 | \usage{ 7 | gpm(gp, rv) 8 | } 9 | \arguments{ 10 | \item{gp}{gross profit, equal to revenue minus cost of goods sold (cogs)} 11 | 12 | \item{rv}{revenue (sales)} 13 | } 14 | \description{ 15 | gross profit margin -- Evaluate a company's financial performance 16 | } 17 | \examples{ 18 | gpm(gp=1000,rv=20000) 19 | } 20 | \seealso{ 21 | \code{\link{npm}} 22 | } 23 | -------------------------------------------------------------------------------- /man/harmonic.mean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/harmonic.mean.R 3 | \name{harmonic.mean} 4 | \alias{harmonic.mean} 5 | \title{harmonic mean, average price} 6 | \usage{ 7 | harmonic.mean(p) 8 | } 9 | \arguments{ 10 | \item{p}{price over multiple periods} 11 | } 12 | \description{ 13 | harmonic mean, average price 14 | } 15 | \examples{ 16 | harmonic.mean(p=c(8,9,10)) 17 | } 18 | -------------------------------------------------------------------------------- /man/hpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hpr.R 3 | \name{hpr} 4 | \alias{hpr} 5 | \title{Computing HPR, the holding period return} 6 | \usage{ 7 | hpr(ev, bv, cfr = 0) 8 | } 9 | \arguments{ 10 | \item{ev}{ending value} 11 | 12 | \item{bv}{beginning value} 13 | 14 | \item{cfr}{cash flow received} 15 | } 16 | \description{ 17 | Computing HPR, the holding period return 18 | } 19 | \examples{ 20 | hpr(ev=33,bv=30,cfr=0.5) 21 | } 22 | \seealso{ 23 | \code{\link{twrr}} 24 | 25 | \code{\link{hpr2ear}} 26 | 27 | \code{\link{hpr2mmy}} 28 | } 29 | -------------------------------------------------------------------------------- /man/hpr2bey.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hpr2bey.R 3 | \name{hpr2bey} 4 | \alias{hpr2bey} 5 | \title{bond-equivalent yield (BEY), 2 x the semiannual discount rate} 6 | \usage{ 7 | hpr2bey(hpr, t) 8 | } 9 | \arguments{ 10 | \item{hpr}{holding period return} 11 | 12 | \item{t}{number of month remaining until maturity} 13 | } 14 | \description{ 15 | bond-equivalent yield (BEY), 2 x the semiannual discount rate 16 | } 17 | \examples{ 18 | hpr2bey(hpr=0.02,t=3) 19 | } 20 | \seealso{ 21 | \code{\link{hpr}} 22 | } 23 | -------------------------------------------------------------------------------- /man/hpr2ear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hpr2ear.R 3 | \name{hpr2ear} 4 | \alias{hpr2ear} 5 | \title{Convert holding period return to the effective annual rate} 6 | \usage{ 7 | hpr2ear(hpr, t) 8 | } 9 | \arguments{ 10 | \item{hpr}{holding period return} 11 | 12 | \item{t}{number of days remaining until maturity} 13 | } 14 | \description{ 15 | Convert holding period return to the effective annual rate 16 | } 17 | \examples{ 18 | hpr2ear(hpr=0.015228,t=120) 19 | } 20 | \seealso{ 21 | \code{\link{ear}} 22 | 23 | \code{\link{hpr}} 24 | 25 | \code{\link{ear2hpr}} 26 | } 27 | -------------------------------------------------------------------------------- /man/hpr2mmy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hpr2mmy.R 3 | \name{hpr2mmy} 4 | \alias{hpr2mmy} 5 | \title{Computing money market yield (MMY) for a T-bill} 6 | \usage{ 7 | hpr2mmy(hpr, t) 8 | } 9 | \arguments{ 10 | \item{hpr}{holding period return} 11 | 12 | \item{t}{number of days remaining until maturity} 13 | } 14 | \description{ 15 | Computing money market yield (MMY) for a T-bill 16 | } 17 | \examples{ 18 | hpr2mmy(hpr=0.01523,t=120) 19 | } 20 | \seealso{ 21 | \code{\link{hpr}} 22 | 23 | \code{\link{mmy2hpr}} 24 | } 25 | -------------------------------------------------------------------------------- /man/irr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irr.R 3 | \name{irr} 4 | \alias{irr} 5 | \title{Computing IRR, the internal rate of return} 6 | \usage{ 7 | irr(cf) 8 | } 9 | \arguments{ 10 | \item{cf}{cash flow,the first cash flow is the initial outlay} 11 | } 12 | \description{ 13 | Computing IRR, the internal rate of return 14 | } 15 | \examples{ 16 | # irr(cf=c(-5, 1.6, 2.4, 2.8)) 17 | } 18 | \seealso{ 19 | \code{\link{pv.uneven}} 20 | 21 | \code{\link{npv}} 22 | } 23 | -------------------------------------------------------------------------------- /man/irr2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irr2.R 3 | \name{irr2} 4 | \alias{irr2} 5 | \title{Computing IRR, the internal rate of return} 6 | \usage{ 7 | irr2(cf, cutoff = 0.1, from = -1, to = 10, step = 1e-06) 8 | } 9 | \arguments{ 10 | \item{cf}{cash flow,the first cash flow is the initial outlay} 11 | 12 | \item{cutoff}{threshold to take npv as zero} 13 | 14 | \item{from}{smallest irr to try} 15 | 16 | \item{to}{largest irr to try} 17 | 18 | \item{step}{increment of the irr} 19 | } 20 | \description{ 21 | This function is the same as irr but can calculate negative value. This function may take a very long time. You can use larger cutoff and larger step to get a less precision irr first. Then based on the result, change from and to, to narrow down the interval, and use a smaller step to get a more precision irr. 22 | } 23 | \examples{ 24 | # irr2(cf=c(-5, 1.6, 2.4, 2.8)) 25 | # irr2(cf=c(-200, 50, 60, -70, 30, 20)) 26 | } 27 | \seealso{ 28 | \code{\link{irr}} 29 | } 30 | -------------------------------------------------------------------------------- /man/iss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/iss.R 3 | \name{iss} 4 | \alias{iss} 5 | \title{calculate the net increase in common shares from the potential exercise of stock options or warrants} 6 | \usage{ 7 | iss(amp, ep, n) 8 | } 9 | \arguments{ 10 | \item{amp}{average market price over the year} 11 | 12 | \item{ep}{exercise price of the options or warrants} 13 | 14 | \item{n}{number of common shares that the options and warrants can be convened into} 15 | } 16 | \description{ 17 | calculate the net increase in common shares from the potential exercise of stock options or warrants 18 | } 19 | \examples{ 20 | iss(amp=20,ep=15,n=10000) 21 | } 22 | \seealso{ 23 | \code{\link{diluted.EPS}} 24 | } 25 | -------------------------------------------------------------------------------- /man/lineChart.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lineChart.R 3 | \name{lineChart} 4 | \alias{lineChart} 5 | \title{Technical analysts - Line charts: show prices for each period as a continuous line} 6 | \usage{ 7 | lineChart(ohlc, y = "close", main = "", ...) 8 | } 9 | \arguments{ 10 | \item{ohlc}{output from get.ohlc.yahoo or get.ohlc.google} 11 | 12 | \item{y}{y coordinates: close, open, high, low or adjusted (yahoo data only)} 13 | 14 | \item{main}{an overall title for the plot} 15 | 16 | \item{...}{Arguments to be passed to ggplot} 17 | } 18 | \description{ 19 | Technical analysts - Line charts: show prices for each period as a continuous line 20 | } 21 | \examples{ 22 | # google <- get.ohlc.yahoo("GOOG"); lineChart(google) 23 | # apple <- get.ohlc.google("AAPL"); lineChart(apple) 24 | } 25 | \seealso{ 26 | \code{\link{get.ohlc.yahoo}} 27 | 28 | \code{\link{get.ohlc.google}} 29 | } 30 | -------------------------------------------------------------------------------- /man/lineChartMult.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lineChartMult.R 3 | \name{lineChartMult} 4 | \alias{lineChartMult} 5 | \title{Technical analysts - Line charts: show prices for each period as a continuous line for multiple stocks} 6 | \usage{ 7 | lineChartMult(ohlcs, y = "close", main = "", ...) 8 | } 9 | \arguments{ 10 | \item{ohlcs}{output from get.ohlc.yahoo.mult or get.ohlc.google.mult} 11 | 12 | \item{y}{y coordinates: close, open, high, low or adjusted (yahoo data only)} 13 | 14 | \item{main}{an overall title for the plot} 15 | 16 | \item{...}{Arguments to be passed to ggplot} 17 | } 18 | \description{ 19 | Technical analysts - Line charts: show prices for each period as a continuous line for multiple stocks 20 | } 21 | \examples{ 22 | # googapple <- get.ohlcs.yahoo(c("GOOG","AAPL"),start="2013-01-01"); 23 | # lineChartMult(googapple) 24 | # googapple <- get.ohlcs.google(c("GOOG","AAPL"),start="2013-01-01"); 25 | # lineChartMult(googapple) 26 | } 27 | \seealso{ 28 | \code{\link{get.ohlcs.yahoo}} 29 | 30 | \code{\link{get.ohlcs.google}} 31 | 32 | \code{\link{lineChart}} 33 | } 34 | -------------------------------------------------------------------------------- /man/lt.d2e.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt.d2e.R 3 | \name{lt.d2e} 4 | \alias{lt.d2e} 5 | \title{long-term debt-to-equity -- Solvency ratios measure the firm's ability to satisfy its long-term obligations.} 6 | \usage{ 7 | lt.d2e(ltd, te) 8 | } 9 | \arguments{ 10 | \item{ltd}{long-term debt} 11 | 12 | \item{te}{total equity} 13 | } 14 | \description{ 15 | long-term debt-to-equity -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 16 | } 17 | \examples{ 18 | lt.d2e(ltd=8000,te=20000) 19 | } 20 | \seealso{ 21 | \code{\link{total.d2e}} 22 | 23 | \code{\link{debt.ratio}} 24 | 25 | \code{\link{financial.leverage}} 26 | } 27 | -------------------------------------------------------------------------------- /man/mmy2hpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mmy2hpr.R 3 | \name{mmy2hpr} 4 | \alias{mmy2hpr} 5 | \title{Computing HPR, the holding period return} 6 | \usage{ 7 | mmy2hpr(mmy, t) 8 | } 9 | \arguments{ 10 | \item{mmy}{money market yield} 11 | 12 | \item{t}{number of days remaining until maturity} 13 | } 14 | \description{ 15 | Computing HPR, the holding period return 16 | } 17 | \examples{ 18 | mmy2hpr(mmy=0.04898,t=150) 19 | } 20 | \seealso{ 21 | \code{\link{bdy2mmy}} 22 | 23 | \code{\link{hpr2mmy}} 24 | 25 | \code{\link{hpr}} 26 | } 27 | -------------------------------------------------------------------------------- /man/n.period.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/n.period.R 3 | \name{n.period} 4 | \alias{n.period} 5 | \title{Estimate the number of periods} 6 | \usage{ 7 | n.period(r, pv, fv, pmt, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{pv}{present value} 13 | 14 | \item{fv}{future value} 15 | 16 | \item{pmt}{payment per period} 17 | 18 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 19 | } 20 | \description{ 21 | Estimate the number of periods 22 | } 23 | \examples{ 24 | n.period(0.1,-10000,60000000,-50000,0) 25 | 26 | n.period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1) 27 | } 28 | \seealso{ 29 | \code{\link{pv}} 30 | 31 | \code{\link{fv}} 32 | 33 | \code{\link{pmt}} 34 | 35 | \code{\link{discount.rate}} 36 | } 37 | -------------------------------------------------------------------------------- /man/npm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm} 4 | \alias{npm} 5 | \title{net profit margin -- Evaluate a company's financial performance} 6 | \usage{ 7 | npm(ni, rv) 8 | } 9 | \arguments{ 10 | \item{ni}{net income} 11 | 12 | \item{rv}{revenue (sales)} 13 | } 14 | \description{ 15 | net profit margin -- Evaluate a company's financial performance 16 | } 17 | \examples{ 18 | npm(ni=8000,rv=20000) 19 | } 20 | \seealso{ 21 | \code{\link{gpm}} 22 | } 23 | -------------------------------------------------------------------------------- /man/npv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npv.R 3 | \name{npv} 4 | \alias{npv} 5 | \title{Computing NPV, the PV of the cash flows less the initial (time = 0) outlay} 6 | \usage{ 7 | npv(r, cf) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{cf}{cash flow,the first cash flow is the initial outlay} 13 | } 14 | \description{ 15 | Computing NPV, the PV of the cash flows less the initial (time = 0) outlay 16 | } 17 | \examples{ 18 | npv(r=0.12, cf=c(-5, 1.6, 2.4, 2.8)) 19 | } 20 | \seealso{ 21 | \code{\link{pv.simple}} 22 | 23 | \code{\link{pv.uneven}} 24 | 25 | \code{\link{irr}} 26 | } 27 | -------------------------------------------------------------------------------- /man/pmt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pmt.R 3 | \name{pmt} 4 | \alias{pmt} 5 | \title{Estimate period payment} 6 | \usage{ 7 | pmt(r, n, pv, fv, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{pv}{present value} 15 | 16 | \item{fv}{future value} 17 | 18 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 19 | } 20 | \description{ 21 | Estimate period payment 22 | } 23 | \examples{ 24 | pmt(0.08,10,-1000,10) 25 | 26 | pmt(r=0.08,n=10,pv=-1000,fv=0) 27 | 28 | pmt(0.08,10,-1000,10,1) 29 | } 30 | \seealso{ 31 | \code{\link{pv}} 32 | 33 | \code{\link{fv}} 34 | 35 | \code{\link{n.period}} 36 | } 37 | -------------------------------------------------------------------------------- /man/pv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pv.R 3 | \name{pv} 4 | \alias{pv} 5 | \title{Estimate present value (pv)} 6 | \usage{ 7 | pv(r, n, fv = 0, pmt = 0, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{fv}{future value} 15 | 16 | \item{pmt}{payment per period} 17 | 18 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 19 | } 20 | \description{ 21 | Estimate present value (pv) 22 | } 23 | \examples{ 24 | pv(0.07,10,1000,10) 25 | 26 | pv(r=0.05,n=20,fv=1000,pmt=10,type=1) 27 | } 28 | \seealso{ 29 | \code{\link{pv.simple}} 30 | 31 | \code{\link{pv.annuity}} 32 | 33 | \code{\link{fv}} 34 | 35 | \code{\link{pmt}} 36 | 37 | \code{\link{n.period}} 38 | 39 | \code{\link{discount.rate}} 40 | } 41 | -------------------------------------------------------------------------------- /man/pv.annuity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pv.annuity.R 3 | \name{pv.annuity} 4 | \alias{pv.annuity} 5 | \title{Estimate present value (pv) of an annuity} 6 | \usage{ 7 | pv.annuity(r, n, pmt, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{pmt}{payment per period} 15 | 16 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 17 | } 18 | \description{ 19 | Estimate present value (pv) of an annuity 20 | } 21 | \examples{ 22 | pv.annuity(0.03,12,1000) 23 | 24 | pv.annuity(r=0.0425,n=3,pmt=30000) 25 | } 26 | \seealso{ 27 | \code{\link{pv}} 28 | } 29 | -------------------------------------------------------------------------------- /man/pv.perpetuity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pv.perpetuity.R 3 | \name{pv.perpetuity} 4 | \alias{pv.perpetuity} 5 | \title{Estimate present value of a perpetuity} 6 | \usage{ 7 | pv.perpetuity(r, pmt, g = 0, type = 0) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{pmt}{payment per period} 13 | 14 | \item{g}{growth rate of perpetuity} 15 | 16 | \item{type}{payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1)} 17 | } 18 | \description{ 19 | Estimate present value of a perpetuity 20 | } 21 | \examples{ 22 | pv.perpetuity(r=0.1,pmt=1000,g=0.02) 23 | 24 | pv.perpetuity(r=0.1,pmt=1000,type=1) 25 | 26 | pv.perpetuity(r=0.1,pmt=1000) 27 | } 28 | \seealso{ 29 | \code{\link{r.perpetuity}} 30 | } 31 | -------------------------------------------------------------------------------- /man/pv.simple.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pv.simple.R 3 | \name{pv.simple} 4 | \alias{pv.simple} 5 | \title{Estimate present value (pv) of a single sum} 6 | \usage{ 7 | pv.simple(r, n, fv) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{n}{number of periods} 13 | 14 | \item{fv}{future value} 15 | } 16 | \description{ 17 | Estimate present value (pv) of a single sum 18 | } 19 | \examples{ 20 | pv.simple(0.07,10,100) 21 | 22 | pv.simple(r=0.03,n=3,fv=1000) 23 | } 24 | \seealso{ 25 | \code{\link{pv}} 26 | } 27 | -------------------------------------------------------------------------------- /man/pv.uneven.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pv.uneven.R 3 | \name{pv.uneven} 4 | \alias{pv.uneven} 5 | \title{Computing the present value of an uneven cash flow series} 6 | \usage{ 7 | pv.uneven(r, cf) 8 | } 9 | \arguments{ 10 | \item{r}{discount rate, or the interest rate at which the amount will be compounded each period} 11 | 12 | \item{cf}{uneven cash flow} 13 | } 14 | \description{ 15 | Computing the present value of an uneven cash flow series 16 | } 17 | \examples{ 18 | pv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000)) 19 | } 20 | \seealso{ 21 | \code{\link{pv.simple}} 22 | 23 | \code{\link{npv}} 24 | } 25 | -------------------------------------------------------------------------------- /man/quick.ratio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/quick.ratio.R 3 | \name{quick.ratio} 4 | \alias{quick.ratio} 5 | \title{quick ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.} 6 | \usage{ 7 | quick.ratio(cash, ms, rc, cl) 8 | } 9 | \arguments{ 10 | \item{cash}{cash} 11 | 12 | \item{ms}{marketable securities} 13 | 14 | \item{rc}{receivables} 15 | 16 | \item{cl}{current liabilities} 17 | } 18 | \description{ 19 | quick ratio -- Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due. 20 | } 21 | \examples{ 22 | quick.ratio(cash=3000,ms=2000,rc=1000,cl=2000) 23 | } 24 | \seealso{ 25 | \code{\link{current.ratio}} 26 | 27 | \code{\link{cash.ratio}} 28 | } 29 | -------------------------------------------------------------------------------- /man/r.continuous.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/r.continuous.R 3 | \name{r.continuous} 4 | \alias{r.continuous} 5 | \title{Convert a given norminal rate to a continuous compounded rate} 6 | \usage{ 7 | r.continuous(r, m) 8 | } 9 | \arguments{ 10 | \item{r}{norminal rate} 11 | 12 | \item{m}{number of times compounded each year} 13 | } 14 | \description{ 15 | Convert a given norminal rate to a continuous compounded rate 16 | } 17 | \examples{ 18 | r.continuous(0.03,4) 19 | } 20 | \seealso{ 21 | \code{\link{r.norminal}} 22 | } 23 | -------------------------------------------------------------------------------- /man/r.norminal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/r.norminal.R 3 | \name{r.norminal} 4 | \alias{r.norminal} 5 | \title{Convert a given continuous compounded rate to a norminal rate} 6 | \usage{ 7 | r.norminal(rc, m) 8 | } 9 | \arguments{ 10 | \item{rc}{continuous compounded rate} 11 | 12 | \item{m}{number of desired times compounded each year} 13 | } 14 | \description{ 15 | Convert a given continuous compounded rate to a norminal rate 16 | } 17 | \examples{ 18 | r.norminal(0.03,1) 19 | 20 | r.norminal(0.03,4) 21 | } 22 | \seealso{ 23 | \code{\link{r.continuous}} 24 | 25 | \code{\link{ear.continuous}} 26 | } 27 | -------------------------------------------------------------------------------- /man/r.perpetuity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/r.perpetuity.R 3 | \name{r.perpetuity} 4 | \alias{r.perpetuity} 5 | \title{Rate of return for a perpetuity} 6 | \usage{ 7 | r.perpetuity(pmt, pv) 8 | } 9 | \arguments{ 10 | \item{pmt}{payment per period} 11 | 12 | \item{pv}{present value} 13 | } 14 | \description{ 15 | Rate of return for a perpetuity 16 | } 17 | \examples{ 18 | r.perpetuity(pmt=4.5,pv=-75) 19 | } 20 | \seealso{ 21 | \code{\link{pv.perpetuity}} 22 | } 23 | -------------------------------------------------------------------------------- /man/sampling.error.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sampling.error.R 3 | \name{sampling.error} 4 | \alias{sampling.error} 5 | \title{Computing Sampling error} 6 | \usage{ 7 | sampling.error(sm, mu) 8 | } 9 | \arguments{ 10 | \item{sm}{sample mean} 11 | 12 | \item{mu}{population mean} 13 | } 14 | \description{ 15 | Computing Sampling error 16 | } 17 | \examples{ 18 | sampling.error(sm=0.45, mu=0.5) 19 | } 20 | -------------------------------------------------------------------------------- /man/slde.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/slde.R 3 | \name{slde} 4 | \alias{slde} 5 | \title{Depreciation Expense Recognition -- Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life} 6 | \usage{ 7 | slde(cost, rv, t) 8 | } 9 | \arguments{ 10 | \item{cost}{cost of long-lived assets} 11 | 12 | \item{rv}{residual value of the long-lived assets at the end of its useful life} 13 | 14 | \item{t}{length of the useful life} 15 | } 16 | \description{ 17 | Depreciation Expense Recognition -- Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life 18 | } 19 | \examples{ 20 | slde(cost=1200,rv=200,t=5) 21 | } 22 | \seealso{ 23 | \code{\link{ddb}} 24 | } 25 | -------------------------------------------------------------------------------- /man/total.d2e.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/total.d2e.R 3 | \name{total.d2e} 4 | \alias{total.d2e} 5 | \title{total debt-to-equity -- Solvency ratios measure the firm's ability to satisfy its long-term obligations.} 6 | \usage{ 7 | total.d2e(td, te) 8 | } 9 | \arguments{ 10 | \item{td}{total debt} 11 | 12 | \item{te}{total equity} 13 | } 14 | \description{ 15 | total debt-to-equity -- Solvency ratios measure the firm's ability to satisfy its long-term obligations. 16 | } 17 | \examples{ 18 | total.d2e(td=6000,te=20000) 19 | } 20 | \seealso{ 21 | \code{\link{total.d2e}} 22 | 23 | \code{\link{debt.ratio}} 24 | 25 | \code{\link{financial.leverage}} 26 | } 27 | -------------------------------------------------------------------------------- /man/twrr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/twrr.R 3 | \name{twrr} 4 | \alias{twrr} 5 | \title{Computing TWRR, the time-weighted rate of return} 6 | \usage{ 7 | twrr(ev, bv, cfr) 8 | } 9 | \arguments{ 10 | \item{ev}{ordered ending value list} 11 | 12 | \item{bv}{ordered beginning value list} 13 | 14 | \item{cfr}{ordered cash flow received list} 15 | } 16 | \description{ 17 | Computing TWRR, the time-weighted rate of return 18 | } 19 | \examples{ 20 | twrr(ev=c(120,260),bv=c(100,240),cfr=c(2,4)) 21 | } 22 | \seealso{ 23 | \code{\link{hpr}} 24 | } 25 | -------------------------------------------------------------------------------- /man/volumeChart.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/volumeChart.R 3 | \name{volumeChart} 4 | \alias{volumeChart} 5 | \title{Technical analysts - Volume charts: show each period's volume as a vertical line} 6 | \usage{ 7 | volumeChart(ohlc, main = "", ...) 8 | } 9 | \arguments{ 10 | \item{ohlc}{output from get.ohlc.yahoo or get.ohlc.google} 11 | 12 | \item{main}{an overall title for the plot} 13 | 14 | \item{...}{Arguments to be passed to ggplot} 15 | } 16 | \description{ 17 | Technical analysts - Volume charts: show each period's volume as a vertical line 18 | } 19 | \examples{ 20 | # google <- get.ohlc.yahoo("GOOG"); 21 | # volumeChart(google) 22 | # apple <- get.ohlc.google("AAPL"); 23 | # volumeChart(apple) 24 | } 25 | \seealso{ 26 | \code{\link{get.ohlc.yahoo}} 27 | 28 | \code{\link{get.ohlc.google}} 29 | } 30 | -------------------------------------------------------------------------------- /man/was.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/was.R 3 | \name{was} 4 | \alias{was} 5 | \title{calculate weighted average shares -- weighted average number of common shares} 6 | \usage{ 7 | was(ns, nm) 8 | } 9 | \arguments{ 10 | \item{ns}{n x 1 vector vector of number of shares} 11 | 12 | \item{nm}{n x 1 vector vector of number of months relate to ns} 13 | } 14 | \description{ 15 | calculate weighted average shares -- weighted average number of common shares 16 | } 17 | \examples{ 18 | s=c(10000,2000);m=c(12,6);was(ns=s,nm=m) 19 | 20 | s=c(11000,4400,-3000);m=c(12,9,4);was(ns=s,nm=m) 21 | } 22 | \seealso{ 23 | \code{\link{EPS}} 24 | 25 | \code{\link{diluted.EPS}} 26 | } 27 | -------------------------------------------------------------------------------- /man/wpr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wpr.R 3 | \name{wpr} 4 | \alias{wpr} 5 | \title{Weighted mean as a portfolio return} 6 | \usage{ 7 | wpr(r, w) 8 | } 9 | \arguments{ 10 | \item{r}{returns of the individual assets in the portfolio} 11 | 12 | \item{w}{corresponding weights associated with each of the individual assets} 13 | } 14 | \description{ 15 | Weighted mean as a portfolio return 16 | } 17 | \examples{ 18 | wpr(r=c(0.12, 0.07, 0.03),w=c(0.5,0.4,0.1)) 19 | } 20 | --------------------------------------------------------------------------------