main

2022/02/11

statsmodels (a good stats package)

 In [1]: import numpy as np

In [2]: import statsmodels.api as sm

In [3]: import statsmodels.formula.api as smf

# Load data
In [4]: dat = sm.datasets.get_rdataset("Guerry", "HistData").data

# Fit regression model (using the natural log of one of the regressors)
In [5]: results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()

# Inspect the results
In [6]: print(results.summary())

matplotlib plot settings

method 1 

import matplotlib

matplotlib.rc('xtick', labelsize=20)

matplotlib.rc('ytick', labelsize=20)

matplotlib.rc('font',family='sans-serif', size=12)


 

method 2

import matplotlib.pyplot as plt

 

SMALL_SIZE = 8

MEDIUM_SIZE = 10

BIGGER_SIZE = 12

 

plt.rc('font', size=SMALL_SIZE)          # controls default text sizes

plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title

plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels

plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels

plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels

plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize

plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title

 

method 3

matplotlib.rc('xtick', labelsize=20)

matplotlib.rc('ytick', labelsize=20)

matplotlib.rc('font', size=20)

matplotlib.rc('axes', titlesize=20)

matplotlib.rc('axes', labelsize=20)

matplotlib.rc('legend', fontsize=20)

matplotlib.rc('figure', titlesize=20)

 


method 4

#size=25

size=15

params = {'legend.fontsize': 'large',

          'figure.figsize': (20,8),

          'axes.labelsize': size,

          'axes.titlesize': size,

          'xtick.labelsize': size*0.75,

          'ytick.labelsize': size*0.75,

          'axes.titlepad': 25}

plt.rcParams.update(params)

 

2022/02/09

beta-PERT Monte Carlo Simulation

 Here, we are running Beta-PERT Monte Carlo simulation.


from scipy import stats as stats

from scipy.stats import beta as beta

from scipy.stats import rv_continuous


import matplotlib.pylab as plt


class Beta_PERT(rv_continuous):

    def _shape(self, minimum, mode, maximum, lamb):

        alpha = 1+lamb*(mode-minimum)/(maximum-minimum)

        beta = 1+lamb*(maximum-mode)/(maximum-minimum)

        return [alpha,beta]

    

    def _cdf(self,x, minimum, mode, maximum, lamb):

        s_alpha, s_beta = self._shape(minimum, mode, maximum, lamb)

        z = (x-minimum)/(maximum-minimum)

        cdf = beta.cdf(z,s_alpha,s_beta)

        return cdf

    

pert = Beta_PERT(name="pert")


rv_1 = pert(0.02,0.05,0.2,4)

rv_2 = pert(1,5,20,4)


N = 5000


freq = rv_1.rvs(N)

loss = rv_2.rvs(N)


ALE = freq*loss





2021/12/07

Common hedging strategies

  1. Long/Short Equity Strategy 
  2. Market Neutral Strategy 
  3. Merger Arbitrage Strategy 
  4. Convertible Arbitrage Strategy 
  5. Capital Structure Arbitrage Strategy 
  6. Fixed-Income Arbitrage Strategy 
  7. Event-Driven Strategy 
  8. Global Macro Strategy 
  9. Short Only Strategy
https://www.wallstreetmojo.com/hedge-fund-strategies/

2021/10/21

L1 and L2 loss function

 http://www.chioka.in/differences-between-l1-and-l2-as-loss-function-and-regularization/

2021/07/18

Deterministic Finite Automaton (DFA)

 https://en.wikipedia.org/wiki/Deterministic_finite_automaton


Check a valid number or a valid decimal number DFA graph:



class Solution(object):

    def isNumber(self, s):

        # This is the DFA we have designed above

        dfa = [

            {"digit": 1, "sign": 2, "dot": 3},

            {"digit": 1, "dot": 4, "exponent": 5},

            {"digit": 1, "dot": 3},

            {"digit": 4},

            {"digit": 4, "exponent": 5},

            {"sign": 6, "digit": 7},

            {"digit": 7},

            {"digit": 7}

        ]

        

        current_state = 0

        for c in s:

            if c.isdigit():

                group = "digit"

            elif c in ["+", "-"]:

                group = "sign"

            elif c in ["e", "E"]:

                group = "exponent"

            elif c == ".":

                group = "dot"

            else:

                return False


            if group not in dfa[current_state]:

                return False

            

            current_state = dfa[current_state][group]

        

        return current_state in [1, 4, 7]



2021/06/14

Neural Network and super neuron

 I have been thinking of this problem for a while now. How human's memory is trigged? For example, you barely think of an event (your friend and you had a great conversation in a club on a rainy night) which happened 20 years ago. However, when you pick up a pen, which was given to you by your friend. Then you suddenly remember some content of the club conversation which took place 20 years ago.

How does a neural network model such brain activity?  Here I am proposing a concept of super neuron. This super neuron is a loosely connected neuron in the NN with both a low probability and an associated event (or event summary) stored deeply inside the network. 

The event associated with the super neuron has to be trigged by the event. Even more, the probability after the event registered with the system and then the memory flashing up is extremely low. 


 



How to Supercharge Your Python Classes with Class Methods

  How to Supercharge Your Python Classes with Class Methods | by Siavash Yasini | May, 2024 | Towards Data Science As we just mentioned, a c...