analitics

Pages

Friday, December 30, 2016

The python arch module for financial econometrics.

This python module arch: is a work-in-progress for ARCH and other tools for financial econometrics, written in Python (and Cython).
The arch python module come with tools for:
  •    Univariate volatility models
  •    Bootstrapping
  •    Multiple comparison procedures
  •    Unit root tests
You can read and see many examples here.
Let's start with instalation into my python 2.7.12 version.
First you need to install this python module with pip tool:
C:\Python27\Scripts>pip install Arch
Collecting Arch
Downloading arch-4.0.tar.gz (107kB)
100% |################################| 112kB 390kB/s
Requirement already satisfied: matplotlib>=1.4 in c:\python27\lib\site-packages (from Arch)
Requirement already satisfied: scipy>=0.15 in c:\python27\lib\site-packages (from Arch)
Collecting patsy>=0.2 (from Arch)
Downloading patsy-0.4.1-py2.py3-none-any.whl (233kB)
100% |################################| 235kB 906kB/s
Collecting statsmodels>=0.6 (from Arch)
Downloading statsmodels-0.6.1.tar.gz (7.0MB)
100% |################################| 7.0MB 85kB/s
Collecting pandas>=0.16 (from Arch)
Downloading pandas-0.19.2-cp27-cp27m-win32.whl (6.8MB)
100% |################################| 6.8MB 81kB/s
Requirement already satisfied: numpy>=1.6 in c:\python27\lib\site-packages (from matplotlib>=1.4->Arch)
Requirement already satisfied: python-dateutil in c:\python27\lib\site-packages (from matplotlib>=1.4->Arch)
Requirement already satisfied: cycler in c:\python27\lib\site-packages (from matplotlib>=1.4->Arch)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,>=1.5.6 in c:\python27\lib\site-packages (from matplotlib>=1.4->Arch)
Requirement already satisfied: pytz in c:\python27\lib\site-packages (from matplotlib>=1.4->Arch)
Requirement already satisfied: six in c:\python27\lib\site-packages (from patsy>=0.2->Arch)
Installing collected packages: patsy, pandas, statsmodels, Arch
Running setup.py install for statsmodels ... done
Running setup.py install for Arch ... done
Successfully installed Arch-4.0 pandas-0.19.2 patsy-0.4.1 statsmodels-0.6.1

This python module is very mathematical and technical so I'll refer you to a few examples.
Can be used in statistical research and econometrics, or the application of mathematics, statistics, and computer science to economic data. 

Sunday, December 18, 2016

NVIDIA python module Theano.

I try to use python module Theano.
First I install this python module.
C:\WINDOWS\system32>cd C:\Python27

C:\Python27>cd Scripts

C:\Python27\Scripts>pip install Theano
Collecting Theano
Using cached Theano-0.8.2.tar.gz
Requirement already satisfied: numpy>=1.7.1 in c:\python27\lib\site-packages (from Theano)
Requirement already satisfied: scipy>=0.11 in c:\python27\lib\site-packages (from Theano)
Requirement already satisfied: six>=1.9.0 in c:\python27\lib\site-packages (from Theano)
Installing collected packages: Theano
Running setup.py install for Theano ... done
Successfully installed Theano-0.8.2

When I try to used I got this error:
import theano
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.

I try to fix that error, but I don't find any solution.
This python module work. I tested with examples from NVIDIA, see:

Thursday, December 15, 2016

Use the twitter python module - part 002.

Using the twitter python module named python-twitter you can search twitter query into the local area.
The default tutorial is here.
The source code to change is that line:
results = api.GetSearch(raw_query="q=from%3Asomething"
with:
results = api.GetSearch(raw_query="q=&geocode=lat,long,10km")
Also, you need to put your lat and long and the area sized.
The good point of this you will be able to spell time with twitter posts.

Wednesday, December 14, 2016

Use the twitter python module - part 001.

About this python module python-twitter you can read here.

C:\>cd Python27
C:\Python27>cd Scripts
C:\Python27\Scripts>pip install python-twitter
Collecting python-twitter
Downloading python_twitter-3.2-py2-none-any.whl (71kB)
100% |################################| 81kB 292kB/s
Requirement already satisfied: requests in c:\python27\lib\site-packages (from python-twitter)
Requirement already satisfied: requests-oauthlib in c:\python27\lib\site-packages (from python-twitter)
Collecting future (from python-twitter)
Downloading future-0.16.0.tar.gz (824kB)
100% |################################| 829kB 485kB/s
Requirement already satisfied: oauthlib>=0.6.2 in c:\python27\lib\site-packages
(from requests-oauthlib->python-twitter)
Installing collected packages: future, python-twitter
Running setup.py install for future ... done
Successfully installed future-0.16.0 python-twitter-3.2


Let's see one simple example with one authentication key and token and one query:

import os
import json
import twitter
from twitter import *
CONSUMER_KEY=""
CONSUMER_SECRET=""

ACCESS_TOKEN=""
ACCESS_TOKEN_SECRET=""

api = Api(CONSUMER_KEY,
          CONSUMER_SECRET,
          ACCESS_TOKEN,
          ACCESS_TOKEN_SECRET)
def main():
    with open('output.txt', 'a') as f:
        for line in api.GetStreamFilter(track='something', languages=LANGUAGES):
            print line
    results = api.GetSearch(raw_query="q=from%3Asomething")
    print results
if __name__ == '__main__':
    main()

Monday, December 12, 2016

Use the tweepy to deal with twitter api - part 001.

I will show you how to install the python module named tweepy  and how to make authentication into twitter webpage.
This will install the tweepy python module.
C:\>cd Python27
C:\Python27>cd Scripts
C:\Python27\Scripts>pip install tweepy
Collecting tweepy
Downloading tweepy-3.5.0-py2.py3-none-any.whl
Collecting requests>=2.4.3 (from tweepy)
Downloading requests-2.12.3-py2.py3-none-any.whl (575kB)
100% |################################| 583kB 556kB/s
Collecting requests-oauthlib>=0.4.1 (from tweepy)
Downloading requests_oauthlib-0.7.0-py2.py3-none-any.whl
Requirement already satisfied: six>=1.7.3 in c:\python27\lib\site-packages (from
tweepy)
Collecting oauthlib>=0.6.2 (from requests-oauthlib>=0.4.1->tweepy)
Downloading oauthlib-2.0.1.tar.gz (122kB)
100% |################################| 133kB 506kB/s
Installing collected packages: requests, oauthlib, requests-oauthlib, tweepy
Running setup.py install for oauthlib ... done
Successfully installed oauthlib-2.0.1 requests-2.12.3 requests-oauthlib-0.7.0 tweepy-3.5.0

To deal with twitter api then you need to create a new application into this webpage.
This webpage will give for authentication your date to connect to twitter:
Application Settings
consumer_key=""
consumer_secret=""

Your Access Token
access_token=""
access_token_secret=""

Let's start with a simple example, by using your application settings and access token:
import tweepy
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

consumer_key=""
consumer_secret=""

access_token=""
access_token_secret=""

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

print(api.me().name)

class StdOutListener(StreamListener):
""" A listener handles tweets that are received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print(data)
return True

def on_error(self, status):
print(status)

if __name__ == '__main__':
lista = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

stream = Stream(auth, lista)
stream.filter(track=['internet'])

Using python shell to run this script will show all about 'internet'.
The output will come into raw format.
Let's try another example to update your status with this message:
I using OAuth authentication via Tweepy!
Just add this into my code before class definition:
api.update_status(status='I using OAuth authentication via Tweepy!')
You can rad more about streaming by reading this docs.
For example, I used track from here.