Skip to content

Instantly share code, notes, and snippets.

View 18182324's full-sized avatar
🎯
Focusing

Wealth Hub 18182324

🎯
Focusing
View GitHub Profile
# Execute this cell to be sure to have a compatible TF (2.0) and TFP (0.8) version.
# If you are bold you can skip this cell.
try: #If running in colab
import google.colab
!pip install tensorflow==2.0.0
!pip install tensorflow_probability==0.8.0
except:
print('Not running in colab')
try: #If running in colab
@18182324
18182324 / prob_signs.py
Created May 19, 2021 09:21
Deep L. Prob. Number of Dollar Signs
#Solution for model assumption. Different number of dollar signs.
from scipy.stats import binom
#Define the considered numbers of dollar signs on the die (zero to six):
ndollar = np.asarray(np.linspace(0,6,7), dtype='int')
#Calculate corresponding probability of 2 $-signs in 10 throws
pdollar = binom.pmf(k=2, n=10, p=ndollar/6)
plt.stem(ndollar, pdollar)
plt.xlabel('Number of dollar signs on the dice')
plt.ylabel('Probability observing 2 dollar signs in 10 throws')
plt.title('Unnormalized likelihoods')
try: #If running in colab
import google.colab
IN_COLAB = True
%tensorflow_version 2.x
except:
IN_COLAB = False
import tensorflow as tf
if (not tf.__version__.startswith('2')): #Checking if tf 2.0 is installed
print('Please install tensorflow 2.0 to run this notebook')
@18182324
18182324 / deeplprob.py
Created May 19, 2021 09:18
Deep Learning Probability
try: #If running in colab
import google.colab
IN_COLAB = True
%tensorflow_version 2.x
except:
IN_COLAB = False
import tensorflow as tf
if (not tf.__version__.startswith('2')): #Checking if tf 2.0 is installed
print('Please install tensorflow 2.0 to run this notebook')
i=0
fitness = 0
counter = 0
while i < max_iter:
if counter > n_repeats:
STOP
Y = [ ]
fit = [ ]
pairs = randompairsfrom (X)
for j in pairs:
import math
increment = 0.1
startingPoint = [1, 1]
point1 = [1,5]
point2 = [6,4]
point3 = [5,2]
point4 = [2,1]
def distance(x1, y1, x2, y2):
model = RandomForestRegressor(n_jobs=-1, random_state=42, verbose=2)
grid = {'n_estimators': [10, 13, 18, 25, 33, 45, 60, 81, 110, 148, 200],
'max_features': [0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.17, 0.19, 0.21, 0.23, 0.25],
'min_samples_split': [2, 3, 5, 8, 13, 20, 32, 50, 80, 126, 200]}
rf_gridsearch = GridSearchCV(estimator=model, param_grid=grid, n_jobs=4,
cv=cv, verbose=2, return_train_score=True)
rf_gridsearch.fit(X1, y1)
def CoarseSelectionFunction(self, coarse):
if self.yearly_rebalance:
self.filtered_coarse = [x.Symbol for x in coarse if (x.HasFundamentalData)
and (x.Market == "usa")]
return self.filtered_coarse
else:
return []
def FineSelectionFunction(self, fine):
if self.yearly_rebalance:
def CalculateAccruals(self, current, previous):
accruals = []
for stock_data in current:
try:
prev_data = None
for x in previous:
if x.Symbol == stock_data.Symbol:
prev_data = x
break
class NetCurrentAssetValue(QCAlgorithm):
def Initialize(self):
#rebalancing should occur in July
self.SetStartDate(2007,5,15) #Set Start Date
self.SetEndDate(2018,7,15) #Set End Date
self.SetCash(1000000) #Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.previous_fine = None
self.filtered_fine = None