Wolfram Language

Computational Audio

Listen to Financial Trends

Import financial data from 1990 until now.

In[1]:=
Click for copyable input
msft = TimeSeriesRescale[ TimeSeries@ FinancialData["MSFT", {"Jan. 1, 1990", DateString[Now]}], {0, 10}]; aapl = TimeSeriesRescale[ TimeSeries@ FinancialData["AAPL", {"Jan. 1, 1990", DateString[Now]}], {0, 10}];

Resample and smooth the data.

In[2]:=
Click for copyable input
resampledMSFT = TimeSeriesResample[Round[MovingAverage[msft, 60]], 1/8]; resampledAAPL = TimeSeriesResample[Round[MovingAverage[aapl, 60]], 1/8]; ListLinePlot[{resampledMSFT, resampledAAPL}, PlotStyle -> {Automatic, Automatic, PointSize[Large]}, PlotLegends -> {"MSFT", "AAPL"}]
Out[2]=

Define a function to convert price to frequency.

In[3]:=
Click for copyable input
midiToFreq[m_] := Clip[2^((m - 69)/12)*440., {0, 22050}];

Generate audio controlled by the two time series.

In[4]:=
Click for copyable input
res = .8 Mean[{AudioGenerator[{"Sin", midiToFreq[.5 resampledMSFT + 40]}], AudioGenerator[{"Triangle", midiToFreq[.5 resampledAAPL + 40]}]}]
Out[4]=
In[5]:=
Click for copyable input
Spectrogram[res, 4096, 4096, PlotRange -> {All, {0, 4000}}, ImageSize -> 300]
Out[5]=

Related Examples

de es fr ja ko pt-br ru zh