4
$\begingroup$

There is a folklore white noise hypothesis related to (and equivalent to some forms of) the efficient market hypothesis in finance -see references below. But are there some asset pairs whose return time series (or perhaps some "natural" transforms of those time series) are approximately noises of another color than white ? -I ask as a nonspecialist, obviously.

Thank you.

Bonus question: Does anyone know how to play/hear a (financial) time series recorded as a pandas series, dataframe, python list, numpy array, csv/txt file,... ?

https://www.jstor.org/stable/2326311 https://www.lasu.edu.ng/publications/management_sciences/james_kehinde_ja_10.pdf http://www2.kobe-u.ac.jp/~motegi/WEB_max_corr_empirics_EJ_revise1_v12.pdf https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8450754/ https://journals.sagepub.com/doi/pdf/10.1177/0256090919930203 http://www.ijhssnet.com/journals/Vol_2_No_22_Special_Issue_November_2012/23.pdf https://en.wikipedia.org/wiki/Colors_of_noise -On colors of noise

$\endgroup$
4
  • 3
    $\begingroup$ For example Brownian/red noise (en.wikipedia.org/wiki/Brownian_noise) is used a lot in finance. However, other than white noise, I don't think people use the color of noise terminology much in standard statistics (or in its applications to finance), where the term noise tends to refer to white noise. $\endgroup$
    – fes
    Commented May 9, 2023 at 18:59
  • $\begingroup$ Thank you @fes. Yes for white and red noise (1D brownian motion) i knew some of their uses. The markets size or single asset price are usually assumed modeled rather by a geometric brownian motion (introduced by Bachelier) which does not have a power law spectrum (ie is not a colored noise), and does not even have a usual spectral density as it does not have stationary increments. The GBM for $S$ the price process corresponds to the logarithmic return process, $R(t)=d\log S/dt$ (0 mean rate here), which is a white noise. I should have added that in the question, but im reading about it. :) $\endgroup$
    – plm
    Commented May 9, 2023 at 23:31
  • $\begingroup$ Actually i am finding relevant papers. First to complete my comment above there is the wikipedia entry on brownian markets: en.wikipedia.org/wiki/Brownian_model_of_financial_markets . Then as partial answer to my original question there was a 1996 article studying the resulting process when replacing white noise logarithmic returns by colored returns, and it seems they match some real markets -but i can only see the abstract, not the fulltext: papers.ssrn.com/sol3/papers.cfm?abstract_id=1663383 . $\endgroup$
    – plm
    Commented May 9, 2023 at 23:36
  • $\begingroup$ Arithmetic Brownian motion is used more in interest rate modelling. Though you can find some applications of different color noises more likely people have implicitly used these without using the terms. $\endgroup$
    – fes
    Commented May 10, 2023 at 4:42

1 Answer 1

7
$\begingroup$

Bonus question: Does anyone know how to play/hear a (financial) time series recorded as a pandas series, dataframe, python list, numpy array, csv/txt file,... ?

This is kind of fun and has practical applications to quantitative finance. My partners and I have actually been experimenting with this as the basis for a model for a short while now and have experienced very interesting results.

At first, I found it most straightforward to map my time series to piano key frequencies. I specifically made a dictionary of piano key frequencies out of just one octave on a piano. The octave consisted of seven white and five black (sharp) keys. Each key was calibrated in relation to the others, just like a piano would be tuned. I "tuned" it to middle C in this way:

$$note frequency = base frequency * 2^\frac N{12} $$

Where the $base frequency$ is that of middle C (261.63 Hz) and each $N$ is a note from C to B (C, c, D, d, E, F, f, G, g, A, a, B). This is known as an equal temperament system.

In Python, we can create a dictionary of frequencies like this:

def piano_notes():
    '''
    Returns a dictionary containing the frequencies of piano notes
    '''

    base_freq = 261.63

    octave = ['C', 'c', 'D', 'd', 'E', 'F', 'f', 'G', 'g', 'A', 'a', 'B']

    note_freqs = {octave[i]: base_freq * 2**(i/12) for i in range(len(octave))}        
    note_freqs[''] = 0.0  # pause / silent note
    
    return note_freqs

The output from print(note_freqs):

{'C': 261.63, 'c': 277.18732937722245, 'D': 293.66974569918125, 'd': 311.1322574981619, 'E': 329.63314428399565, 'F': 349.2341510465061, 'f': 370.00069432367286, 'G': 392.0020805232462, 'g': 415.31173722644, 'A': 440.00745824565865, 'a': 466.1716632541139, 'B': 493.89167285382297, '': 0.0}

From here, you must decide how to transform every price or return in your time series into an integer from 0 - 11 and map them to their respective dictionary values. That step requires some creativity, and I'll leave that to you.

Now that you have your time series mapped to piano note frequencies, to be able to listen to your time series, you need to convert your frequencies into something that can be played, i.e., you need to turn them into sound waves!

A wave can be mathematically described as: $$g(f)=A * \sin(2\pi\ {ft})$$ where: $A$=amplitude, $f$=frequency, and $t$=time. That said, we need to have a function that generates a wave array with respect to time which is much easier than it sounds:

import numpy as np

sample_rate = 44100  # Standard sample rate in digital audio (in Hertz, Hz)

def waves(freq, duration=0.5):
    '''
    Takes frequency, and time_duration as inputs and returns
    a numpy array of values at all points in time
    '''
    
    amplitude = 4096  # tuning fork frequency

    t = np.linspace(0, duration, int(sample_rate * duration))
    wave = amplitude * np.sin(2 * np.pi * freq * t)
    
    return wave

After turning your notes into playable waves, you concatenate them, save them locally, and play them.

import numpy as np
from scipy.io.wavfile import write

def song_data(music_notes):
    '''
    concatenate all the waves
    '''
    note_freqs = piano_notes()
    song = [waves(note_freqs[note]) for note in music_notes.split('-')]
    song = np.concatenate(song)
    return song

Here is an example of using the above functions to play "Mary Had A Little Lamb." The file will save in your working directory and can be played using a generic .wav player on just about any machine.

music_notes = 'E-D-C-D-E-E-E--D-D-D--E-E-E--E-D-C-D-E-E-E--E-D-D-E-D-C-'
data = song_data(music_notes)
write('mary-had-a-little-lamb.wav', samplerate, data.astype(np.int16))

Practically speaking, the similarities between the math behind the music and other patterns in nature are extremely interesting. Our original idea has morphed into a full piano (88 keys) with seven octaves and all known chords being played. We have begun to incorporate other instruments recently as well.

I'll leave it to you to determine whether or not the markets are, indeed, playing a song that you like--and can profit from!

$\endgroup$
3
  • 1
    $\begingroup$ Thanks alot @amdopt. I will try running your code on some examples in the coming days -i can't do it in one go right now. And i will try to see if i can find other interesting audio representations of financial time series -as my motivation allows. :) $\endgroup$
    – plm
    Commented May 9, 2023 at 23:39
  • 6
    $\begingroup$ I thought the bonus question was a joke $\endgroup$
    – quantinho
    Commented May 10, 2023 at 5:04
  • $\begingroup$ @quantinho i presented it as a bonus because it is more a question in programming than in quantitative finance. And bonus questions are often the best. :) $\endgroup$
    – plm
    Commented May 12, 2023 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.