Skip to content

Commit 5dc967e

Browse files
committed
added economics, furthered probistics
1 parent fec5240 commit 5dc967e

File tree

12 files changed

+1779
-260
lines changed

12 files changed

+1779
-260
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
class Distribution:
2+
3+
def __init__(self):
4+
self.e = 2.718281828459045235360287471352
5+
6+
class Discrete_Distribution(Distribution):
7+
pass
8+
9+
10+
class Continuous_Distribution(Distribution):
11+
pass
12+
13+
##############################################
14+
15+
class Weibull_Distribution(Continuous_Distribution):
16+
17+
def __init__(self, alpha, beta):
18+
self.alpha = alpha
19+
self.beta = beta
20+
21+
self.pdf = lambda x : (alpha/(beta**alpha))*(x**(alpha-1))*self.e**(-(x/beta)**alpha)
22+
self.cdf = lambda x : 1-self.e**(-(x/beta)**alpha)
23+
24+
def p(self,X, left = True):
25+
if (type(X) is not list):
26+
return self.cdf(X) if left else 1-self.cdf(X)
27+
return self.cdf(X[1])-self.cdf(X[0])
28+
29+
def point_perc(self,percent):
30+
return self.beta*(-np.log(1-percent))**(1/self.alpha)
31+
32+
33+
class Gamma_Distribution(Continuous_Distribution):
34+
35+
def __init__(self,alpha,beta=1):
36+
self.alpha = alpha
37+
self.beta = beta
38+
self.e = 2.718281828459045235360287471352
39+
self.pdf = lambda x : (1/( (beta**alpha) * gamma(alpha) ))*x**(alpha-1)*self.e**(-x/beta)
40+
self.cdf = lambda x, n : integrate(self.pdf,[0,n])
41+
42+
#TODO:
43+
class ChiSquared_Distribution(Continuous_Distribution):
44+
pass
45+
46+
class Lognormal_Distribution(Continuous_Distribution):
47+
pass
48+
49+
class Beta_Distribution(Continuous_Distribution):
50+
pass
51+
52+
class Exponential_Distribution(Continuous_Distribution):
53+
pass
54+
55+
class Normal_Distribution(Continuous_Distribution):
56+
pass
57+
58+
class Uniform_Distribution(Continuous_Distribution):
59+
pass
60+
61+
###################################
62+
63+
class Poisson_Distribution(Discrete_Distribution):
64+
pass
65+
66+
class Binomial_Distribution(Discrete_Distribution):
67+
pass

.ipynb_checkpoints/Probistics-checkpoint.ipynb

Lines changed: 414 additions & 2 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 4
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 4
6+
}

