Quantlib Black Karasinski calibration with negative rates - quantitative-finance

I was calibrating Black Karasinski model using QuantLib-Python with Euro swaption at-the-money vol surface using TreeSwaptionEngine. I got the following error:
return _QuantLib.CalibratedModel_calibrate(self, *args)
RuntimeError: root not bracketed: f[-50,50] -> [1.434457e-04,1.000143e+00]
Might this error be related with negative interest rates?
Does Quantlib ql.BlackKarasinski allow ShiftedLognormal option and a displacement input?
Many thanks,
Huarong

Related

Shap explainer gives an error with ECFP4 fingerprints

I am training a Random Forest with molecular fingerprints and adding a shap explainer, with the shap package function
explainer = shap.Explainer(forest)
and it gives me the error:
"ExplainerError: Additivity check failed in TreeExplainer! Please ensure the data matrix you passed to the explainer is the same shape that the model was trained on. If your data shape is correct then please report this on GitHub. Consider retrying with the feature_perturbation='interventional' option. This check failed because for one of the samples the sum of the SHAP values was 28208132836061024.000000, while the model output was 0.846000. If this difference is acceptable you can set check_additivity=False to disable this check."
Now, the error seems to be very straight forward, but the unintelligible thing is :
I did the exact same thing with MACC fingerprints, it worked.
I looked into the shape of the data, it is (2334, 2048) for train and (193, 2048) for validation, with MACCS it was analogous.
the validation set consists only of 1 and 0 as it should
the fingerprints are all same lengths, no errors there
I did some external validation with the validation set and there were no problems there.
roc = metrics.roc_auc_score(labels_val, predicted)
tn, fp, fn, tp = confusion_matrix(labels_val, predicted).ravel()
I checked that the forest I trained with was the forest I was using.
And yes, I even restarted my computer.
If someone has any idea what could cause this problem, please let me know!

SortedEffects R Package

I study the association between air pollution levels and the weekly number of cases of a respiratory disease controlling for various socioeconomic characteristics at the census block level in a state. I do not attempt to examine the causal effect of pollution - just the association between air pollution and the respiratory disease.
I want to explore the heterogeneity of the effect of pollution on the respiratory disease incidence across census blocks. I know that I can implement the partial (sorted) effects method and classification analysis using the SortedEffects R package. However, my main variable of interest, the level of pollution, is continuous and not binary. In this case, does it still make sense for me to use the package (its spe command, etc.)?
If I set var_type = "continuous”, the spe command gives me the following error: “Error in FUN(left, right) : non-numeric argument to binary operator”.
If I set var_type = "binary”, which is not the case in ‘real life’, the command starts working, but then it gives new errors: “Error in quantile.default(t_hat, 1 - alpha) : missing values and NaN's not allowed if 'na.rm' is FALSE. In addition: Warning message: In predict.lm(model_fit, newdata = d1) : prediction from a rank-deficient fit may be misleading”
I do not know what I am doing wrong.
I am quite new to R, so sorry in advance.
Thank you.

GaussianProductOp.ProductAverageConditional - has quality band Experimental which is less than the recommended quality band (Preview)

I have a quite simple rule and I get already the quality band issue. Can someone explain why this is happening? I have read the docs about Quality bands but I don't understand it.
This is the code I wrote that produces the warning:
Gaussian BornYoungPerLitterDist = new Gaussian(5.5, 0);
Gaussian BirthRateDist = new Gaussian(0.004102103451, 0.00000144);
Variable<double> BornYoungPerLitter = Variable.Random<double, Gaussian>(BornYoungPerLitterDist);
Variable<double> Birthrate = Variable.Random<double, Gaussian>(BirthRateDist);
InferenceEngine engine = new InferenceEngine();
Gaussian Born = engine.Infer<Gaussian>(BornYoungPerLitter * Birthrate);
Console.WriteLine(
"Born Mean: {0:f10}, Standard Deviation: {1:f10}",
Born.GetMean(),
Math.Sqrt(Born.GetVariance())
);
the warning is:
Compiling model...compilation had 1 warning(s).
[1] GaussianProductOp.ProductAverageConditional(vdouble2_use_B, vGaussian0, vGaussian1) has quality band Experimental which is less than the recommended quality band (Preview)
This question was answered on the Github repository from Infer.Net.
On date January 2019 the feature is still in development and for that always throws the warning.
This happens because the code that implements a product of Gaussian variables (GaussianProductOp) is in an early stage of development. If you want to disable the model compiler errors and/or the warnings, set the options on engine.Compiler.
https://github.com/dotnet/infer/issues/104

