josemiotto / pylevy

Levy distributions for Python
GNU General Public License v3.0
34 stars 18 forks source link

Levy_fit error #3

Closed VBrassart closed 6 years ago

VBrassart commented 7 years ago

Hi, I've tried to do a simple fit of SP500 log returns and got an erroneous fit (1.5,0,0,1). Looking at the warning, it said it encountered a divide by zero. I double checked the dataset for zero values and there were none. Do you have an idea of what the error could be? I have attached a screenshot of the code.

Best regards, Victor

screen shot 2017-04-26 at 14 23 49
josemiotto commented 7 years ago

Thanks Victor for reporting this one.

the zero that brings the error is in the sigma, not in x. It is strange, because the parameter for the fit corresponding to sigma is 1.0. I'll check it soon. Meanwhile, can you put in the line before the error (278) a print(sigma)?

best Jose

On Wed, Apr 26, 2017 at 2:25 PM, VBrassart notifications@github.com wrote:

Hi, I've tried to do a simple fit of SP500 log returns and got an erroneous fit (1.5,0,0,1). Looking at the warning, it said it encountered a divide by zero. I double checked the dataset for zero values and there were none. Do you have an idea of what the error could be? I have attached a screenshot of the code.

Best regards, Victor

[image: screen shot 2017-04-26 at 14 23 49] https://cloud.githubusercontent.com/assets/28051075/25434326/26913ec4-2a8c-11e7-8688-8b9bd43759b7.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/josemiotto/pylevy/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQp0i5tFLo-tiKkH3JyzihGssJwTqUKks5rzzfDgaJpZM4NIyQ8 .

VBrassart commented 7 years ago

Yes, you are right about sigma. Sigma seems to converge quite quickly to zero. Here is the print result:

screen shot 2017-04-27 at 10 59 14
josemiotto commented 7 years ago

Hi, I just committed a change. Now there is a lower boundary of sigma on 1e-6, instead of 0. The problem is that the optimization algorithm accept the value of the border as well, so let's see if this improves the situation. It could be that you get stuck in sigma=1e-6, in that case probably something happens with your data (it could be that is not levy distributed).

let me know, Jose

On Thu, Apr 27, 2017 at 11:00 AM, VBrassart notifications@github.com wrote:

Yes, you are right about sigma. Sigma seems to converge quite quickly to zero. Here is the print result: [image: screen shot 2017-04-27 at 10 59 14] https://cloud.githubusercontent.com/assets/28051075/25475898/9d88c7ca-2b38-11e7-802c-a3d9b545ee06.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/josemiotto/pylevy/issues/3#issuecomment-297656016, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQp0pRujobjJhU7UFZL3ZXwbANCOVeDks5r0Fk0gaJpZM4NIyQ8 .

VBrassart commented 7 years ago

Hi again Jose,

it seemed like a good idea but it doesn't fix the problem (I've also tried for even lower boundaries of sigma). A new error appears in the reflect function, when at some point is has to handle a NoneType. I don't think the data is the problem (I've used the same data with success in Mathematica and R, which also have options to fit levy stable distributions). Maybe letting the user come with initial guesses for the fit values could be an option?

Cheers, Victor

screen shot 2017-04-27 at 19 00 44
josemiotto commented 7 years ago

Sorry, can you try to change the last value of par_bounds (line 42) from None to 1e10?

On Thu, Apr 27, 2017 at 7:01 PM, VBrassart notifications@github.com wrote:

Hi again Jose,

it seemed like a good idea but it doesn't fix the problem (I've also tried for even lower boundaries of sigma). A new error appears in the reflect function, when at some point is has to handle a NoneType. I don't think the data is the problem (I've used the same data with success in Mathematica and R, which also have options to fit levy stable distributions). Maybe letting the user come with initial guesses for the fit values could be an option?

Cheers, Victor [image: screen shot 2017-04-27 at 19 00 44] https://cloud.githubusercontent.com/assets/28051075/25494988/dc440964-2b7b-11e7-9f92-f3082a387341.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/josemiotto/pylevy/issues/3#issuecomment-297776609, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQp0vhIokZhQG51X0gUjmvwFyzrKBLfks5r0MnsgaJpZM4NIyQ8 .

VBrassart commented 7 years ago

I found the error. You are using parbounds[2] instead of parbounds[3] for sigma. Including your last remark, the code works. For mu you could also have parameter boundaries.

screen shot 2017-04-27 at 20 10 07
josemiotto commented 6 years ago

This was fixed.