Created
January 5, 2023 21:55
-
-
Save 18182324/12ee1d7313923f1647b24336f54359b5 to your computer and use it in GitHub Desktop.
Quant Fidelity Fixed Income Asset Allocation Model
This file contains hidden or 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 matplotlib.pyplot as plt | |
import yfinance as yf | |
import requests | |
# Load the data for the macro, fundamentals, sentiment, and valuation pillars | |
macro_data = pd.read_csv('macro_data.csv') | |
fundamentals_data = pd.read_csv('fundamentals_data.csv') | |
sentiment_data = pd.read_csv('sentiment_data.csv') | |
valuation_data = pd.read_csv('valuation_data.csv') | |
# Normalize and truncate the data for each pillar | |
for pillar_data in [macro_data, fundamentals_data, sentiment_data, valuation_data]: | |
pillar_data = (pillar_data - pillar_data.mean()) / pillar_data.std() | |
pillar_data = pillar_data.clip(-2, 2) | |
# Round the data for each pillar to the nearest 0.5 | |
for pillar_data in [macro_data, fundamentals_data, sentiment_data, valuation_data]: | |
pillar_data = pillar_data.round(0.5) | |
# Load the information ratios for each indicator | |
info_ratios = pd.read_csv('info_ratios.csv') | |
# Weight the indicators based on their information ratios | |
macro_weights = macro_data * info_ratios['macro'] | |
fundamentals_weights = fundamentals_data * info_ratios['fundamentals'] | |
sentiment_weights = sentiment_data * info_ratios['sentiment'] | |
valuation_weights = valuation_data * info_ratios['valuation'] | |
# Calculate the final scores for each pillar | |
macro_score = macro_weights.sum(axis=1) | |
fundamentals_score = fundamentals_weights.sum(axis=1) | |
sentiment_score = sentiment_weights.sum(axis=1) | |
valuation_score = valuation_weights.sum(axis=1) | |
# Print the final scores | |
print('Macro score:', macro_score) | |
print('Fundamentals score:', fundamentals_score) | |
print('Sentiment score:', sentiment_score) | |
print('Valuation score:', valuation_score) | |
# Visualize the scores over time | |
plt.plot(macro_score, label='Macro') | |
plt.plot(fundamentals_score, label='Fundamentals') | |
plt.plot(sentiment_score, label='Sentiment') | |
plt.plot(valuation_score, label='Valuation') | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment