Forums  > Software  > Python for Commercial Software Development?  
     
Page 1 of 3Goto to page: [1], 2, 3 Next
Display using:  

IAmEric
Phorgy Phynance
Banned
Total Posts: 2961
Joined: Oct 2004
 
Posted: 2004-11-08 04:21
What do you guys think about beginning a large-scale trading app (trading mechanics, strategies, risk management, visualization) in python? The more computationally intensive stuff will probably be wrapped in C++.

Eric

Patrik
Founding Member

Total Posts: 1179
Joined: Mar 2004
 
Posted: 2004-11-08 09:50

My initial view:

Pros:

  • Rapid development (at least initially)
  • Leverage a lot of free prebuilt libraries (graphs, numerics, etc)
  • You can easily integrate a phyton intepreter and have everything scriptable in an easy way. Cool feature.
  • A lot of people have at least heard about phyton

Cons:

  • If need to specify that it is a phyton based product that might scare some people away (policy reasons, etc)
  • You might run into scalability problems later on in the development. I'm no expert of phyton, but that is a tendency for these types of languages

 


Paper Trading - Capital Structure Demolition, LLC Radiation

manta
Founding Member
B.O.F.H.
Total Posts: 282
Joined: Mar 2004
 
Posted: 2004-11-08 11:58

Hey! Nice to see people discussing Python over here.

I would say that IAmEric has the same motivation I had to think on Python, I mean I had terrible development skills (some C inheritance from the undergrad and nothing more) and I need to program.

So what is the simpler way to program in a OO fashion? I found it to be Python.

Recently I have started the development of a Python based trading platform (am I ambitious or what?). I have completed the graphical interface (wxPython) and the broker connectivity (IB at this time) in less than a week.

The application get the underlying and the option on several maturities. Now it is time to download the Eurodollar rates, build the interest curve and calculate the black volatilities, possible graphing the vol surface, etc.

If there is interest I can post the code.

Best Regards,

Manta


IT unhelpful desk

IAmEric
Phorgy Phynance
Banned
Total Posts: 2961
Joined: Oct 2004
 
Posted: 2004-11-08 14:11
Of course I'm interested! That is what I was about to embark on. I'd love to see how it works.

Cheers,
Eric

Crassus


Total Posts: 1191
Joined: May 2004
 
Posted: 2004-11-08 19:32
What are the advantages of Python compared to Java?

What is best in life? To crush your enemies... to see them driven before you and to hear the lamentation of the women

manta
Founding Member
B.O.F.H.
Total Posts: 282
Joined: Mar 2004
 
Posted: 2004-11-08 20:10
For me it was easier to learn (Hey, but this is just me Smiley )

IT unhelpful desk

Crassus


Total Posts: 1191
Joined: May 2004
 
Posted: 2004-11-09 10:11
compare java and python

What is best in life? To crush your enemies... to see them driven before you and to hear the lamentation of the women

asd


Total Posts: 461
Joined: May 2004
 
Posted: 2004-11-10 02:08

Manta,

 Can you you kindly post your code for the trading platform? It would be pretty exciting to see it.

Many Thanks in advance

 


manta
Founding Member
B.O.F.H.
Total Posts: 282
Joined: Mar 2004
 
Posted: 2004-11-10 03:34

Asd,

Calling it a trading platform a this stage is a joke... Anyway it is in your inbox.


IT unhelpful desk

IAmEric
Phorgy Phynance
Banned
Total Posts: 2961
Joined: Oct 2004
 
Posted: 2004-11-10 03:39
me too? Smiley

eforgyyahoo.com

manta
Founding Member
B.O.F.H.
Total Posts: 282
Joined: Mar 2004
 
Posted: 2004-11-10 11:30

Eric,

It is in your inbox.

Btw, I accept collaboration partners that want to help on my project. Smiley


IT unhelpful desk

rollyHeyHey


Total Posts: 28
Joined: Jun 2004
 
Posted: 2004-11-10 12:00
yes please Manta. 

Tradenator


Total Posts: 1187
Joined: Sep 2006
 
Posted: 2006-11-16 00:39

Looks like I might be solving a problem that has already been solved...long ago.  Does anyone have any advice on time series analysis in python?  Comments on my approach here?

I'm currently defining a time series as a tuple (or at least a pair of variables) of dates,data where dates is a list and data is an array.  I pass the tuples as args into functions, where the manipulation on the data array uses scipy, etc.  If I need to alter the dates (eg fill in non-trading days to week days) then the list approach works well.  One inefficiency is that it seems redundant to always pass in dates regardless of whether they will change or not, but I accept this in order to have a consistent format across all functions.


MadMax


Total Posts: 406
Joined: Feb 2006
 
Posted: 2006-11-16 14:19