Economics/functions.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
3+
4+
def simple_interest ( P , i , n ) -> float:
5+
"""
6+
Calculates the simple interest over n periods of applied interest i, given a starting principle P.
7+
INPUT:
8+
P : numerical - the starting principle
9+
i : numerical - the interest rate
10+
n : int - the number of periods the interest compounds
11+
RETURN:
12+
F : numerical - P(1+i*n), the future value of P given i and n.
13+
"""
14+
return P * ( 1 + i * n )
15+
16+
17+
def compound_worth ( O , i , n , forward = True ) -> float:
18+
"""
19+
Calculates the worth of O at some other time, either a future worth (when forward == True, which gives O == P);
20+
else present worth - i.e. O == F.
21+
INPUT:
22+
O : numerical - the worth at some time, P if forward is True, else F
23+
i : numerical - the interest rate
24+
n : int - the number of periods the interest compounds
25+
forward : bool - the direction of worth to be calculated, defaults to True
26+
RETURN:
27+
Z : numerical - P(1+i)^n, the future value of P given i and n, when forward == True,
28+
else F(1+i)^-n, giving the present worth, i.e. the principle P needed to obtain F given i and n.
29+
"""
30+
return O * ( ( 1 + i ) ** n ) if forward else O * ( ( 1 + i ) ** ( -n ) )
31+
32+
33+
34+
def series_F ( O , i , n , forward = True ) -> float:
35+
"""
36+
Calculates the worth of n 'payments' of O at some other time, either a future worth (when forward == True, which gives O == A, Z == F);
37+
else worth at time of 'payment' - i.e. O == F, Z == A.
38+
INPUT:
39+
O : numerical - the known variable, either A - the regular payments if forward == True, else F - the future worth of those payments
40+
i : numerical - the interest rate
41+
n : int - the number of periods the interest compounds
42+
forward : bool - the direction of worth to be calculated, defaults to True
43+
RETURN:
44+
Z : numerical - A(((1+i)^n-1)/i), the future value of n payments of A given i and n, when forward == True,
45+
else F(i/( (1+i)^n-1 )), the value of each A (assuming constant A, effectively an average) at time of payment.
46+
"""
47+
return O * ( ( ( 1 + i ) ** n - 1 ) / i ) if forward else O * ( i / ( ( 1 + i ) ** n - 1 ) )
48+
49+
def series_P ( O , i , n , forward = True ) -> float:
50+
"""
51+
Calculates the worth of n 'payments' of O at some other time, either worth at time of 'payment' (when forward == True, which gives O == P, Z == A);
52+
else a present worth - i.e. O == A, Z == P.
53+
INPUT:
54+
O : numerical - the known variable, either P - the present worth of the payments A if forward == True, else A - the worth of each payment at the time of payment
55+
i : numerical - the interest rate
56+
n : int - the number of periods the interest compounds
57+
forward : bool - the direction of worth to be calculated, defaults to True
58+
RETURN:
59+
Z : numerical - P( ( i(1+i)^n ) / ( (1+i)^n - 1 ) ), the neccessary value of A - for instance the needed payments to recoup a loss P
60+
else A( ( (1+i)^n - 1 ) / ( i(1+i)^n ) ), the present worth of payments A, for instance the loss that n payments of A could cover.
61+
"""
62+
return O * ( ( i * ( 1 + i ) ** n ) / ( ( 1 + i ) ** n - 1 ) ) if forward else O * ( ( ( 1 + i ) ** n - 1 ) / ( i * ( 1 + i ) ** n ) )
63+
64+
65+
def arith_grad_series ( O , i , n , forward = True ) -> float:
66+
"""
67+
Calculates the worth of n 'payments' of O at some other time, either worth at time of 'payment' (when forward == True, which gives O == P, Z == A);
68+
else a present worth - i.e. O == A, Z == P.
69+
INPUT:
70+
O : numerical - the known variable, either G - the gradient factor if forward == True, else A - the worth of each payment at the time of payment
71+
i : numerical - the interest rate
72+
n : int - the number of periods the interest compounds
73+
forward : bool - the direction of worth to be calculated, defaults to True
74+
RETURN:
75+
Z : numerical - G( ( 1 / i ) - n / ( ( 1 + i )^n - 1 ) ), the neccessary value of A
76+
else A/( ( 1 / i ) - n / ( ( 1 + i )^n - 1 ) ), the gradient value.
77+
"""
78+
return O * ( ( 1 / i ) - n / ( ( 1 + i ) ** n - 1 ) ) if forward else O / ( ( 1 / i ) - n / ( ( 1 + i ) ** n - 1 ) )
79+
80+
81+
def arith_grad_worth ( O , i , n , forward = True ) -> float:
82+
"""
83+
Calculates the worth of n 'payments' of O at some other time, either worth at time of 'payment' (when forward == True, which gives O == P, Z == A);
84+
else a present worth - i.e. O == A, Z == P.
85+
INPUT:
86+
O : numerical - the known variable, either G - the gradient factor if forward == True, else A - the worth of each payment at the time of payment
87+
i : numerical - the interest rate
88+
n : int - the number of periods the interest compounds
89+
forward : bool - the direction of worth to be calculated, defaults to True
90+
RETURN:
91+
Z : numerical - G( ( 1 / i ) - n / ( ( 1 + i )^n - 1 ) ), the neccessary value of A
92+
else A/( ( 1 / i ) - n / ( ( 1 + i )^n - 1 ) ), the gradient value.
93+
"""
94+
return O * ( ( 1 / i ) - n / ( ( 1 + i ) ** n - 1 ) ) if forward else O / ( ( 1 / i ) - n / ( ( 1 + i ) ** n - 1 ) )

Economics/objects.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Objects related to economics
2+
3+
4+
class Currency:
5+
6+
pass

Probistics.ipynb

Lines changed: 0 additions & 258 deletions
This file was deleted.

