Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Markov Switching Multifractal simulation #28

Merged
merged 2 commits into from
Feb 16, 2021

Conversation

xavierdcruz0
Copy link
Contributor

I added a module that runs a Binomial Markov Switching Multifractal simulation, as introduced by Calvet and Fisher in this 2002 paper https://core.ac.uk/download/pdf/162459682.pdf

I think there might be a couple of mistakes and/or improvements to be made, so please review this, but I thought it would be a good addition to this package.

I wasn't exactly sure how to get it to adhere to the same interface as the BrownianMotion.simulate() method, as this seems to return some kind of distorted time along with the Brownian motion itself. Maybe you can explain further.

In the future it might be interesting to develop modules to infer MSM model parameters from data, which is a can of worms... But for the time being, a simulation from hardcoded parameters is nice.

If you run the markov_switching_multifractal.py as main you can quickly demo the code.

@hyperstripe50 hyperstripe50 self-assigned this Feb 14, 2021
@hyperstripe50
Copy link
Owner

hyperstripe50 commented Feb 14, 2021

@xavierdcruz0 Thank you for your contribution! After a quick review we will merge your code.

You are right that the BrownianMotion.simulate() method returns a distorted time such that the step increments are not equivalent. This is a product of constructing the time series with a fractal generator that has two turning points. The time coordinates of this generator are adjusted based off of a random measure. See this Medium article for more detail.

In the examples section, you will see that interpolation of the time series that BrownianMotion.simulate() produces is required to produce equal time steps.

@hyperstripe50
Copy link
Owner

@xavierdcruz0 Once again, fantastic work on this. Your contribution is really appreciated!

I have one request before I merge your code. With respect to the simulate method, you have the ideal output as compared to the BrownianMotion simulate method, since your time increments are equivalent. The method, however, should return the price series in the form of a 2D array [[x,y]...]. I see that you have a helper method to get this price series named returns_to_prices. Please do the following before the merge.

Adjust the code to comply to the proper simulate method. You will have to move the timesteps parameter to the __init__ method.

def simulate(self): 
    ...
    return prices # where prices is a 2D array [[x, y]...] where x is the time coordinate and y is the price. (your x will be equally spaced)

Feel free, of course, to keep a method that calculates the returns series from the price series.

@xavierdcruz0
Copy link
Contributor Author

Hi, thanks for getting back to me. I made the changes to add the time array, so it fits the existing interface:

msm

I just wanted to get your opinion on one design choice:

When converting the returns generated by MSM into absolute price values, I chose a starting price arbitrarily of 1.0. https://github.com/xavierdcruz0/fractal-market-analysis/blob/master/fractalmarkets/msm/markov_switching_multifractal.py#L101

I don't know how exactly this impacts the scale of the resulting values, as I noticed that the existing Brownian Motion is (mostly) confined to the unit interval (owing to the interesting way it is constructed recursively from that lightning-bolt shape).

Just have a look and let me know if it's consistent with the rest of the simulations in the package.

I am excited by this repo, I hope we can make it a one-stop-shop for everything multifractal in python time-series analysis! Perhaps writing code to estimate multifractal model parameters from data would be a good direction to go?

@hyperstripe50 hyperstripe50 merged commit 00bacd7 into hyperstripe50:master Feb 16, 2021
@hyperstripe50
Copy link
Owner

@xavierdcruz0,

@dluftspring and I discussed the consequences of starting the price arbitrarily at 1.0 and concluded that there weren't any.

With respect to the following question:

Perhaps writing code to estimate multifractal model parameters from data would be a good direction to go?

This is exactly the right direction to take the project and all suggestions are welcome here. Please see issue #27 for a starting point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants