Monday, 27 April 2015

How to Get High Frequency Stock Prices with Python: Prague Stock Exchange Example

From time to time high frequency stock prices data is needed even for less developed CEE stock markets. I needed high frequency prices for CEZ (a Prague Stock Exchange listed company). With this task and having Python I wrote a brief code for extracting the data (the final piece of code is saving the data):

import urllib

def create_url(ticker):
    base_url = 'http://www.pse.cz/XML/ProduktKontinualJS.aspx?'
    search_query = 'cnpa={}'.format(ticker)
    search_url = '{}{}'.format(base_url, search_query)
    return search_url

def clean_url(url):
    cleaned=urllib.urlopen(url).read().split("function createOnlineChart(divName)")[0]
    for character in ['k:', 'o:', 'd:new Date', '{', '}', '\r\nvar chartDataOL =', '[', ']', '(', ')', ';', ' ']:
        if character in cleaned:
            cleaned=cleaned.replace(character,'')
    return cleaned

if __name__ == '__main__':
    ticker='4169' # '4169' CEZ, '6407' Erste Group Bank, '4171' Komercni Banka, '4174' O2, '6816' NWR, '4254' Philip Morris CR

url=create_url(ticker)
cleanurl=clean_url(url)
with open ("trades.txt", "w") as f:
    f.write(cleanurl)

Wednesday, 15 April 2015

Copula Application in Euro Area Credit Default Swaps

Summary 
In the research we presented copula as measure of dependence that is particularly useful for identification of tail dependence between variables. We tested different copula functions for credit default swap (CDS) changes of selected euro area countries. We reached the conclusion that the Student’s t copula describes best the dependence structure of the variables. The results support the opinion that the Gaussian copula is not a suitable tool despite its widespread use. Student’s t copula has tail dependence and hence it is more useful than Gaussian copula (no tail dependence) to simulate events like joint defaults and stock market crashes. Another interesting result of the research is that in some cases we proved that certain types of Archimedean copulas provide second best fit to data (implying that the asymmetric tail dependence is also a good fit).We use the best fit copula to model market risk of CDS.