Return on Investment. Return on investment (ROI) is often stated on an annual
basis. If you buy and sell stock over shorter or longer periods of
time, the ROI must be adjusted to be a full year's time period.
The basic calculation is as follows:
Given the sale date, purchase date, sale price,
sp
, and purchase price,
pp
.
Compute the period the asset was held: use
time.mktime
to create floating point time
values for sale date, s
, and purchase date,
p
. The weighting, w
, is
computed as
w
= (86400*365.2425) /
(s
-p
)
Write a program to compute ROI for some fictitious stock
holdings. Be sure to include stocks held both more than one year and
less than one year. See the section called “Stock Valuation” in Chapter 21, Classes
for some additional information on this
kind of calculation.