Repository navigation
Description
(no immediate plans, but we don't have an issue, it's mentioned in just a few issues)
application to pairs trading https://www.quantopian.com/posts/statistical-arbitrage-using-gaussian-copula
(comment recommends ICA https://www.hindawi.com/journals/isrn/2013/434832 )
some background on pairs trading using cointegration or copulas https://www.quantconnect.com/tutorials/pairs-trading-strategy/
https://statsletters.com/2016/10/19/trying-out-copula-packages-in-python-i/
https://statsletters.com/2016/11/16/trying-out-copula-packages-in-python-ii/
https://github.com/lia-statsletters/notebooks/blob/master/Copula%20packages%20continuation.ipynb
the second blog post, (ii), uses the old code in statsmodels sandbox
quote: "However as it is, is quite flexible. Is good that the developers decided to keep it anyway."
(an argument for not just deleting stale code in the sandbox)
(Note: the notebook repo has a GPL license)
There would be a long way to catch up with more recent developments which went more into vines and nested copulas (last time I checked) which are a bit more difficult to implement (efficiently).
However, it would be possible to get the basics. Either following up on the sandbox with unit tests comparing to R, or emphasis on special cases, e.g. bivariate normal and t copulas.
(Integration code of ... is now BSD licensed, scipy has only the generic multivariate normal cdf Fortran code, but we should be able to get relatively efficient/fast bivariate normal and t cdf.)
Of interest besides financial applications are cases with discrete or mixed continuous-discrete multivariate models.
Activity
josef-pkt commentedon Oct 18, 2017
only partially related, but a good answer with a list of python packages for quantitative finance
https://quant.stackexchange.com/questions/34275/equivalent-to-matlabs-financial-toolbox-in-python/34278
josef-pkt commentedon Oct 18, 2017
adding a reference because it showed up on the google search, I haven't looked at it beyond title
Irannezhad, Elnaz, Carlo G. Prato, Mark Hickman, and Afshin Shariat Mohaymany. A Copula-Based Joint Discrete-Continuous Model of Road Vehicle Type and Shipment Size. No. 17-05892. 2017.
http://docs.trb.org/prp/17-05892.pdf
josef-pkt commentedon Oct 18, 2017
and another stale issue
http://jpktd.blogspot.ca/2012/06/non-linear-dependence-measures-distance.html
I was initially looking at and working on copula based tests of 'independence' (?) or uncorrelated it terms of some non-linear distance measure. (including auto-correlation, serial independence)
(I have no idea where the code or notes are.)
lia-statsletters commentedon Jan 24, 2018
Hi! I wrote the notebooks and came here to say: resurrecting copulas? yes please! There is also very good material in this book: "Quantitative Risk Management: Concepts, Techniques and Tools" by Alexander J. McNeil, Rüdiger Frey and Paul Embrechts, published by Princeton University Press in 2015" and in qrmtutorial.org.
jmatthewpeters commentedon Aug 30, 2018
I'd like to help with this if I can. I would love to have something like [https://cran.r-project.org/web/packages/copula/copula.pdf]( R copula Package ) [https://datascienceplus.com/modelling-dependence-with-copulas/] I'm trying to replicate a project that was written in R that uses that package and while I think what is here is good enough, I'd be willing to help out if I can (I haven't built many python libraries).
josef-pkt commentedon Aug 30, 2018
It would be great if you (and anyone else) would move this forward.
One of the first things that would be needed are unit tests against R to check that those functions are correct. Also a rough roadmap for missing pieces would be useful to see what is needed to make this useful. When I wrote this I mainly focused on pdf and cdf, and the general setup for Archimedean and extreme value copulas. I guess adding fit (and rvs ?) would be important.
Then it would be easier to incrementally add more features.
I just looked for a while through my old (2011) folders to see what else I did. I have one more commit in my local repo that is not in the statsmodels sandbox. I don't find any additional example scripts or code that I might have written.
(I have 500 pdf files with copula in the name in my old folders, but it looks like I did more reading articles than writing code. )
josef-pkt commentedon Aug 30, 2018
A general warning:
We are not allowed to translate code that is released under GPL or any other license that is not BSD compatible, unless we have explicit permission to do so.
jmatthewpeters commentedon Aug 30, 2018
Ok, I will need some guidance on how you want the tests to look, if there is some standards already for statsmodels I can look them up or if you want to point me to them. I can't imagine just translating anything, I don't really like the structure for the R code. I like the approach so some of the more complicated functions, but they used mathematica to derive some of the functions and I can use sympy for it. I can't guarantee how fast I can get stuff done but at least I can work on it.
josef-pkt commentedon Aug 30, 2018
(I found a file where I had used sympy to try out obtaining derivatives for some copula functions. Mathematica online is also pretty good.)
for unit tests
background reading is the numpy testing guidelines which is roughly followed by most packages in this area, although there are idiosyncratic differences, e.g. we have many classes
https://github.com/numpy/numpy/blob/master/doc/TESTS.rst.txt
for many unit test we use test classes when we need to check many different attributes or results.
However, the simplest cases are just hardcoding the corresponding number from R and compare them to the statsmodels function with
assert_allclosefrom numpy testing.e.g. https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/tests/test_proportion.py#L500
For example for the current copula code you could get the pdf and cdf at several values from R.
If there are many cases and it gets repetitive, then storing the results separately and using a loop or parameterized test will reduce copy-paste tasks. (e.g. in Stata and R I use export scripts if there are too many cases to do it by hand.)
josef-pkt commentedon Aug 30, 2018
I added the commit that I found with the example for some of the Archimedean copulas
#5076
It adds the derivatives to the archimedean copula transform classes, but I don't remember why we need them.
josef-pkt commentedon Aug 31, 2018
I checked that the basic things in
copulaare working, but didn't verify by comparing to other packages.I merged the extra commit in #5076, and added some comments on my interpretation of the copula code.
I need to go back to other projects, but I can spend more time on this if there are questions or if I need to help with implementing parts of it.
jmatthewpeters commentedon Aug 31, 2018
Thank you. I'm slowly getting up to speed on some of its and will work on some tests and comparisons to R. I'm just going to need some time to figure out how to replicate the test cases in R and then translate that to here.
35 remaining items
tupui commentedon May 13, 2021
We can use and compare our values to the output, but the documentation is also licensed. Most people don't bother to use a proper licensing for their doc and just license the whole thing with the same license, but still. If having a look at a licensed code to figure something out and code yourself the solution is not ok, then the same apply for the doc if covered under the same terms.
josef-pkt commentedon May 13, 2021
No, we can read documentation without problems. Copyright for documentation means we cannot copy the documentation itself. (e.g. We can read scientific articles and use them, but we cannot plagiarize them.)
It does not affect writing code after reading the documentation, otherwise we would never be allowed to look at documentation of proprietary packages like Matlab, SAS, SPSS, Stata and ...
tupui commentedon May 13, 2021
Well nobody will come here to annoy us... So just for the sack of the discussion. But if the documentation is licensed under GPL's terms, it's GPL. There are other license which are more appropriate to properly distribute doc, and almost no package have a separate license for the doc. What is commonly done by people is another story I am afraid. As for the articles, here as well it's the far west as nobody really reads the copyright of any paper which is different from one journal to the other.
josef-pkt commentedon May 13, 2021
But facts and definitions cannot be copyrighted. Whatever copyright is assigned, doesn't matter.
e.g. random google find: copyrightability of short phrases https://fairuse.stanford.edu/2003/09/09/copyright_protection_for_short/
for example from copBasic surfuncCOP docstring:
Nothing original, copyrightable in there.
ChadFulton commentedon May 13, 2021
Another good example of this is recipes for food. Anyone is free to publish their own cookbook with a collection of any recipes.
This is also one of the reasons why companies maintain trade secrets - the fundamental elements of many trade secrets (e.g. algorithms, these days) often can't be copyrighted.
tupui commentedon May 13, 2021
See this for the recipe, not that simple 😉: https://www.copyright.gov/circs/circ33.pdf As always, this is a question of understanding and subjective to the appreciation of the judge. Also remember that copyright laws are different from one country to another.
But I just wanted to ensure you saw this R library was under GPL and hence it should be dealt with care.
bashtage commentedon May 13, 2021
In the US at least, the Google vs Oracle made it pretty clear that API documentation is not copyrighted. So if one wanted to write a work-alike package, that would probably be OK under current US case law.
tupui commentedon May 13, 2021
Sure sure, but here we are not talking about naming things the same. But read the doc or have a look at some other work to figure out how it works and how we can replicate. Which is quite different.
josef-pkt commentedon May 13, 2021
That's the same as in the recipe case in your linked pdf.
The original, artistic presentation of a recipe can be copyrighted, but not the ingredients and procedure to replicate the dish.
Also, except for a few computational hints, e.g. for corner cases, nothing in the documentation of packages like copula, copBasic is original methods. If there were a copyright on methods/procedures/definitions, then it would be copyright be the original authors. However, that (methods, definitions, theorems, ...) is not copyrightable because it would kill science.
josef-pkt commentedon Mar 3, 2023
closing
we still have updated open issues
general:
#8635 missing parts and extensions
#7258 some notes and references
and other issues for specific extensions