Signalysis.ipynb

Lines changed: 142 additions & 0 deletions
Large diffs are not rendered by default.

Superica.ipynb

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 3,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import numpy as np\n",
10+
"import re"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"exp1 = \"x = 2\"\n",
20+
"exp2 = \"$cos(x)$\""
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 4,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"func = dict(cos = np.cos)"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 5,
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"data": {
39+
"text/plain": [
40+
"-1.0"
41+
]
42+
},
43+
"execution_count": 5,
44+
"metadata": {},
45+
"output_type": "execute_result"
46+
}
47+
],
48+
"source": [
49+
"func['cos'](np.pi)"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 12,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"class express:\n",
59+
" \n",
60+
" def __init__(self,strinput : str):\n",
61+
" self.expression : str = strinput\n",
62+
" self.vars,self.funcs = self._decompose()\n",
63+
" \n",
64+
" \n",
65+
" def _decompose(self):\n",
66+
" return 0,0"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 13,
72+
"metadata": {},
73+
"outputs": [
74+
{
75+
"data": {
76+
"text/plain": [
77+
"<__main__.express at 0x2168e554148>"
78+
]
79+
},
80+
"execution_count": 13,
81+
"metadata": {},
82+
"output_type": "execute_result"
83+
}
84+
],
85+
"source": [
86+
"express(exp1)"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 21,
92+
"metadata": {},
93+
"outputs": [],
94+
"source": [
95+
"spec = re.compile(\"\\((.+)\\)\")\n",
96+
"encase = re.compile(\"\\$.+\\$\")"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 22,
102+
"metadata": {},
103+
"outputs": [
104+
{
105+
"name": "stdout",
106+
"output_type": "stream",
107+
"text": [
108+
"<re.Match object; span=(4, 7), match='(x)'>\n",
109+
"<re.Match object; span=(0, 8), match='$cos(x)$'>\n"
110+
]
111+
}
112+
],
113+
"source": [
114+
"print(spec.search(exp2))\n",
115+
"print(encase.search(exp2))"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": 47,
121+
"metadata": {},
122+
"outputs": [
123+
{
124+
"name": "stdout",
125+
"output_type": "stream",
126+
"text": [
127+
"index.html <-> home\n",
128+
"base.html <-> base\n"
129+
]
130+
}
131+
],
132+
"source": [
133+
"w = \"TEMPLATES = ( ('index.html', 'home'), ('base.html', 'base'))\"\n",
134+
"\n",
135+
"# find outer parens\n",
136+
"outer = re.compile(\"\\((.+)\\)\")\n",
137+
"m = outer.search(w)\n",
138+
"inner_str = m.group(1)\n",
139+
"\n",
140+
"# find inner pairs\n",
141+
"innerre = re.compile(\"\\('([^']+)', '([^']+)'\\)\")\n",
142+
"\n",
143+
"results = innerre.findall(inner_str)\n",
144+
"for x,y in results:\n",
145+
" print(\"%s <-> %s\" % (x,y))"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 26,
151+
"metadata": {},
152+
"outputs": [
153+
{
154+
"data": {
155+
"text/plain": [
156+
"'cos(x)'"
157+
]
158+
},
159+
"execution_count": 26,
160+
"metadata": {},
161+
"output_type": "execute_result"
162+
}
163+
],
164+
"source": [
165+
"encase.search(exp2).group(0).lstrip('$').rstrip('$')"
166+
]
167+
},
168+
{
169+
"cell_type": "code",
170+
"execution_count": null,
171+
"metadata": {},
172+
"outputs": [],
173+
"source": []
174+
}
175+
],
176+
"metadata": {
177+
"kernelspec": {
178+
"display_name": "Python 3",
179+
"language": "python",
180+
"name": "python3"
181+
},
182+
"language_info": {
183+
"codemirror_mode": {
184+
"name": "ipython",
185+
"version": 3
186+
},
187+
"file_extension": ".py",
188+
"mimetype": "text/x-python",
189+
"name": "python",
190+
"nbconvert_exporter": "python",
191+
"pygments_lexer": "ipython3",
192+
"version": "3.7.9"
193+
}
194+
},
195+
"nbformat": 4,
196+
"nbformat_minor": 4
197+
}

0 commit comments

Comments
 (0)