SERVING THE QUANTITATIVE FINANCE COMMUNITY

• 1
• 3
• 4
• 5
• 6
• 7
• 17

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Be careful around the memory leaks in Pandas.
I suppose memory management in the Python-C twilight zone is tricky.
BTW library looks nice.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

berndL
Posts: 171
Joined: August 22nd, 2007, 3:46 pm

### Re: Python tricks

1. I am looking for books on Numpy and Scipy, with focus on the numerical algorithms and background. I am not interested in having to wade in syntax before getting to these topics.

Any suggestions? Thx!
Not a book but maybe also interesting if you look at numpy. Take a look at cupy.

Lets you run the same code on either cpu or gpu by just setting a switch methode.

rmax
Posts: 6080
Joined: December 8th, 2005, 9:31 am

### Re: Python tricks

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

The Joy of FP
multiply = lambda x: x*x
expo = lambda x: exp(x)

input = [1,2,3,4]

for func in funcs:
value = list(map(func, a))
print(value)

for i in range(4):
values = map(lambda x: x(i), funcs)
print(values)


http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

tagoma
Topic Author
Posts: 18351
Joined: February 21st, 2010, 12:58 pm

### Re: Python tricks

The Joy of FP
multiply = lambda x: x*x
expo = lambda x: exp(x)

input = [1,2,3,4]

for func in funcs:
value = list(map(func, a))
print(value)

for i in range(4):
values = map(lambda x: x(i), funcs)
print(values)



You probably need numpy or math (or cmath!?).
Variable a is not defined.
I would go for list comprehension. (sorry I previously typed in 'list a comprehension').

import numpy as np

multiply = lambda x: x*x
expo = lambda x: np.exp(x)

input = [1,2,3,4]

[list(map(func, input)) for func in funcs]
Last edited by tagoma on June 24th, 2019, 3:15 pm, edited 2 times in total.

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Oh, a = [1,2,3]

BTW OOP in Python is a real shocker. Still, it is probably good for scaffolding to prevent cognitive overload?

Funny name, 'comprehension', C++ STL calls it 'transform' and more generic (ignore that remark).
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

ExSan
Posts: 4550
Joined: April 12th, 2003, 10:40 am

### Re: Python tricks

Oh, a = [1,2,3]

BTW OOP in Python is a real shocker. Still, it is probably good for scaffolding to prevent cognitive overload?

Funny name, 'comprehension', C++ STL calls it 'transform' and more generic (ignore that remark).
I spent some time trying to implement  abstract data structure Red-Black tree. I just gave up. It gets very complicated in python. Coding it using C/C++  is not easy, but a real nightmare in Python. My idea was to reproduce a master template I already coded in C

ISayMoo
Posts: 2276
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Python does not support private attributes/member data (?)
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

ExSan
Posts: 4550
Joined: April 12th, 2003, 10:40 am

### Re: Python tricks

Thanks!!! Now I have no excuses to retake my project!

FaridMoussaoui
Posts: 507
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

### Re: Python tricks

If you have a working library in C/C++, you can use it as a shared library in python through Boost.Python. No need to reinvent the wheel.

tagoma
Topic Author
Posts: 18351
Joined: February 21st, 2010, 12:58 pm

### Re: Python tricks

Python does not support private attributes/member data (?)
Not really (You already know it, don't you?).

https://docs.python.org/3.7/tutorial/classes.html#tut-private

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

If you have a working library in C/C++, you can use it as a shared library in python through Boost.Python. No need to reinvent the wheel.
Indeed.
Creating rb trees in Python must be the closest thing to torture.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

Cuchulainn
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Python does not support private attributes/member data (?)
Not really (You already know it, don't you?).

https://docs.python.org/3.7/tutorial/classes.html#tut-private
This is scary. Meshuggah.

It's just this subtle point will be lost on newbies going forward.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...

 JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...

GZIP: On