liveBook · Manning

SciPy

As explained in Build a Robo-Advisor with Python (From Scratch)

SciPy is a Python library of algorithms and functions for scientific and numerical computing, including optimization, integration, root-finding, and statistics.

SciPy is a Python library for scientific and numerical computing. In robo-advising, it supplies reusable algorithms for optimization, integration, root-finding, and statistical calculations, with performance-critical subroutines implemented in lower-level languages such as C and Fortran. section 1.4

SciPy is especially useful when a financial decision can be expressed as minimizing or maximizing an objective function. Its scipy.optimize library handles arbitrary functions, including nonconvex ones, through named algorithms such as fmin_<algorithm> and the broader minimize interface. section 10.1.3

Apply SciPy optimization by making the problem and its numerical limitations explicit:

  • Define the objective to optimize, such as a portfolio construction goal. section 10.1.3
  • Select an algorithm through fmin_<algorithm> or minimize, matching its capabilities to the constraints and required derivatives. section 10.1.3
  • Provide an initial guess; constrained problems require an initial guess that already satisfies their constraints. section 10.1.3
  • Check sensitivity to the starting point, because most methods can return different or incorrect solutions when special conditions such as convexity do not hold. section 10.1.3

Portfolio optimization with scipy.optimize

A portfolio construction routine can encode its financial objective and constraints, then call scipy.optimize.minimize with a feasible starting allocation. The result is useful only after checking constraint satisfaction and the effect of alternative starting points. For heavily constrained robo-advisor problems, constructing that feasible starting point may itself be difficult, motivating a modeling layer such as cvxpy instead. section 10.1.3

How Build a Robo-Advisor with Python (From Scratch) covers it

How deep it goes
Explains optimization interfaces, constraints, derivatives, initialization, and nonconvex pitfalls, but stops short of algorithm internals.
Examples
Uses scipy.optimize methods, minimize, objective functions, constraints, gradients, Hessians, and feasible initial guesses.
What it assumes
Assumes basic Python familiarity and requires users to understand objective functions, constraints, and feasible initial guesses.
What you can do after
Apply it via scipy.optimize to formulate and solve numerical optimization problems while testing initialization and constraint limitations.
How it connects
Connects numerical optimization with NumPy, pandas, cvxpy, statistics, integration, and root-finding.

Also explained in

Compare how 2 books explain SciPy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Robo-Advisor with Python (From Scratch). The section links point to the parts of the book it draws on.