This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import quandl | |
import requests | |
class QuandlSocket: | |
""" | |
Socket for cached historical market data requests | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer