Most viewed recipes by alexander baker http://code.activestate.com/recipes/users/4166679/views/2015-03-05T15:59:30-08:00ActiveState Code Recipeshow to create a windows service in python (Python) 2008-08-26T01:32:47-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/ <p style="color: grey"> Python recipe 576451 by <a href="/recipes/users/4166679/">alexander baker</a> . </p> <p>The following code snippet shows you have to create a windows service from a python script. The most important thing here is the username and password, if you ignore supplying these the server will never start and you will get a message saying that the service has not responded in time, this is a red herring. The default account that the pythonservice wrapper uses is not permissioned to run the service. </p> A simple KD Tree example with custom Euclidean distance ball query. (Python) 2013-01-24T10:28:24-08:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578434-a-simple-kd-tree-example-with-custom-euclidean-dis/ <p style="color: grey"> Python recipe 578434 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>In computer science, a k-d tree (short for k-dimensional tree) is a space-partitioning data structure for organizing points in a k-dimensional space. k-d trees are a useful data structure for several applications, such as searches involving a multidimensional search key (e.g. range searches and nearest neighbor searches). k-d trees are a special case of binary space partitioning trees.</p> <p><a href="http://en.wikipedia.org/wiki/K-d_tree" rel="nofollow">http://en.wikipedia.org/wiki/K-d_tree</a></p> Hartree Fock SCF (Python) 2013-04-30T09:09:20-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578515-hartree-fock-scf/ <p style="color: grey"> Python recipe 578515 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/physics/">physics</a>). Revision 4. </p> <p>Quantum Chemistry technique to calculate various interesting operators for HeH.</p> Newton Raphson Root Finding (Python) 2009-05-19T05:18:00-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576762-newton-raphson-root-finding/ <p style="color: grey"> Python recipe 576762 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/scipy/">scipy</a>). </p> <p>Newton Raphson Root Finding</p> Conway's Game of Life In Python (Python) 2013-06-13T15:33:41-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578559-conways-game-of-life-in-python/ <p style="color: grey"> Python recipe 578559 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/life/">life</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/of/">of</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>Conway's Game of Life In Python</p> Convolving Gaussian (Python) 2009-05-19T05:23:48-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576764-convolving-gaussian/ <p style="color: grey"> Python recipe 576764 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Convolving Gaussian</p> Brownian Motion of Stock (Python) 2009-05-19T05:16:29-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576760-brownian-motion-of-stock/ <p style="color: grey"> Python recipe 576760 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/finance/">finance</a>). </p> <p>Brownian Motion of a Stock</p> Simple FIFO trading model for pnl (Python) 2015-02-10T13:34:48-08:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/579024-simple-fifo-trading-model-for-pnl/ <p style="color: grey"> Python recipe 579024 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/pnl/">pnl</a>, <a href="/recipes/tags/trading/">trading</a>). Revision 2. </p> <p>Simple approach to calculating FIFO pnl.</p> Simple way to find number of perfect square numbers in a range. (Python) 2015-03-05T15:59:30-08:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/579031-simple-way-to-find-number-of-perfect-square-number/ <p style="color: grey"> Python recipe 579031 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/complex/">complex</a>, <a href="/recipes/tags/fun/">fun</a>, <a href="/recipes/tags/interview/">interview</a>, <a href="/recipes/tags/maths/">maths</a>, <a href="/recipes/tags/range/">range</a>). </p> <p>The strategy here is not to iterate through the set of possible integer values and check for is_perfect_square() each time but to translate the upper and lower values to either complex or real space of square numbers.</p> <pre class="prettyprint"><code> # O(n) complexity len([x for x in range(0, 100) if x!= 0 and float(math.sqrt(x)).is_integer()]) so if a and b positive then we count the number of integer values between upper and lower sqrt() values if either a or b are negative then we need to use the complex number space for the sqrt() results. In this case we are still counting integer values either along the imaginary or real axis, the result is then a simple sum if both a and b are negative we need to make sure that when walking down the same imaginary axis we dont count the same inteters twice, in this case we can take the min(a,b) to get max distinct set of integer values. </code></pre> Spherical Polar Coordinates (Python) 2008-08-26T08:49:39-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576457-spherical-polar-coordinates/ <p style="color: grey"> Python recipe 576457 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/mechanics/">mechanics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/polar/">polar</a>, <a href="/recipes/tags/quantum/">quantum</a>). </p> <p>Spherical Polar Coordinates <a href="http://www.alexfb.com/cgi-bin/twiki/view/PtPhysics/Spherical-Polar-Coordinates-Python" rel="nofollow">http://www.alexfb.com/cgi-bin/twiki/view/PtPhysics/Spherical-Polar-Coordinates-Python</a></p> Quick Numerical Integration (Python) 2009-05-19T05:24:37-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576765-quick-numerical-integration/ <p style="color: grey"> Python recipe 576765 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/integration/">integration</a>, <a href="/recipes/tags/scipy/">scipy</a>). </p> <p>Quick Numerical Integration</p> zero curve bootstrapping and forward curve generation (Python) 2012-09-10T08:07:56-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578257-zero-curve-bootstrapping-and-forward-curve-generat/ <p style="color: grey"> Python recipe 578257 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/finance/">finance</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/sympy/">sympy</a>). </p> <p>example of a bootstrapping and forward curve generation this can be used to build a set of curves for different currencies</p> pauli spin matricies (Python) 2008-08-26T01:52:06-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576458-pauli-spin-matricies/ <p style="color: grey"> Python recipe 576458 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/kron/">kron</a>, <a href="/recipes/tags/ladder/">ladder</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/pauli/">pauli</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/spin/">spin</a>). </p> <p>simple spin investigation in python</p> Script that compares various Interest Rate term structure models. (Python) 2012-09-10T08:02:34-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578256-script-that-compares-various-interest-rate-term-st/ <p style="color: grey"> Python recipe 578256 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/finance/">finance</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>A common model used in the financial industry for modelling the short rate (think overnight rate, but actually an infinitesimally short amount of time) is the Vasicek model. # Although it is unlikely to perfectly fit the yield curve, it has some nice properties that make it a good model to work with. The dynamics of the Vasicek model are describe below.</p> <p>In this model, the parameters are constants, and the random motion is generated by the Q measure Brownian motion . An important property of the Vasicek model is that the interest rate is mean reverting to , and the tendency to revert is controlled by . Also, this process is a diffusion process, hence Markovian, which will lead to some nice closed form formulas. Finally, the future value of the interest rate is normally distributed with the distribution .</p> Locate and see the biggest cross in a random matrix (Python) 2013-09-13T13:31:03-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578657-locate-and-see-the-biggest-cross-in-a-random-matri/ <p style="color: grey"> Python recipe 578657 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>). </p> <p>Interesting search space problem.</p> Monte Carlo Engine : Simple Head Tail Model (Python) 2014-04-27T17:25:25-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578868-monte-carlo-engine-simple-head-tail-model/ <p style="color: grey"> Python recipe 578868 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/strategy/">strategy</a>). Revision 2. </p> <p>Wanted to implement something that shows how the simple framework can be used to investigate a basic heads and tail game. The betting strategy can be varied simply by changing the logic in the ontrail() method. This currently tests the double or quits strategy. Run it to see how many </p> Simple model to predict UK Interest Rates (Python) 2014-06-13T14:29:36-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578891-simple-model-to-predict-uk-interest-rates/ <p style="color: grey"> Python recipe 578891 by <a href="/recipes/users/4166679/">alexander baker</a> . </p> <p>A common model used in the financial industry for modelling the short rate (think overnight rate, but actually an infinitesimally short amount of time) is the Vasicek model. # Although it is unlikely to perfectly fit the yield curve, it has some nice properties that make it a good model to work with. The dynamics of the Vasicek model are describe below.</p> <p>In this model, the parameters are constants, and the random motion is generated by the Q measure Brownian motion . An important property of the Vasicek model is that the interest rate is mean reverting to , and the tendency to revert is controlled by . Also, this process is a diffusion process, hence Markovian, which will lead to some nice closed form formulas. Finally, the future value of the interest rate is normally distributed with the distribution .</p> Monte Carlo Engine : Stochastic Interest Rate Predictor (Python) 2014-04-27T16:42:29-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578867-monte-carlo-engine-stochastic-interest-rate-predic/ <p style="color: grey"> Python recipe 578867 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/interest/">interest</a>, <a href="/recipes/tags/model/">model</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/rate/">rate</a>). Revision 2. </p> <p>This is a simple Monte Carlo Engine model, based on some ideas from the Quantopian folks. The idea is that the model and the engine are separate. I have integrated a simple example from an earlier post. The idea was to try and build some game theory simulations using simple models that were separate from the Engine. </p> principal component analysis (Python) 2009-07-29T06:18:40-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576459-principal-component-analysis/ <p style="color: grey"> Python recipe 576459 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/eigenvectors/">eigenvectors</a>). Revision 2. </p> <p>simple pca</p> Lancos Gamma Approximation (Python) 2009-05-19T05:19:15-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576763-lancos-gamma-approximation/ <p style="color: grey"> Python recipe 576763 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/gamma/">gamma</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Lancos Gamme Approximation</p>