-
Notifications
You must be signed in to change notification settings - Fork 0
/
MARKET_STATS_DISTRIBUTION.py
183 lines (109 loc) · 3.43 KB
/
MARKET_STATS_DISTRIBUTION.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 13 03:32:24 2021
@author: alexx
File that contains probability distribution for pair, securities
#latest?symbol=EUR/USD,USD/JPY,GBP/CHF&access_key=5sT7U5zKOMY3oDSv0h90gNA0o
aapl = yf.download('AAPL','2018-12-26', '2019-12-26')
mean = np.mean(aapl['Adj Close'])
median = np.median(aapl['Adj Close'])
mode = statistics.mode(aapl['Adj Close'])
aapl['daily_percent_change'] = aapl['Adj Close'].pct_change()
aapl.daily_percent_change.hist(figsize=(10,7))
plt.ylabel('Frequency')
plt.xlabel('Daily Percentage Change')
plt.show()
#index reference for apple pricing
spx = yf.download('^GSPC','2018-12-26', '2021-01-13')
spx['daily_percent_change'] = spx['Adj Close'].pct_change()
plt.figure(figsize=(10,7))
plt.scatter(aapl.daily_percent_change,spx.daily_percent_change)
plt.xlabel('AAPL Daily Returns')
plt.ylabel('SPY Daily Returns')
plt.grid()
plt.show()
correlation, _ = spearmanr(aapl.daily_percent_change.dropna(),spx.daily_percent_change.dropna())
print('Spearmans correlation is %.2f' % correlation)
data_binom = binom.rvs(n=10,p=0.8,size=10000)
ax = sns.distplot(data_binom,
kde=False,
color='skyblue',
hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Binomial Distribution', ylabel='Frequency')
"""
import requests
import statistics
import matplotlib.pyplot as plt
import numpy as np
import yfinance as yf
from scipy import special
from scipy.stats import spearmanr
from scipy.stats import bernoulli
import scipy.stats as ss
import yfinance as yf
import sys
'''
sys.path.append is needed in order to import other files as packages
as we do this into out folder we can rename our packages and use them for calculations
'''
sys.path.append('D:\ProiectePersonale\PythonPrograms\QUANT_FL\QUANT_ANALYSIS')
#brokerage api connection and function
import MARKET_OPENX_CONN_API as openx_api
#technical analysis api connection and data
import API_CONN_OPENX as intr_stats
#monte carlo simulations
import MC_RISK_ASSESMENT as mc
#markov chain implementation
import MARKET_VISUALIZER as markov
#historic data parsed from csv
import MARKET_ANALYZER as hist_parsed
'''
import market_openx_conn_api as api
import mc_risk_assesment as mc
'''
def calc_p():
adx_list = intr_stats.adx_list
rsi_list = intr_stats.rsi_list
adx_move = intr_stats.calculate_adx_move()
rsi_move = intr_stats.calculate_rsi_move()
p_adx = 0
p_rsi = 0
ind = 0
while ind < 14:
p_adx = p_adx + adx_list[ind] * adx_move[ind]
p_rsi = p_rsi + rsi_list[ind] * rsi_move[ind]
ind += 1
p_adx = abs(p_adx /14)
p_rsi = abs(p_rsi /14)
print(p_adx)
print(p_rsi)
return (p_adx + p_rsi) / 2 / 100
# for adx in adx_list:
#cdf = cumulative distribution
def plot_beta_ind(x_range, a, b, mu, sigma = 1, cdf = True, **kwargs):
x = x_range
X = ss.beta(1, 3)
def return_transpose():
t = markov.tMatrix
p = calc_p()
'''
def main():
calc_p()
mc.plot_security('AAPL')
x = ss.binom(14, 1 - p)
UP = x.cdf(4)
CS = 1 - DN - UP
i = 0
j = 0
while i < 3:
var = random(0, 5)
while j < 3 :
X = ss.binom(14, p)
DN = X.cdf(var)
t[i][j] =
print(DN)
print(UP)
print(CS)
if __name__ == "__main__":
main()
'''