Can I receive the code as well ? I had plans to learn Python for a few months already, but did not find time yet to really dig into it. Would be nice to have some finance-related code to look at.

Thanks


signalseeker


Total Posts: 224
Joined: Oct 2006
 
Posted: 2006-11-16 15:00
I might be able to help you more if you post some code, but from what I gather you
have a tuple,
ts = ( [dates], array[data])
and you want to just pass in the array[data] to your functions?

in that case, you can do
foo(ts[1])

Given that you have defined foo as:
def foo(range)

Another approach is that you might want to keep your data and methods together in a class or a closure so that there is no need to pass anything around.

However, everything in python is passed as references, so it is not really inefficient if you are passing the complete tuple as args to your functions.

hope that helps.

The dark is light enough.

Tradenator


Total Posts: 1187
Joined: Sep 2006
 
Posted: 2006-11-16 23:23

My goal is to have a time series toolbox in python that is useful and easy to use.  I'd like it to be flexible to handle various data frequencies (starting with daily), with flexible sized data sets going along with any set of dates.

As you will be able to tell, I am new at this, planning to learn OO for a later version.  I would have thought this would have been already done by now but I couldn't find it in the cheese shop.  I'm using Enthought 2.4 on a winXP lapdog, and have not been able to get gnuplot or VTK to work either.  (I believe I have the paths set correctly.)  For references I am using the python docs and this book.

Attached File: py code.zip

pytso.py - time series functions

pyopt.py - a first attempt at python, some dodgy options pricing/greeks functions

test.py - use to test pytso.py, dumping output to a csv file for comparison to excel.

In order to use pytso or test, the first step is to upload data.  See calcrets in pytso for this.  You may need to modify it to fit your data.  My raw data (NYMEX: CL) came to me like this from Unfair Advantage:

Attached File: CL.zip

"Another approach is that you might want to keep your data and methods together in a class or a closure so that there is no need to pass anything around."

I'll google "closure" to find out what those are.

 

 


tristanreid


Total Posts: 1676
Joined: Aug 2005
 
Posted: 2006-11-17 03:53

"Another approach is that you might want to keep your data and methods together in a class or a closure so that there is no need to pass anything around."

I'll google "closure" to find out what those are.

A closure is functional programming. You have blocks of code in functions that can access local data. So to understand what I just said, first learn what the lambda operator does.  I only learned enough python to understand others' code, so I might make a syntactical error, but this should be the idea:

Here's what lambda does:

>>>def make_power_operator (n): return lambda x: x**n

>>>sqrt = make_power_operator(.5)

>>>square = make_power_operator(2)

>>>sqrt(16)

4

>>>square(16)

256

So that's lambda. It comes in even more handy with more complex functions, obviously, and you often see it used with 'filter'. The idea of filter is that you pass in a condition (using lambda) and filter will operate on a list, returning only the items that meet the condition.  Like this:

>>> numlist = [12, 99, 18, 77]
>>> def is_even(n): return lambda x: x%2==0
>>> filter(is_even, numlist)

[12,18]

Another python feature similar to filter is 'map'. It takes a function and a collection, and returns the result of executing the function on each item in the collection.  Like this:

>>> nums = [2, 4, 5, 6]
>>> map(square,nums)

[4, 16, 25, 36]

Ok, so that's enough about lambda to understand closures. A closure is where you define a function inside of another function, and the inner function can access variables that are local to the outer function. Like this: uh, I'm tired of typing >>>

def totalSquares(numlist)

    totalSquares = 0

    def addSqrToTotal(x): totalSquares=totalSquares+square(x)

     map(addSqrToTotal,numlist)

return totalSquares

The thing is, python doesn't fully support closures, so that will give you an error. The totalSquares variable in 'addSqrToTotal' is different from the totalSquares in 'totalSquares'. But you can fix it by using a list:

def totalSquares(numlist)

    totalSquares = [0]

    def addSqrToTotal(x): totalSquares[0]=totalSquares[0]+square(x)

     map(addSqrToTotal,numlist)

return totalSquares[0]

 

-t. 


the only reason it would be easier to program in C is that you can't easily express complex problems in C, so you don't. -comp.lang.lisp

Tradenator


Total Posts: 1187
Joined: Sep 2006
 
Posted: 2006-11-17 04:31

signalseeker and tristanreid, many thanks.  There is much to learn.


signalseeker


Total Posts: 224
Joined: Oct 2006
 
Posted: 2006-11-17 14:40
> The thing is, python doesn't fully support closures, so that will give you an error. The totalSquares variable in 'addSqrToTotal' is different from the totalSquares in 'totalSquares'. But you can fix it by using a list:

Actually, this has been fixed in some version of python I don't remember and is slated to appear in python 3 if I am not mistaken.

For now, you can enable nested scopes by
from __future__ import nested_scopes

