SERVING THE QUANTITATIVE FINANCE COMMUNITY

  • 1
  • 3
  • 4
  • 5
  • 6
  • 7
  • 14
 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

May 22nd, 2019, 2:01 pm

Be careful around the memory leaks in Pandas.
I suppose memory management in the Python-C twilight zone is tricky.
BTW library looks nice.
 
User avatar
berndL
Posts: 171
Joined: August 22nd, 2007, 3:46 pm

Re: Python tricks

May 23rd, 2019, 6:24 pm

  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.
 
User avatar
rmax
Posts: 6080
Joined: December 8th, 2005, 9:31 am

Re: Python tricks

June 4th, 2019, 1:12 pm

 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

June 18th, 2019, 8:07 am

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

funcs = [multiply, add, expo]

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)

 
User avatar
tagoma
Topic Author
Posts: 18255
Joined: February 21st, 2010, 12:58 pm

Re: Python tricks

June 24th, 2019, 2:08 pm

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

funcs = [multiply, add, expo]

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
add = lambda x: x+x
expo = lambda x: np.exp(x)

funcs = [multiply, add, expo]

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.
 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

June 24th, 2019, 2:32 pm

ImageOh, 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).
 
User avatar
ExSan
Posts: 4548
Joined: April 12th, 2003, 10:40 am

Re: Python tricks

July 8th, 2019, 11:10 pm

ImageOh, 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
 
User avatar
ISayMoo
Posts: 1988
Joined: September 30th, 2015, 8:30 pm

Re: Python tricks

July 9th, 2019, 7:16 am

 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

July 9th, 2019, 11:06 am

 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

July 9th, 2019, 11:08 am

Python does not support private attributes/member data (?)
 
User avatar
ExSan
Posts: 4548
Joined: April 12th, 2003, 10:40 am

Re: Python tricks

July 9th, 2019, 12:11 pm

Thanks!!! Now I have no excuses to retake my project!
 
User avatar
FaridMoussaoui
Posts: 412
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

Re: Python tricks

July 9th, 2019, 1:04 pm

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.
 
User avatar
tagoma
Topic Author
Posts: 18255
Joined: February 21st, 2010, 12:58 pm

Re: Python tricks

July 9th, 2019, 2:32 pm

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
 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

July 9th, 2019, 4:01 pm

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.
 
User avatar
Cuchulainn
Posts: 59669
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

July 9th, 2019, 4:02 pm

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.
ABOUT WILMOTT

PW by JB

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


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

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


GZIP: On