Skip to content

Instantly share code, notes, and snippets.

View romanmichaelpaolucci's full-sized avatar
:octocat:
Studying

Roman Paolucci romanmichaelpaolucci

:octocat:
Studying
View GitHub Profile
@romanmichaelpaolucci
romanmichaelpaolucci / Evolution.py
Created July 11, 2019 01:03
Neural Evolution
# Read Data
data = pd.read_csv('banknote.csv')
# Create Matrix of Independent Variables
X = data.drop(['Y'], axis=1)
# Create Vector of Dependent Variable
y = data['Y']
# Create a Train Test Split for Genetic Optimization
X_train, X_test, y_train, y_test = train_test_split(X, y)
# Create a List of all active GeneticNeuralNetworks
networks = []
# New Type of Neural Network
class GeneticNeuralNetwork(Sequential):
# Constructor
def __init__(self, child_weights=None):
# Initialize Sequential Model Super Class
super().__init__()
# If no weights provided randomly generate them
if child_weights is None:
# Layers are created and randomly generated
layer1 = Dense(4, input_shape=(4,), activation='sigmoid')
[Command: python -u 'C:\Users\Roman\Documents\Software Development\archive\(deprecated) Neural Evolution Algorithm\neural_genetics.py']
Using TensorFlow backend.
WARNING:tensorflow:From C:\Users\Roman\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Generation: 1
2019-07-10 18:00:54.582107: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Max Fitness: 0.620019436345967
[array([[-0.55393076, 0.6676968 , -0.447821 , 0.2897933 ],
[-0.760463 , 0.49176246, 0.48069805, 0.42872745],
[Command: python -u 'C:\Users\Roman\Documents\Software Development\archive\(deprecated) Neural Evolution Algorithm\test.py']
Using TensorFlow backend.
WARNING:tensorflow:From C:\Users\Roman\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From C:\Users\Roman\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Epoch 1/10
2019-07-10 21:16:45.434436: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
@romanmichaelpaolucci
romanmichaelpaolucci / api_socket.py
Last active January 17, 2020 02:39
Quandl Socket
import pandas as pd
import quandl
import requests
class QuandlSocket:
"""
Socket for cached historical market data requests
"""
@romanmichaelpaolucci
romanmichaelpaolucci / portfolio_data_request.py
Created January 17, 2020 02:38
Portfolio Data Request from Quandl
class PortfolioDataRequest:
""" stocks = [], start_date/end_date are strings 'YYYY-MM-DD' """
"""
Class for portfolfio optimization, downloads relevant portfolio data
and caches it for use in optimization without saving it locally.
"""
def __init__(self, stocks, start_date, end_date):
QuandlSocket()
@romanmichaelpaolucci
romanmichaelpaolucci / portfolio_optimization.py
Last active January 23, 2020 22:48
Portfolio Optimization
class PortfolioOptimization:
"""
Class for optimizing a historic portfolio
"""
def __init__(self, table):
mu = expected_returns.mean_historical_return(table)
S = risk_models.sample_cov(table)
@romanmichaelpaolucci
romanmichaelpaolucci / portfolio_returns.py
Created January 17, 2020 02:50
Discrete Portfolio Returns
class PortfolioReturns:
def __init__(self, stocks, discrete_allocation, start_date, end_date):
data = PortfolioDataRequest(stocks, start_date, end_date).table
self.start_date = start_date
self.end_date = end_date
starting_value = 0
ending_value = 0
for stock in stocks:
try:
@romanmichaelpaolucci
romanmichaelpaolucci / pyopt_pipeline.py
Created January 17, 2020 02:52
Portfolio Optimization Pipeline
from portfolio_tools import PortfolioDataRequest
from portfolio_tools import PortfolioOptimization
from portfolio_tools import PortfolioReturns
"""
Script for portfolio optimization pipeline research
"""
if __name__ == '__main__':
stocks = 'AAPL MSFT JNJ JPM XOM WMT UNH PFE VZ V BA'.split()
@romanmichaelpaolucci
romanmichaelpaolucci / bad_AI_PM.py
Last active January 18, 2020 15:03
Poor Performing AI Portfolio Manager
# Class to develop your AI portfolio manager
class AIPMDevelopment:
def __init__(self):
# Read your data in and split the dependent and independent
data = pd.read_csv('IBM.csv')
X = data['Delta Close']
y = data.drop(['Delta Close'], axis=1)
# Train test spit