Created
January 18, 2022 16:29
-
-
Save robcarver17/97ea44466d7f0c31b8414409f2a727a8 to your computer and use it in GitHub Desktop.
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 matplotlib | |
matplotlib.use("TkAgg") | |
from syscore.objects import arg_not_supplied | |
# from sysdata.sim.csv_futures_sim_data import csvFuturesSimData | |
from sysdata.sim.db_futures_sim_data import dbFuturesSimData | |
from sysdata.config.configdata import Config | |
from systems.basesystem import System | |
from systems.provided.rob_system.rawdata import myFuturesRawData | |
from systems.provided.dynamic_small_system_optimise.portfolio_weights_stage import ( | |
portfolioWeightsStage, | |
) | |
from sysquant.estimators.clustering_correlations import * | |
def futures_system( | |
sim_data=arg_not_supplied, config_filename="systems.provided.rob_system.config.yaml" | |
): | |
if sim_data is arg_not_supplied: | |
sim_data = dbFuturesSimData() | |
config = Config(config_filename) | |
system = System( | |
[ | |
portfolioWeightsStage(), | |
myFuturesRawData(), | |
], | |
sim_data, | |
config, | |
) | |
system.set_logging_level("on") | |
return system | |
import datetime | |
system = futures_system() | |
instrument_list = system.get_instrument_list() | |
system.config.instrument_returns_correlation['cleaning'] = False | |
system.config.instrument_returns_correlation['shrinkage_parameter'] = 0.0 | |
system.config.instrument_returns_correlation['date_method']='in_sample' | |
system.config.instrument_returns_correlation['using_exponent'] = False | |
corr_matrix = system.portfolioWeights.get_correlation_matrix() | |
def display_clusters(system, clusters): | |
for idx, cluster in enumerate(clusters): | |
print("Cluster %d" % (idx+1)) | |
show_cluster(system, cluster) | |
def show_cluster(system, cluster): | |
instruments = cluster | |
assets = [system.data.asset_class_for_instrument(code) for code in instruments] | |
classes = list(set(assets)) | |
for aclass in classes: | |
subset = [code for (code,asset_class) in zip(instruments, assets) | |
if asset_class==aclass] | |
print("%s: %s" % (aclass, str(subset))) | |
N=2 | |
clusters = cluster_correlation_matrix(corr_matrix,N) | |
show_cluster(system, clusters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment