In [1]:
using PyPlot
using Dates
using YahooFinanceAPI


INFO: Loading help data...

In [30]:
startDate = Date(2000,1,1)
sym = "^GSPC";
data = fetchHistoricalData("$sym", startDate);

In [31]:
#compute the N-day trailing average
lag = 50;
ma = zeros(length(data.adjusted_close)-lag)
for i = lag+1:length(data.adjusted_close)
    sum = 0
    for j = 1:lag
        sum += data.adjusted_close[i-j]
    end
    ma[i-lag] = sum/lag;
end

Basic Plotting


In [32]:
plot(data.dates,data.adjusted_close,"b-")
plot(data.dates[lag+1:end], ma, "r-")
legend(["$sym", "$sym MA$(lag)"])


Out[32]:
PyObject <matplotlib.legend.Legend object at 0x7ff897e38d50>

Comparing S&P 500 and VIX


In [33]:
vixdat = fetchHistoricalData("^VIX",startDate);

In [34]:
subplot(2,1,1)
plot(data.dates, data.adjusted_close)
legend([sym],"best")
subplot(2,1,2)
plot(vixdat.dates, vixdat.adjusted_close)
legend(["^VIX"],"best")


Out[34]:
PyObject <matplotlib.legend.Legend object at 0x7ff897c8fbd0>

In [29]:


In [ ]: