In recent years most banks are pushing their customers to invest in Funds with the argument that this is more profitable then any other option. As always it is valid to question this statement.
As an compelling argument the follwing chart is presented which shows indeed that the stock market was growing.
Before we start we get the dependencies and import the necessary packages
%classpath config resolver maven-public1 http://nuc.local:8081/repository/maven-public/
%%classpath add mvn
ch.pschatzmann:investor:0.9-SNAPSHOT
ch.pschatzmann:jupyter-jdk-extensions:0.0.1-SNAPSHOT
org.apache.commons:commons-math3:LATEST
import ch.pschatzmann.stocks.data.index.SP500Index
import ch.pschatzmann.stocks._
import ch.pschatzmann.display.Table
import java.util.List
import org.apache.commons.math3.stat.StatUtils
import java.util.Random
import ch.pschatzmann.stocks.data.index.SP500Index import ch.pschatzmann.stocks._ import ch.pschatzmann.display.Table import java.util.List import org.apache.commons.math3.stat.StatUtils import java.util.Random
Here is a plot of the SP500 index:
var sd = Context.getStockData(new SP500Index().getStockID())
var table = Table.create(sd)
new SimpleTimePlot {
data = table.seq()
columns = Seq("^GSPC.Closing")
showLegend = false
}
The clue if an investoment is profitable all depends on when you invested and the time horizon!
So I was asking myself: what's the average profit (or loss) you would have - let's say over a period of the last 18 years. In order to calculate this, we generate random start and end days and we calculate the average profit over all generated samples.
In our simulation we invest 10'000 USD (and assume that this can be done in fractions).
def getRandomProfit(investmentAmount:Double, history:List[IStockRecord]):Double = {
var size = history.size()
var r = new Random();
var startIndex = r.nextInt(size)
var endIndex = r.nextInt(size - startIndex) + startIndex
var qty = investmentAmount / history.get(startIndex).getClosing().doubleValue()
var buy = history.get(startIndex).getClosing().doubleValue
var sell = history.get(endIndex).getClosing().doubleValue
return qty * (sell - buy)
}
var investmentAmount = 10000.0
var history = Context.getStockData(new SP500Index().getStockID()).getHistory(Context.date("2000-01-01"))
var profits = (1 to 1000000).map(i => getRandomProfit(investmentAmount, history)).toArray
var avg = StatUtils.mean(profits)
var max = StatUtils.max(profits)
var min = StatUtils.min(profits)
var percent = avg / investmentAmount * 100
s"Profit %: $percent - avg: $avg ( min: $min / max: $max )"
Profit %: 36.33501080413464 - avg: 3633.5010804134636 ( min: -5656.558890544368 / max: 32983.30933363491 )
So it seems to be true. In avarage you would have had a profit of 36 % over roughly 10 year - which gives an annual profitability of around 3%. The worst simulaiton example was loosing 5600 USD and the best example was gaining 33000 - which would have tripled your fortune.
In a nutshell - in average it was paying off to be invested but it all depends on your timing so you could have ended up with a loss. The average annual profitibility is not very thrilling and you will need to compare this with your other investment options!