In that case, tristanreid's example will work seemlessly.


The dark is light enough.

tristanreid


Total Posts: 1676
Joined: Aug 2005
 
Posted: 2006-11-17 17:18

Very cool.  Thanks for the info.

Can we keep this thread going with more simple examples, illustrating the language and how it's changed? Besides being a python dilettante, I've been working with much older versions of python, I'm largely unaware of what's gone on.  I only recently learned the 'yield' keyword.

If you think about it, adding the yield keyword was very unfriendly to those with lots of fixed income code.  I don't think they were fully consulted about it. Scared Anyway, here's an example of the yield keyword; it lets you create a function that may be called multiple times, and maintains a state.  Like this:

>>> def pows2Until(n):
...     i=1
...     while i<n:
...             yield i
...             i*=2
...
>>> for i in pows2Until(100):
...     print i
...
1
2
4
8
16
32
64

I know there are other python sites out there, maybe this is unnecessary.  But I'm hoping we can build up to something more complicated than illustrating the basics of the language, something domain specific?

-t.


the only reason it would be easier to program in C is that you can't easily express complex problems in C, so you don't. -comp.lang.lisp

signalseeker


Total Posts: 224
Joined: Oct 2006
 
Posted: 2006-11-17 19:06
tristanreid,

I am all for idea of keeping this thread going with examples. But like you suggested, I think it will be better if we build something useful. How about building the timeseries tool box that tradenator is writing?

tradenator,

I have never used enthought, so cannot comment about the installation issues you are having. For that matter, I only use python on linux. Are you using enthought for any particular reason? All the modules that you are using can be downloaded independantly and installed pretty easily. Regarding vkt, I have used it couple of years back for some image segmentation work. In my opinion, it is rather heavy duty and best avoided if you do not have a very good reason to use it. Take a look at this for plotting, it is very simple and can get you started in 5 mins.

The dark is light enough.

tristanreid


Total Posts: 1676
Joined: Aug 2005
 
Posted: 2006-11-17 20:23

tristanreid,

I am all for idea of keeping this thread going with examples. But like you suggested, I think it will be better if we build something useful. How about building the timeseries tool box that tradenator is writing?

I'm all for it.  One question though: at what level do we start?  We could build everything from scratch or we could use open-src libraries like numpy (which has linear alg. routines), and scipy (includes fft and some stats stuff) and build time series specific interfaces on top of that.  I don't have experience with either of those libraries, I'd love to learn, but I'd also love to just write stuff.  Whatever's clever, I'm happy either way.

One thing that could be fun is to pick a particular time-series problem, and learn how to use numpy/scipy to solve the problem, then to expand the solution to make it as generic as possible, then to argue about a better way to do it.  Then repeat. 

-t.


the only reason it would be easier to program in C is that you can't easily express complex problems in C, so you don't. -comp.lang.lisp

IAmEric
Phorgy Phynance
Banned
Total Posts: 2961
Joined: Oct 2004
 
Posted: 2006-11-17 20:42
The only thing about keeping this thread alive is that it brings back painful memories. When I wrote this, I was unemployed, had a mortgage payment I couldn't make, wife was living in a different city, I was basically living in an internet cafe, and was desparate enough to consider starting my own software company.

Aside from that, feel free Big Smile

Tradenator


Total Posts: 1187
Joined: Sep 2006
 
Posted: 2006-11-17 23:54

<sniff> <sniff> I was once unemployed, living with my new mother-in-law in a 2 bedroom apartment in a foreign country, with my dog in quarantine.  I was so desparate I accepted a job doing y2k project management in the end.

I selected Enthought on the advice of the book I have (link earlier in the thread) and because they have things packaged up together nicely for a noob like me.  I'll put biggles on the list of things to try (thanks signalseeker).

I think scipy's distribution functions and numpy/scipy arrays are worth using.  I'd be happy to collaborate on this, but I am not the right person to be leading it. Following tristanreid's approach, we could start with the movav and movsd functions I posted below.  Assuming I have a series of dates,data what would a better approach to these be?  Also, I was thinking of having a third item in the tuple carrying descriptive info like market, what the data is, and so on.  This could be useful if/when data becomes a 2-D array, such as a set of returns for my universe of commodity markets that I can pass through the movav function all together.

Should this be tagged as a new thread or does it matter?


signalseeker


Total Posts: 224
Joined: Oct 2006
 
Posted: 2006-11-20 16:50

I think we should go with numpy/scipy. I know them at a very introductary level and would like to further my knowledge. So, how about we start with some basic functions for tradenator's module and then move towards a particular time-series problem?

Does anyone have any suggestions?

Also, do we have the admin's blessings to proceed with this?


The dark is light enough.
Previous Thread :: Next Thread 
Page 1 of 3Goto to page: [1], 2, 3 Next