• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Python Questions

I am interested in Python design issues. Any good books on Design Patterns in Python?
I am also looking for a precise/compact treatment of how Python does the Functional Programming model.

Thanks!

@pingu
@APalley
 
Last edited:
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!

some good books on python that focus on mathematics

amit saha - doing math with python
yahya osais - computer simulation
jose garrido - computational models with python
jose unpingco - python for probability, statistics and machine learning
anything written by yves hilpsich (e.g., python for finance - analyze big financial data)
fabio nelli - python data analytics
jaan kiusalaas - numerical methods in engineering with python
ivan idris - numpy cookbook
 
some good books on python that focus on mathematics

amit saha - doing math with python
yahya osais - computer simulation
jose garrido - computational models with python
jose unpingco - python for probability, statistics and machine learning
anything written by yves hilpsich (e.g., python for finance - analyze big financial data)
fabio nelli - python data analytics
jaan kiusalaas - numerical methods in engineering with python
ivan idris - numpy cookbook
I had a look at the contents; the price spread is $[39,118]. The price seems to be a monotonic function on how fancy the title seems to be.

A general remark/question; is it necessary to devote the first X chapter to basic stuff. Can we not just assume stuf like variables, loops etc.?
 
How about
1. "Python for Option Pricing (analytical, binomial, PDE, SDE, MC etc.)". Build on all those lovely libraries.
2. "42"
3. "Creating Object and Functional Programming Applications in Python A Design Patterns Approach" with focus the stuff in 1.
 
Stupid question:
I use VS2017 and I have all Python libraries installed, including anaconda etc.

I want to run anaconda navigator but

1. I don't see it on my desktop
2. I don't know how to run it from VS2017 (I don't even know if it is even possible)

Any ideas? Thanks!

//
Solved.
 
Last edited:
This code does not build because it cannot find pyconfig.h
Any ideas (Visual Studio 2017 and Python 3.6)?

C++:
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

char const* greet()
{
   return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}
 
Numerical Python by Robert Johansson. It covers a broad range of numerical methods from ODE, PDE to optimization, probability, statistics, data science.

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!
 
Last edited:
Python does have its own view of what private attributes/member data are..

C++:
class PointTest: 
# Counterexample: class with "private" attributes
    def __init__(self,x=-10, y=0): #default values
        self.move(x,y)

    def move(self, x, y):   
        self._x = x
        self._y = y
        self.__x = x
        self.__y = y

    def printI(self):
         print (self._x, self._y)
 
    def printII(self):
         print (self.__x, self.__y)

pp = PointTest(1,2)
pp._x = -1; pp._y = -2
print("Private in name only? (PINO)")
print(pp._x); print(pp._y); #-1, -2
#print(pp.__x); print(pp.__y); #AttributeError

pp.printI() #(-1,-2)
pp.printII() #(1,2)
 
Is this a bug in Python?
(in fairness, using 'range' in 3 different ways is real bad programming style)

C++:
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()
 
You are redefining range in line 9. So in line 10 when you call range(12) now you are trying to call the PeriodIndex range, not the function range. That's why it fails.
 
'range' is ambiguous. The issue can be resolved if we could put the function range() in a namespace (like std::range()), which is better programming practice. But I don't know if this I possible.
Plan B: call it range1 and be done with it.

Fair enough.
 
Even this doesn't compile (BTW I am trying to break the compiler). I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

C++:
range = 12
range1 = pd.date_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range1)
 
Last edited:
Even more interesting I accidentally had a range() function and this is the one that resample() sees. Ouch
Very bad.

C++:
def range(i):
    print ("range")
    return 1/0
 
Even this doesn't compile (BTW I am trying to break the compiler). I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

C++:
range = 12
range1 = pd.date_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range1)

range in Python is a generator object actually. So, its defined as range(start,stop=Null,step=Null) and yields start+step*index when its iterated over.
What helped me from moving from C++ to Python was this book (first two chapters) Data Structures and Algorithms in Python: Amazon.in: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser: Books

Its not a keyword like lambda
 
Even this doesn't compile (BTW I am trying to break the compiler). I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

C++:
range = 12
range1 = pd.date_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range1)
again, you are re-defining what range is. Python allows you to do that. Functions are first class citizens.
 
Even this doesn't compile (BTW I am trying to break the compiler). I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

C++:
range = 12
range1 = pd.date_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range1)
This is not an undocumented keyword. It's a library function and you are allowed in python to do rename/re-define anything that is not a reserved keyword. Here is the list of keywords 2. Lexical analysis — Python 3.8.0 documentation

This is very well documented. You need to learn the standard library first.
 
Back
Top