surface feature detection on image processing

An example of detectSURFFeatures in comparison of 2 image is in below. I couldn't make detectSURFFeatures function work in my MATLAB. no help or doc detectSURFFeatures gives any clue. the error says " > UncalibratedSterio
Undefined function 'detectSURFFeatures' for input arguments of type 'uint8'." but the function itself can cover uint8 as i know. what should i do?
%Rectified Sterio Image Uncalibrated
% There is no calibration of cameras
I1 = rgb2gray(imread('right_me.jpg'));
I2 = rgb2gray(imread('left_me.jpg'));
Value = 2000.0;
blobs1 = detectSURFFeatures(I1, 'MetricThreshold', Value);
blobs2 = detectSURFFeatures(I2, 'MetricThreshold', Value);
figure;
imshow(I1);
hold on;
plot(selectStrongest(blobs1, 30));
title('Thirty strongest SURF features in I1');
figure;
imshow(I2);
hold on;
plot(selectStrongest(blobs2, 30));
title('Thirty strongest SURF features in I2');
You are getting that error because detectSURFFeatures does not exist in your MATLAB distribution. You must have at least R2011b, as that was when detectSURFFeatures was available: http://www.mathworks.com/help/vision/release-notes.html#R2011b
I suspect you have an older version of MATLAB than R2011b and so if you want to make it easy on yourself, you need to upgrade your version of MATLAB. However, if I may make a suggestion, I suggest the mexopencv project by Kota Yamaguchi: http://kyamagu.github.io/mexopencv/
He wrote OpenCV wrappers that can directly interface with MATLAB and so you can actually call OpenCV's SURF feature detection and matching methods from MATLAB but you will need to install OpenCV to do that. It will be a bit of work to get it working, but this is one solution I can provide if you don't want to upgrade your version of MATLAB.
Good luck!

Cannot use scatterplot in Octave

I was learning how to do machine learning on mldata.org and I was watching a video on Youtube on how to use the data (https://www.youtube.com/watch?v=zY0UhXPy8fM) (2:50). Using the same data, I tried to follow exactly what he did and create a scatterplot of the dataset. However when he used the scatterplot command, it worked perfectly on his side, but I cannot do it on myside.
Can anyone explain what's wrong and what I should do?
octave:2> load banana_data.octave
octave:3> pkg load communications
octave:4> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
data 2x5300 84800 double
label 1x5300 42400 double
Total is 15900 elements using 127200 bytes
octave:5> scatterplot(data, label)
error: scatterplot: real X must be a vector or a 2-column matrix
error: called from:
error: /home/anthony/octave/communications-1.2.0/scatterplot.m at line 69, column 7
The error message says it all. Your data is a 2-row matrix, and not a 2-column matrix as it should be. Just transpose it with .'.
scatterplot(data.')
I dropped the label argument since it is not compatible with the communications toolbox, either in matlab or in octave.
Update:
According to news('communications'),
The plotting functions eyediagram' andscatterplot' have improved Matlab compatibility
This may be why the behaviour is different. Be ready to find other glitches, as the octave 3.2.4 used in this course is about 5 years old.
In order to use the label, you should rather use the standard octave scatter function.
Colors could be changed by choosing another colormap.
colormap(cool(256))
scatter(data(1,:), data(2,:), 6, label, "filled")

Resources