8 votes
Accepted

Efficient way to store orderbook in Python

The best solution is to change how you're doing it completely: Store the data before it even gets to your program and process it later. e.g. Use your program merely as a daemon to subscribe to the ...
  • 1,820
7 votes
Accepted

Problem with pricing a call option using the Monte Carlo Vasicek model

To make sure that I understand the problem: you are trying to price a call option expiring at time 0.5, which will exercise into a unit notional zero-coupon bond with a maturity of 1.0 at a strike (...
  • 845
5 votes

How to minimize Nelson-Siegel parametric form

When we worked with that model several years go, we used Differential Evolution and it worked very well. See Calibrating the Nelson-Siegel-Svensson Model. At least in the standard version, a best-of-...
4 votes
Accepted

How to calculate Sortino ratio from a weighted portfolio with Python?

Sortino ratio in Python: Doing my own due dilligence, I found a paper depicting the formula for the Sortino ratio, which follows the same setup as from this link described in an earlier comment. For ...
  • 3,903
4 votes
Accepted

Quantlib: How to print the maturity dates or pillars from the helpers in Quantlib python?

You can see at the beginning of this file the methods exported by all helpers. For the pillar dates, you can write for h in helpers: print(h.pillarDate())
4 votes
Accepted

QuantLib: How to import indexes from QuantLib?

That's the structure of the folders in the C++ source, but the Python module is flat. Just write: from QuantLib import EUHICP, TARGET
4 votes
Accepted

QuantlIb: How to use maturities in place of Tenors in OIS rate helpers Quantlib?

Use the DatedOISRateHelper class instead. It takes explicit start and end dates. (The two cases—tenor and explicit dates—needed to be implemented differently in C++...
4 votes

Quantlib: VanillaSwap not using underlying Index fixings correctly

That's because the default of the library is to estimate floating-rate coupons at par on the curve. This can cause the end dates of the underlying forward rates to differ from the ones implied by ...
4 votes

Why is my put intrinsic value greater than my actual put value in BSM? Python code

The answer to your question: A European put option can be priced below intrinsic value in a high interest rate environment (such as r=0.1) when stock price is low enough. That is due to time value of ...
  • 9,657
3 votes
Accepted

Easier way than using QuantLib to compute the price and Greeks of a vanilla European option?

You should think of QuantLib as a set of very powerfull tools/parts which you can use to build your own pricers. If you are going to price a single option, yes it takes a bit of boilerplate code to ...
  • 5,375
3 votes

Where can I find a Python module for Stock volatility estimators using Yang Zhang method?

There's a github repository for this: "A complete set of volatility estimators based on Euan Sinclair's Volatility Trading." https://github.com/jasonstrimpel/volatility-trading
3 votes
Accepted

How to make a schedule for amortizing bonds in python quantlib?

Amortization is included when you build the bond. Given that you're mentioning a payment of 300, I'll guess that your face amount is 1000, not 100 as you wrote. Also, you're mentioning a payment on ...
3 votes
Accepted

Fitting a volatility smile with pySABR -- Python implementation of SABR model

Edit: You need to specify the keyword arguments in your second example The poor calibration of your second example comes from the fact, that you didn't define the keyword arguments in the LNsabr-...
  • 3,903
3 votes
Accepted

Can NumPy calculate the % change the way it is shown in multiple instrument charts?

Sure - just divide (.div()) the values in each series by the starting value in that series and subtract 1. The actual syntax will depend on how your data is ...
  • 1,111
3 votes

How do Personal Finance companies get access to their customers investment accounts?

I would reach out to SnapTrade. You would connect your platform to them, and in turn they allow your customers to connect numerous brokerage accounts to your platform.
3 votes

How do you handle non integer time intervals in Quantlib for options pricing (ie intraday pricing)

QuantLib has support for intraday calculations, but it's not enabled by default because it makes the library slower. Unfortunately, it's not a runtime switch: you'll have to recompile QuantLib and ...
2 votes
Accepted

Triple Gaussian integrals in Python

Both values are practically zero and the difference between the two pieces of software is really, really small (almost infinitesimal compared to your inputs). Computers are not perfect calculators and ...
  • 7,731
2 votes
Accepted

Simulating Correlated Stock Returns in Python (SciPy)

I have not run your code, but this is an example where Jensen's inequality holds. Suppose you look at returns of a single asset over two periods, $R_1$ and $R_2$. Returns here mean gross returns, such ...
2 votes
Accepted

Quantlib HW 1f model calibration not fitting to market normal vol quotes

You will need a time-dependent volatility function rather than a constant volatility, typically a piece-wise constant volatility function is used and can reproduce the swaption vols exactly (presuming ...
2 votes
Accepted

Specify fixing days for floating leg in Interest Rate Swap valuation using QuantLib Python

VanillaSwap models simple swaps, so it doesn't have a lot of bells and whistles. For more control, you can create the two legs separately and use the ...
2 votes

question on QuantLib schedule to get bond coupon payment dates - python

With end-of-month set to False, the schedule doesn't even try to hit the 31st; it starts from a stub on the 30th, so it uses the 30th of the month for all other ...
2 votes
Accepted

Option Pricing - Incorrect price outcome for Out of the Money (OTM) calls

Your end goal of obtaining "fair" theoretical option prices will unfortunately require a lot of effort if you want to get this done properly on your own. Here are a few reasons why: All ...
  • 4,962
2 votes

Easier way than using QuantLib to compute the price and Greeks of a vanilla European option?

You could simply code the formulas yourself, but this would not reduce the amount of code. I would say using quantlib is already very compact.
  • 103
2 votes

QuantlIb: How to use maturities in place of Tenors in OIS rate helpers Quantlib?

It seems the constructor insists on a tenor. What you could perhaps try is convert the days between the maturity date and settlement date/effective date of the curve and then create a Period object ...
  • 21
2 votes

Verify numerically relation between mean deviation and standard deviation

There's a small typo, Mean absolute deviation, with 0 mean = sum(abs(x))/n Standard deviation, with 0 mean = np.sqrt(sum(x ** 2))/np.sqrt(n) So when you divide MAD over SD you should use: sum(abs(x)) /...
2 votes

GRS test (Gibbon, Ross and Shanken (1989) in Python

If by the middle part you refer to $$\bigg[1 + \bigg(\frac{E_T[f]}{\hat{\sigma}_T(f)}\bigg)^2 \bigg]^{-1},$$ then I believe that $E_T[f]$ is the mean of the excess factor returns and $\hat{\sigma}_T(f)...
  • 41
2 votes
Accepted

compute Expected Shortfall / Conditional VaR from distribution

Generally, VaR and ES can been seen from two different points of view: $R_t$ are portfolio returns. Then VaR is left quantile (e.g. 0.05) and ES is expected return below this quantile. $L_t = -R_t$ ...
2 votes
Accepted

Finding optimal option to maximise gains under given price hypothesis

I do not know of any package that can solve your problem; but it seems to be a simple problem, in the end: Given a 'future target price' $S^*$ (say 150 in your case) and a set of call options with ...
  • 5,938
2 votes
Accepted

Euler Discretization python code

I believe this link will have what you are looking for. Python Numerical Methods -- Chapter 22.3
  • 3,880
2 votes

Cointegration between crypto markets

There is likely an issue with the missing candles in your data. Whilst you have made steps to ensure that the data is equal length for your test, it is quite possible that these two series' timestamps ...

Only top scored, non community-wiki answers of a minimum length are eligible