Python Bustlings

Loading a library in python from a local path


If all else fails, and you really do want to edit your source code, you’ll need to edit sys.path. sys.path is a list of locations where Python will look for code.

In your code, write:

import sys

import tweepy

Creating a class in python

Code Example 6 – the Shape class
class Shape:
    def __init__(self,x,y):
        self.x = x
        self.y = y
    description = "This shape has not been described yet"
    author = "Nobody has claimed to make this shape yet"
    def area(self):
        return self.x * self.y
    def perimeter(self):
        return 2 * self.x + 2 * self.y
    def describe(self,text):
        self.description = text
    def authorName(self,text): = text
    def scaleSize(self,scale):
        self.x = self.x * scale
    self.y = self.y * scale

source :

Making own library in python

My Readings 1 – Stochastic Processes Sheldon Ross – Preliminaries

Three axioms of probability

In probability theory, Boole’s inequality, also known as the union bound, says that for any finite or countable set of events, the probability that at least one of the events happens is no greater than the sum of the probabilities of the individual events.

Computational Investing Wiki


Passing by reference : This means that if we do in python

fred = squareArray

and then fred[1,1] = 0

Python does not make a copy of squareArray, rather its just passed as a reference, hence by changing fred[1,1], squareArray also gets changed.

Whereas if we want to pass by value something like

fred = squareArray.copy() should be done.

the general formula for the variance of returns for a portfolio is:

σ²(port) = ΣΣw(i)w(j)σ(i)σ(j)ρ(i,j)

where the first sum is taken over all is, and the second over all js.  Thus, for a 5-asset portfolio, the formula would be:

σ²(port) = w1²σ1² + w2²σ2² + w3²σ3² + w3²σ3² + w5²σ5²

+ 2w1w2σ1σ2ρ(1,2) + 2w1w3σ1σ3ρ(1,3) + 2w1w4σ1σ4ρ(1,4) + 2w1w5σ1σ5ρ(1,5)

+ 2w2w3σ2σ3ρ(2,3) + 2w2w4σ2σ4ρ(2,4) + 2w2w5σ2σ5ρ(2,5)

+ 2w3w4σ3σ4ρ(3,4) + 2w3w5σ3σ5ρ(3,5)

+ 2w4w5σ4σ5ρ(4,5)

ρ is covariance