Title: | Time Value of Money, Time Series Analysis and Computational Finance |
---|---|
Description: | Package for time value of money calculation, time series analysis and computational finance. |
Authors: | Felix Yanhui Fan <[email protected]> |
Maintainer: | Felix Yanhui Fan <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.6.4 |
Built: | 2024-10-29 04:16:30 UTC |
Source: | https://github.com/felixfan/fincal |
Computing bank discount yield (BDY) for a T-bill
bdy(d, f, t)
bdy(d, f, t)
d |
the dollar discount, which is equal to the difference between the face value of the bill and the purchase price |
f |
the face value (par value) of the bill |
t |
number of days remaining until maturity |
bdy(d=1500,f=100000,t=120)
bdy(d=1500,f=100000,t=120)
Computing money market yield (MMY) for a T-bill
bdy2mmy(bdy, t)
bdy2mmy(bdy, t)
bdy |
bank discount yield |
t |
number of days remaining until maturity |
bdy2mmy(bdy=0.045,t=120)
bdy2mmy(bdy=0.045,t=120)
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.
candlestickChart(ohlc, start = NULL, end = NULL, main = "", ...)
candlestickChart(ohlc, start = NULL, end = NULL, main = "", ...)
ohlc |
output from get.ohlc.yahoo or get.ohlc.google |
start |
start date to plot, if not specified, all date in ohlc will be included |
end |
end date to plot |
main |
an overall title for the plot |
... |
Arguments to be passed to ggplot |
# google <- get.ohlc.yahoo("GOOG",start="2013-07-01",end="2013-08-01"); candlestickChart(google) # apple <- get.ohlc.google("AAPL",start="2013-07-01",end="2013-08-01"); candlestickChart(apple)
# google <- get.ohlc.yahoo("GOOG",start="2013-07-01",end="2013-08-01"); candlestickChart(google) # apple <- get.ohlc.google("AAPL",start="2013-07-01",end="2013-08-01"); candlestickChart(apple)
cash ratio – Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
cash.ratio(cash, ms, cl)
cash.ratio(cash, ms, cl)
cash |
cash |
ms |
marketable securities |
cl |
current liabilities |
cash.ratio(cash=3000,ms=2000,cl=2000)
cash.ratio(cash=3000,ms=2000,cl=2000)
Computing Coefficient of variation
coefficient.variation(sd, avg)
coefficient.variation(sd, avg)
sd |
standard deviation |
avg |
average value |
coefficient.variation(sd=0.15,avg=0.39)
coefficient.variation(sd=0.15,avg=0.39)
Cost of goods sold and ending inventory under three methods (FIFO,LIFO,Weighted average)
cogs(uinv, pinv, units, price, sinv, method = "FIFO")
cogs(uinv, pinv, units, price, sinv, method = "FIFO")
uinv |
units of beginning inventory |
pinv |
prince of beginning inventory |
units |
nx1 vector of inventory units. inventory purchased ordered by time (from first to last) |
price |
nx1 vector of inventory price. same order as units |
sinv |
units of sold inventory |
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) |
cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="FIFO") cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="LIFO") cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="WAC")
cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="FIFO") cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="LIFO") cogs(uinv=2,pinv=2,units=c(3,5),price=c(3,5),sinv=7,method="WAC")
current ratio – Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
current.ratio(ca, cl)
current.ratio(ca, cl)
ca |
current assets |
cl |
current liabilities |
current.ratio(ca=8000,cl=2000)
current.ratio(ca=8000,cl=2000)
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.
ddb(cost, rv, t)
ddb(cost, rv, t)
cost |
cost of long-lived assets |
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. |
t |
length of the useful life |
ddb(cost=1200,rv=200,t=5)
ddb(cost=1200,rv=200,t=5)
debt ratio – Solvency ratios measure the firm's ability to satisfy its long-term obligations.
debt.ratio(td, ta)
debt.ratio(td, ta)
td |
total debt |
ta |
total assets |
debt.ratio(td=6000,ta=20000)
debt.ratio(td=6000,ta=20000)
diluted Earnings Per Share
diluted.EPS(ni, pd, cpd = 0, cdi = 0, tax = 0, w, cps = 0, cds = 0, iss = 0)
diluted.EPS(ni, pd, cpd = 0, cdi = 0, tax = 0, w, cps = 0, cds = 0, iss = 0)
ni |
net income |
pd |
preferred dividends |
cpd |
dividends on convertible preferred stock |
cdi |
interest on convertible debt |
tax |
tax rate |
w |
weighted average number of common shares outstanding |
cps |
shares from conversion of convertible preferred stock |
cds |
shares from conversion of convertible debt |
iss |
shares issuable from stock options |
diluted.EPS(ni=115600,pd=10000,cdi=42000,tax=0.4,w=200000,cds=60000) diluted.EPS(ni=115600,pd=10000,cpd=10000,w=200000,cps=40000) diluted.EPS(ni=115600,pd=10000,w=200000,iss=2500) diluted.EPS(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000,cps=40000,cds=60000,iss=2500)
diluted.EPS(ni=115600,pd=10000,cdi=42000,tax=0.4,w=200000,cds=60000) diluted.EPS(ni=115600,pd=10000,cpd=10000,w=200000,cps=40000) diluted.EPS(ni=115600,pd=10000,w=200000,iss=2500) diluted.EPS(ni=115600,pd=10000,cpd=10000,cdi=42000,tax=0.4,w=200000,cps=40000,cds=60000,iss=2500)
Computing the rate of return for each period
discount.rate(n, pv, fv, pmt, type = 0, lower = 1e-04, upper = 100)
discount.rate(n, pv, fv, pmt, type = 0, lower = 1e-04, upper = 100)
n |
number of periods |
pv |
present value |
fv |
future value |
pmt |
payment per period |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
lower |
the lower end points of the rate of return to be searched. |
upper |
the upper end points of the rate of return to be searched. |
discount.rate(n=5,pv=0,fv=600,pmt=-100,type=0)
discount.rate(n=5,pv=0,fv=600,pmt=-100,type=0)
Convert stated annual rate to the effective annual rate
ear(r, m)
ear(r, m)
r |
stated annual rate |
m |
number of compounding periods per year |
ear(r=0.12,m=12) ear(0.04,365)
ear(r=0.12,m=12) ear(0.04,365)
Convert stated annual rate to the effective annual rate with continuous compounding
ear.continuous(r)
ear.continuous(r)
r |
stated annual rate |
ear.continuous(r=0.1) ear.continuous(0.03)
ear.continuous(r=0.1) ear.continuous(0.03)
bond-equivalent yield (BEY), 2 x the semiannual discount rate
ear2bey(ear)
ear2bey(ear)
ear |
effective annual rate |
ear2bey(ear=0.08)
ear2bey(ear=0.08)
Computing HPR, the holding period return
ear2hpr(ear, t)
ear2hpr(ear, t)
ear |
effective annual rate |
t |
number of days remaining until maturity |
ear2hpr(ear=0.05039,t=150)
ear2hpr(ear=0.05039,t=150)
An interest rate to be applied n times p.a. can be converted to an equivalent rate to be applied p times p.a.
EIR(r, n = 1, p = 12, type = c("e", "p"))
EIR(r, n = 1, p = 12, type = c("e", "p"))
r |
interest rate to be applied n times per year (r is annual rate!) |
n |
times that the interest rate r were compounded per year |
p |
times that the equivalent rate were compounded per year |
type |
equivalent interest rates ('e',default) or proportional interest rates ('p') |
# monthly interest rat equivalent to 5% compounded per year EIR(r=0.05,n=1,p=12) # monthly interest rat equivalent to 5% compounded per half year EIR(r=0.05,n=2,p=12) # monthly interest rat equivalent to 5% compounded per quarter EIR(r=0.05,n=4,p=12) # annual interest rate equivalent to 5% compounded per month EIR(r=0.05,n=12,p=1) # this is equivalent to ear(r=0.05,m=12) # quarter interest rate equivalent to 5% compounded per year EIR(r=0.05,n=1,p=4) # quarter interest rate equivalent to 5% compounded per month EIR(r=0.05,n=12,p=4) # monthly proportional interest rate which is equivalent to a simple annual interest EIR(r=0.05,p=12,type='p')
# monthly interest rat equivalent to 5% compounded per year EIR(r=0.05,n=1,p=12) # monthly interest rat equivalent to 5% compounded per half year EIR(r=0.05,n=2,p=12) # monthly interest rat equivalent to 5% compounded per quarter EIR(r=0.05,n=4,p=12) # annual interest rate equivalent to 5% compounded per month EIR(r=0.05,n=12,p=1) # this is equivalent to ear(r=0.05,m=12) # quarter interest rate equivalent to 5% compounded per year EIR(r=0.05,n=1,p=4) # quarter interest rate equivalent to 5% compounded per month EIR(r=0.05,n=12,p=4) # monthly proportional interest rate which is equivalent to a simple annual interest EIR(r=0.05,p=12,type='p')
Basic Earnings Per Share
EPS(ni, pd, w)
EPS(ni, pd, w)
ni |
net income |
pd |
preferred dividends |
w |
weighted average number of common shares outstanding |
EPS(ni=10000,pd=1000,w=11000)
EPS(ni=10000,pd=1000,w=11000)
financial leverage – Solvency ratios measure the firm's ability to satisfy its long-term obligations.
financial.leverage(te, ta)
financial.leverage(te, ta)
te |
total equity |
ta |
total assets |
financial.leverage(te=16000,ta=20000)
financial.leverage(te=16000,ta=20000)
Estimate future value (fv)
fv(r, n, pv = 0, pmt = 0, type = 0)
fv(r, n, pv = 0, pmt = 0, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
pv |
present value |
pmt |
payment per period |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
fv(0.07,10,1000,10)
fv(0.07,10,1000,10)
Estimate future value of an annuity
fv.annuity(r, n, pmt, type = 0)
fv.annuity(r, n, pmt, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
pmt |
payment per period |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
fv.annuity(0.03,12,-1000) fv.annuity(r=0.03,n=12,pmt=-1000,type=1)
fv.annuity(0.03,12,-1000) fv.annuity(r=0.03,n=12,pmt=-1000,type=1)
Estimate future value (fv) of a single sum
fv.simple(r, n, pv)
fv.simple(r, n, pv)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
pv |
present value |
fv.simple(0.08,10,-300) fv.simple(r=0.04,n=20,pv=-50000)
fv.simple(0.08,10,-300) fv.simple(r=0.04,n=20,pv=-50000)
Computing the future value of an uneven cash flow series
fv.uneven(r, cf)
fv.uneven(r, cf)
r |
stated annual rate |
cf |
uneven cash flow |
fv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000))
fv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000))
Geometric mean return
geometric.mean(r)
geometric.mean(r)
r |
returns over multiple periods |
geometric.mean(r=c(-0.0934, 0.2345, 0.0892))
geometric.mean(r=c(-0.0934, 0.2345, 0.0892))
Download stock prices from Google Finance (open, high, low, close, volume)
get.ohlc.google(symbol, start = "2013-01-01", end = "today")
get.ohlc.google(symbol, start = "2013-01-01", end = "today")
symbol |
symbol of stock, e.g. AAPL, GOOG, SPX |
start |
start date, e.g., 2013-07-31 |
end |
end date, e.g., 2013-08-06 |
# get.ohlc.google(symbol="AAPL") # get.ohlc.google(symbol="AAPL",start="2013-08-01") # get.ohlc.google(symbol="AAPL",start="2013-07-01",end="2013-08-01")
# get.ohlc.google(symbol="AAPL") # get.ohlc.google(symbol="AAPL",start="2013-08-01") # get.ohlc.google(symbol="AAPL",start="2013-07-01",end="2013-08-01")
Download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted)
get.ohlc.yahoo(symbol, start = "firstDay", end = "today", freq = "d")
get.ohlc.yahoo(symbol, start = "firstDay", end = "today", freq = "d")
symbol |
symbol of stock, e.g. AAPL, GOOG, SPX |
start |
start date, e.g., 2013-07-31 |
end |
end date, e.g., 2013-08-06 |
freq |
time interval, e.g., d:daily, w:weekly, m:monthly |
# get.ohlc.yahoo(symbol="AAPL") # get.ohlc.yahoo(symbol="AAPL",start="2013-08-01",freq="d") # get.ohlc.yahoo(symbol="AAPL",start="2013-07-01",end="2013-08-01",freq="w")
# get.ohlc.yahoo(symbol="AAPL") # get.ohlc.yahoo(symbol="AAPL",start="2013-08-01",freq="d") # get.ohlc.yahoo(symbol="AAPL",start="2013-07-01",end="2013-08-01",freq="w")
Batch download stock prices from Google Finance (open, high, low, close, volume)
get.ohlcs.google(symbols, start = "2013-01-01", end = "today")
get.ohlcs.google(symbols, start = "2013-01-01", end = "today")
symbols |
symbols of stock, e.g. AAPL, GOOG, SPX |
start |
start date, e.g., 2013-07-31 |
end |
end date, e.g., 2013-08-06 |
# get.ohlcs.google(symbols=c("AAPL","GOOG","SPY")) # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01") # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",end="2013-07-31")
# get.ohlcs.google(symbols=c("AAPL","GOOG","SPY")) # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01") # get.ohlcs.google(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",end="2013-07-31")
Batch download stock prices from Yahoo Finance (open, high, low, close, volume, adjusted)
get.ohlcs.yahoo(symbols, start = "firstDay", end = "today", freq = "d")
get.ohlcs.yahoo(symbols, start = "firstDay", end = "today", freq = "d")
symbols |
symbols of stock, e.g. AAPL, GOOG, SPX |
start |
start date, e.g., 2013-07-31 |
end |
end date, e.g., 2013-08-06 |
freq |
time interval, e.g., d:daily, w:weekly, m:monthly |
# get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),freq="d") # get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",freq="m")
# get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),freq="d") # get.ohlcs.yahoo(symbols=c("AAPL","GOOG","SPY"),start="2013-01-01",freq="m")
gross profit margin – Evaluate a company's financial performance
gpm(gp, rv)
gpm(gp, rv)
gp |
gross profit, equal to revenue minus cost of goods sold (cogs) |
rv |
revenue (sales) |
gpm(gp=1000,rv=20000)
gpm(gp=1000,rv=20000)
harmonic mean, average price
harmonic.mean(p)
harmonic.mean(p)
p |
price over multiple periods |
harmonic.mean(p=c(8,9,10))
harmonic.mean(p=c(8,9,10))
Computing HPR, the holding period return
hpr(ev, bv, cfr = 0)
hpr(ev, bv, cfr = 0)
ev |
ending value |
bv |
beginning value |
cfr |
cash flow received |
hpr(ev=33,bv=30,cfr=0.5)
hpr(ev=33,bv=30,cfr=0.5)
bond-equivalent yield (BEY), 2 x the semiannual discount rate
hpr2bey(hpr, t)
hpr2bey(hpr, t)
hpr |
holding period return |
t |
number of month remaining until maturity |
hpr2bey(hpr=0.02,t=3)
hpr2bey(hpr=0.02,t=3)
Convert holding period return to the effective annual rate
hpr2ear(hpr, t)
hpr2ear(hpr, t)
hpr |
holding period return |
t |
number of days remaining until maturity |
hpr2ear(hpr=0.015228,t=120)
hpr2ear(hpr=0.015228,t=120)
Computing money market yield (MMY) for a T-bill
hpr2mmy(hpr, t)
hpr2mmy(hpr, t)
hpr |
holding period return |
t |
number of days remaining until maturity |
hpr2mmy(hpr=0.01523,t=120)
hpr2mmy(hpr=0.01523,t=120)
Computing IRR, the internal rate of return
irr(cf)
irr(cf)
cf |
cash flow,the first cash flow is the initial outlay |
# irr(cf=c(-5, 1.6, 2.4, 2.8))
# irr(cf=c(-5, 1.6, 2.4, 2.8))
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.
irr2(cf, cutoff = 0.1, from = -1, to = 10, step = 1e-06)
irr2(cf, cutoff = 0.1, from = -1, to = 10, step = 1e-06)
cf |
cash flow,the first cash flow is the initial outlay |
cutoff |
threshold to take npv as zero |
from |
smallest irr to try |
to |
largest irr to try |
step |
increment of the irr |
# irr2(cf=c(-5, 1.6, 2.4, 2.8)) # irr2(cf=c(-200, 50, 60, -70, 30, 20))
# irr2(cf=c(-5, 1.6, 2.4, 2.8)) # irr2(cf=c(-200, 50, 60, -70, 30, 20))
calculate the net increase in common shares from the potential exercise of stock options or warrants
iss(amp, ep, n)
iss(amp, ep, n)
amp |
average market price over the year |
ep |
exercise price of the options or warrants |
n |
number of common shares that the options and warrants can be convened into |
iss(amp=20,ep=15,n=10000)
iss(amp=20,ep=15,n=10000)
Technical analysts - Line charts: show prices for each period as a continuous line
lineChart(ohlc, y = "close", main = "", ...)
lineChart(ohlc, y = "close", main = "", ...)
ohlc |
output from get.ohlc.yahoo or get.ohlc.google |
y |
y coordinates: close, open, high, low or adjusted (yahoo data only) |
main |
an overall title for the plot |
... |
Arguments to be passed to ggplot |
# google <- get.ohlc.yahoo("GOOG"); lineChart(google) # apple <- get.ohlc.google("AAPL"); lineChart(apple)
# google <- get.ohlc.yahoo("GOOG"); lineChart(google) # apple <- get.ohlc.google("AAPL"); lineChart(apple)
Technical analysts - Line charts: show prices for each period as a continuous line for multiple stocks
lineChartMult(ohlcs, y = "close", main = "", ...)
lineChartMult(ohlcs, y = "close", main = "", ...)
ohlcs |
output from get.ohlc.yahoo.mult or get.ohlc.google.mult |
y |
y coordinates: close, open, high, low or adjusted (yahoo data only) |
main |
an overall title for the plot |
... |
Arguments to be passed to ggplot |
# googapple <- get.ohlcs.yahoo(c("GOOG","AAPL"),start="2013-01-01"); # lineChartMult(googapple) # googapple <- get.ohlcs.google(c("GOOG","AAPL"),start="2013-01-01"); # lineChartMult(googapple)
# googapple <- get.ohlcs.yahoo(c("GOOG","AAPL"),start="2013-01-01"); # lineChartMult(googapple) # googapple <- get.ohlcs.google(c("GOOG","AAPL"),start="2013-01-01"); # lineChartMult(googapple)
long-term debt-to-equity – Solvency ratios measure the firm's ability to satisfy its long-term obligations.
lt.d2e(ltd, te)
lt.d2e(ltd, te)
ltd |
long-term debt |
te |
total equity |
lt.d2e(ltd=8000,te=20000)
lt.d2e(ltd=8000,te=20000)
Computing HPR, the holding period return
mmy2hpr(mmy, t)
mmy2hpr(mmy, t)
mmy |
money market yield |
t |
number of days remaining until maturity |
mmy2hpr(mmy=0.04898,t=150)
mmy2hpr(mmy=0.04898,t=150)
Estimate the number of periods
n.period(r, pv, fv, pmt, type = 0)
n.period(r, pv, fv, pmt, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
pv |
present value |
fv |
future value |
pmt |
payment per period |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
n.period(0.1,-10000,60000000,-50000,0) n.period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1)
n.period(0.1,-10000,60000000,-50000,0) n.period(r=0.1,pv=-10000,fv=60000000,pmt=-50000,type=1)
net profit margin – Evaluate a company's financial performance
npm(ni, rv)
npm(ni, rv)
ni |
net income |
rv |
revenue (sales) |
npm(ni=8000,rv=20000)
npm(ni=8000,rv=20000)
Computing NPV, the PV of the cash flows less the initial (time = 0) outlay
npv(r, cf)
npv(r, cf)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
cf |
cash flow,the first cash flow is the initial outlay |
npv(r=0.12, cf=c(-5, 1.6, 2.4, 2.8))
npv(r=0.12, cf=c(-5, 1.6, 2.4, 2.8))
Estimate period payment
pmt(r, n, pv, fv, type = 0)
pmt(r, n, pv, fv, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
pv |
present value |
fv |
future value |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
pmt(0.08,10,-1000,10) pmt(r=0.08,n=10,pv=-1000,fv=0) pmt(0.08,10,-1000,10,1)
pmt(0.08,10,-1000,10) pmt(r=0.08,n=10,pv=-1000,fv=0) pmt(0.08,10,-1000,10,1)
Estimate present value (pv)
pv(r, n, fv = 0, pmt = 0, type = 0)
pv(r, n, fv = 0, pmt = 0, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
fv |
future value |
pmt |
payment per period |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
pv(0.07,10,1000,10) pv(r=0.05,n=20,fv=1000,pmt=10,type=1)
pv(0.07,10,1000,10) pv(r=0.05,n=20,fv=1000,pmt=10,type=1)
Estimate present value (pv) of an annuity
pv.annuity(r, n, pmt, type = 0)
pv.annuity(r, n, pmt, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
pmt |
payment per period |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
pv.annuity(0.03,12,1000) pv.annuity(r=0.0425,n=3,pmt=30000)
pv.annuity(0.03,12,1000) pv.annuity(r=0.0425,n=3,pmt=30000)
Estimate present value of a perpetuity
pv.perpetuity(r, pmt, g = 0, type = 0)
pv.perpetuity(r, pmt, g = 0, type = 0)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
pmt |
payment per period |
g |
growth rate of perpetuity |
type |
payments occur at the end of each period (type=0); payments occur at the beginning of each period (type=1) |
pv.perpetuity(r=0.1,pmt=1000,g=0.02) pv.perpetuity(r=0.1,pmt=1000,type=1) pv.perpetuity(r=0.1,pmt=1000)
pv.perpetuity(r=0.1,pmt=1000,g=0.02) pv.perpetuity(r=0.1,pmt=1000,type=1) pv.perpetuity(r=0.1,pmt=1000)
Estimate present value (pv) of a single sum
pv.simple(r, n, fv)
pv.simple(r, n, fv)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
n |
number of periods |
fv |
future value |
pv.simple(0.07,10,100) pv.simple(r=0.03,n=3,fv=1000)
pv.simple(0.07,10,100) pv.simple(r=0.03,n=3,fv=1000)
Computing the present value of an uneven cash flow series
pv.uneven(r, cf)
pv.uneven(r, cf)
r |
discount rate, or the interest rate at which the amount will be compounded each period |
cf |
uneven cash flow |
pv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000))
pv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000))
quick ratio – Liquidity ratios measure the firm's ability to satisfy its short-term obligations as they come due.
quick.ratio(cash, ms, rc, cl)
quick.ratio(cash, ms, rc, cl)
cash |
cash |
ms |
marketable securities |
rc |
receivables |
cl |
current liabilities |
quick.ratio(cash=3000,ms=2000,rc=1000,cl=2000)
quick.ratio(cash=3000,ms=2000,rc=1000,cl=2000)
Convert a given norminal rate to a continuous compounded rate
r.continuous(r, m)
r.continuous(r, m)
r |
norminal rate |
m |
number of times compounded each year |
r.continuous(0.03,4)
r.continuous(0.03,4)
Convert a given continuous compounded rate to a norminal rate
r.norminal(rc, m)
r.norminal(rc, m)
rc |
continuous compounded rate |
m |
number of desired times compounded each year |
r.norminal(0.03,1) r.norminal(0.03,4)
r.norminal(0.03,1) r.norminal(0.03,4)
Rate of return for a perpetuity
r.perpetuity(pmt, pv)
r.perpetuity(pmt, pv)
pmt |
payment per period |
pv |
present value |
r.perpetuity(pmt=4.5,pv=-75)
r.perpetuity(pmt=4.5,pv=-75)
Computing Sampling error
sampling.error(sm, mu)
sampling.error(sm, mu)
sm |
sample mean |
mu |
population mean |
sampling.error(sm=0.45, mu=0.5)
sampling.error(sm=0.45, mu=0.5)
Computing Roy's safety-first ratio
SFRatio(rp, rl, sd)
SFRatio(rp, rl, sd)
rp |
portfolio return |
rl |
threshold level return |
sd |
standard deviation of portfolio retwns |
SFRatio(rp=0.09,rl=0.03,sd=0.12)
SFRatio(rp=0.09,rl=0.03,sd=0.12)
Computing Sharpe Ratio
Sharpe.ratio(rp, rf, sd)
Sharpe.ratio(rp, rf, sd)
rp |
portfolio return |
rf |
risk-free return |
sd |
standard deviation of portfolio retwns |
Sharpe.ratio(rp=0.038,rf=0.015,sd=0.07)
Sharpe.ratio(rp=0.038,rf=0.015,sd=0.07)
Depreciation Expense Recognition – Straight-line depreciation (SL) allocates an equal amount of depreciation each year over the asset's useful life
slde(cost, rv, t)
slde(cost, rv, t)
cost |
cost of long-lived assets |
rv |
residual value of the long-lived assets at the end of its useful life |
t |
length of the useful life |
slde(cost=1200,rv=200,t=5)
slde(cost=1200,rv=200,t=5)
total debt-to-equity – Solvency ratios measure the firm's ability to satisfy its long-term obligations.
total.d2e(td, te)
total.d2e(td, te)
td |
total debt |
te |
total equity |
total.d2e(td=6000,te=20000)
total.d2e(td=6000,te=20000)
Computing TWRR, the time-weighted rate of return
twrr(ev, bv, cfr)
twrr(ev, bv, cfr)
ev |
ordered ending value list |
bv |
ordered beginning value list |
cfr |
ordered cash flow received list |
twrr(ev=c(120,260),bv=c(100,240),cfr=c(2,4))
twrr(ev=c(120,260),bv=c(100,240),cfr=c(2,4))
Technical analysts - Volume charts: show each period's volume as a vertical line
volumeChart(ohlc, main = "", ...)
volumeChart(ohlc, main = "", ...)
ohlc |
output from get.ohlc.yahoo or get.ohlc.google |
main |
an overall title for the plot |
... |
Arguments to be passed to ggplot |
# google <- get.ohlc.yahoo("GOOG"); # volumeChart(google) # apple <- get.ohlc.google("AAPL"); # volumeChart(apple)
# google <- get.ohlc.yahoo("GOOG"); # volumeChart(google) # apple <- get.ohlc.google("AAPL"); # volumeChart(apple)
calculate weighted average shares – weighted average number of common shares
was(ns, nm)
was(ns, nm)
ns |
n x 1 vector vector of number of shares |
nm |
n x 1 vector vector of number of months relate to ns |
s=c(10000,2000);m=c(12,6);was(ns=s,nm=m) s=c(11000,4400,-3000);m=c(12,9,4);was(ns=s,nm=m)
s=c(10000,2000);m=c(12,6);was(ns=s,nm=m) s=c(11000,4400,-3000);m=c(12,9,4);was(ns=s,nm=m)
Weighted mean as a portfolio return
wpr(r, w)
wpr(r, w)
r |
returns of the individual assets in the portfolio |
w |
corresponding weights associated with each of the individual assets |
wpr(r=c(0.12, 0.07, 0.03),w=c(0.5,0.4,0.1))
wpr(r=c(0.12, 0.07, 0.03),w=c(0.5,0.4,0.1))