In [1]:
using PyPlot
using Dates
using YahooFinanceAPI
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
In [32]:
plot(data.dates,data.adjusted_close,"b-")
plot(data.dates[lag+1:end], ma, "r-")
legend(["$sym", "$sym MA$(lag)"])
Out[32]:
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]:
In [29]:
In [ ]: