SERVING THE QUANTITATIVE FINANCE COMMUNITY

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

Re: Python tricks

October 10th, 2019, 3:40 pm

that's python IDE is easier
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 11th, 2019, 7:51 am

that's python IDE is easier
I sugested pyCharm. My student loves it! No looking back, goodbye VS and parallels for her. We keep the infrastructure threshold low. The rest is plain sailing.
Merci, Farid.
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 17th, 2019, 1:56 pm

Is this a bug in Python?
import pandas as pd
from pandas import datetime, period_range

#compiles
#myRange = pd.period_range('2000-01-01', periods=12, freq='T')
#ts  = pd.Series(range(12), index=myRange)

#NOT compile
range = pd.period_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range)

ts.index = ts.index.astype('datetime64[ns]')
data_higher_freq = ts.resample('5T').sum()
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
FaridMoussaoui
Posts: 507
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

Re: Python tricks

October 17th, 2019, 2:52 pm

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 17th, 2019, 4:51 pm

Even more interesting I accidentally had a range() function and this is the one that resample() sees. Ouch
Very bad.I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

Q: The ability to override core Python functions with impunity,feature or bug?

Code:
 
def range(i):
    print ("range")
    return 1/0

 
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

October 17th, 2019, 4:58 pm

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
range is a function, not an object
?
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
tagoma
Topic Author
Posts: 18385
Joined: February 21st, 2010, 12:58 pm

Re: Python tricks

October 20th, 2019, 8:49 am

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
range is a function, not an object
?
Python allows built-in functions overloading. Bad or good is mental masturbation. That's just the way it is. Programmer is supposed to have come through the list of these built-in functions at some point, and understands it is usually bad practice to use those name to create object/functions/etc. To somewhat circumvent the issue, programmer can use scope/namespace tricks.

import builtins
builtins.range(10)
#range(0, 10)


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

Re: Python tricks

October 20th, 2019, 9:56 am

Nice. So, one can put functions and so on in modules which is good practice. System decomposition into independent and loosely coupled modules is recommended before jumping head first into coding marathons.
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
ISayMoo
Posts: 2368
Joined: September 30th, 2015, 8:30 pm

Re: Python tricks

November 1st, 2019, 4:45 pm

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

Re: Python tricks

November 23rd, 2019, 1:23 pm

Python 3.8 introduced the Walrus operator.
What are the cons according to you Wilmotters?
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

February 14th, 2020, 4:18 pm

Am getting issues when installing packages in Pycharm, VS and Anaconda.
Any ideas?
Collecting clawpack
  Using cached clawpack-5.6.1.tar.gz (5.7 MB)
ERROR: The tar file (C:\Users\ABC\AppData\Local\Temp\pip-unpack-vv069ogw\clawpack-5.6.1.tar.gz) has a file (C:\Users\ABC1\AppData\Local\Temp\pip-install-3y0_4wxk\clawpack\pyclaw/
development/point_wise_rs/pyWrapperForRiemannSolver/aux.npy) trying to install outside target directory (C:\Users\ABC\AppData\Local\Temp\pip-install-3y0_4wxk\clawpack)
----- Failed to install 'clawpack' -----

My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
FaridMoussaoui
Posts: 507
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

Re: Python tricks

February 14th, 2020, 6:35 pm

Who is user "ABC1"? a typo in your target directory?
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

February 14th, 2020, 7:31 pm

Who is user "ABC1"? a typo in your target directory?
No, I changed the real name to ABC. That directory exists.

BTW my problem is well-known.

https://stackoverflow.com/questions/52949531/could-not-install-packages-due-to-an-environmenterror-errno-13/53916143
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
FaridMoussaoui
Posts: 507
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

Re: Python tricks

February 14th, 2020, 7:57 pm

That's not the correct link. Your error arise in the pip file unpacking.py
 
User avatar
Cuchulainn
Posts: 63378
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Python tricks

February 14th, 2020, 8:36 pm

That's not the correct link. Your error arise in the pip file unpacking.py
uh! Is that a bug in Python?
What next?
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl
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