-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrisk_calculator.py
106 lines (55 loc) · 2.69 KB
/
risk_calculator.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
from PyQt5.QtCore import QRunnable, Qt, QThreadPool, QThread, pyqtSignal
import numpy as np
import asset_srch as ass
import sys
import os
import time
def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
class RebalRisk(QThread):
#worker_signal = Signal(str)
change_value = pyqtSignal(int)
def __init__(self, mw, SlideManager):
super().__init__()
self.mw = mw
self.SlideManager = SlideManager
self.continue_running = True
print(f"Initialized RebalRisk")
def run(self):
SlideManager = self.SlideManager
mw = self.mw
print("runing blc risk calculation")
asset_ars = [slid.wlw.search_ar for slid in SlideManager.sliders]
blclist = np.array([slid.getValue()/100 for slid in SlideManager.sliders])
#ret = totVal[-1]/totVal[0]
ret_list = []
for blc_intrvl in range(10,365,2):
progress(blc_intrvl, 365)
self.change_value.emit(blc_intrvl)
blc_coam = np.array([ ass.multi_balance_crawler(asset_ars, blclist, 0, blc_intrvl, push)[0][:,-1].sum()
for push in range(1,blc_intrvl, 2) ])
ret_list.append( blc_coam )
#################################
self.change_value.emit(365)
ret_list = np.array(ret_list)
"""
try:
mw.progressBar.setValue(100)
mw.label_10.setText(f"Calculation completed!")
except: pass"""
print("done running blc risk calculation")
print(f" ret_list array is now shape {ret_list.shape}")
np.save("tts", ret_list)
#return ret_list
#@Slot() # <<-- This is recommended for stability ###########################################
def kill(self):
self.continue_running = False
"""
def quadratize(self, noquad):
l = max([len(n) for n in noquad])
pass"""