Application Center - Maplesoft

App Preview:

Downloading Stock Prices and Plotting Returns Distributions

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application




Downloading Stock Prices and

Plotting Returns Distributions

Introduction

This application

 

• 

   downloads historical stock prices from Yahoo Finance,

• 

   calculates the returns,

• 

   plots the distribution of the returns in a histogram,

• 

   and overlays a normal distribution with the same mean and standard deviation as the historical data.

 

The application uses Maple 18's improved Internet connectivity; you can now download data from a URL straight into a matrix using ImportMatrix() .

with(LinearAlgebra):

Ticker, Dates and Frequency

ticker := "XOM":

startDay := "25":

endDay := "25":

frequency := "d":

Download Historical Stock Quotes and Calculate Returns

url := cat("http://ichart.finance.yahoo.com/table.csv?s=", ticker, "&a=", startMonth, "&b=", startDay, "&c=", startYear, "&d=", endMonth, "&e=", endDay, "&f=", endYear, "&g=",frequency,"&ignore=.csv"):

data := ImportMatrix(url):

nRows := RowDimension(data)-2:

returns := Vector(nRows, proc (i) options operator, arrow; evalf(ln(data[i+2, 7]/data[i+1, 7])) end proc):

p1 := Histogram(returns, frequencyscale = relative, color = "SteelBlue", axes = boxed, gridlines):

Plot Histogram and Overlay Normal Distribution

av := Mean(returns);

HFloat(-6.28458979559889e-4)

(4.1)

stdev := StandardDeviation(returns);

HFloat(0.011406382150493648)

(4.2)

n := Normal(av, stdev):

p2 := DensityPlot(Normal(av, stdev), range = min(returns) .. max(returns)):

display(p1, p2)

NULL