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 numpy as np | |
import pandas as pd | |
import statsmodels.api as sm | |
data = pd.read_csv("http://web.pdx.edu/~crkl/ceR/data/usyc87.txt",index_col='YEAR',sep='\s+',nrows=66) | |
y = data['Y'] | |
c = data['C'] | |
from statsmodels.tsa.vector_ar.vecm import coint_johansen | |
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 matplotlib.pyplot as plt | |
import pandas as pd | |
from johansen import coint_johansen | |
df_x = pd.read_csv ("yourfile.csv",index_col=0) | |
df_y = pd.read_csv ("yourfile.csv",index_col=0) | |
df = pd.DataFrame({'x':df_x['Close'],'y':df_y['Close']}) | |
coint_johansen(df,0,1) |
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
from datetime import timedelta | |
class IronCondorAlgorithm(QCAlgorithm): | |
def Initialize(self): | |
self.SetStartDate(2021, 2, 1) | |
self.SetEndDate(2021, 8, 1) | |
self.SetCash(30000) | |
equity = self.AddEquity("TSLA", Resolution.Minute) | |
option = self.AddOption("TSLA", Resolution.Minute) |
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
companies_dict = { | |
'Amazon':'AMZN', | |
'Apple':'AAPL', | |
'Walgreen':'WBA', | |
'Northrop Grumman':'NOC', | |
'Boeing':'BA', | |
'Lockheed Martin':'LMT', | |
'McDonalds':'MCD', | |
'Intel':'INTC', | |
'Navistar':'NAV', |
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
#requirements | |
#alpaca-trade-api>=0.25 | |
#ta | |
#sklearn | |
import alpaca_trade_api as tradeapi | |
import requests | |
import time | |
from ta import macd | |
import numpy as np |
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
# Step 1: Load libraries and data | |
library(quantmod) | |
library(PerformanceAnalytics) | |
## | |
##Attaching package: 'PerformanceAnalytics' | |
##The following object is masked from 'package:graphics': | |
##legend | |
getSymbols('NFCI', src = 'FRED', , from = '2000-01-01') | |
##[1] "NFCI" | |
NFCI <- na.omit(lag(NFCI)) # we can only act on the signal after release, i.e. the next day |
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
# The investment universe consists of 24 commodity futures, 12 cross-currency pairs (with 9 underlying currencies), 9 developed equity indices, and 13 | |
# government bond futures. | |
# Every month, the investor considers whether the excess return of each asset over the past 12 months is positive or negative and goes long on the | |
# contract if it is positive and short if negative. The position size is set to be inversely proportional to the instrument’s volatility. A univariate | |
# GARCH model is used to estimated ex-ante volatility in the source paper. However, other simple models could probably be easily used with good results | |
# (for example, the easiest one would be using historical volatility instead of estimated volatility). The portfolio is rebalanced monthly. | |
# QC implementation changes: | |
# instead of GARCH model volatility, simple historical volatility is used in this code. | |
# for more info on trading strategies visit miltonfmr.com | |
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
# Load libraries | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from pandas import read_csv, set_option | |
from pandas.plotting import scatter_matrix | |
import seaborn as sns | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.model_selection import train_test_split, KFold, cross_val_score, GridSearchCV | |
from sklearn.linear_model import LogisticRegression |
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
#Scikit-learn library to build and train a linear regression model | |
# First, we'll import the necessary libraries | |
from sklearn.linear_model import LinearRegression | |
from sklearn.model_selection import train_test_split | |
# Next, we'll load our data and split it into training and testing sets | |
X = # Your input data (economic indicators) | |
y = # Your output data (stagflation probability) | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
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
#Markov-Switching Vector Autoregression (MSVAR) model | |
import numpy as np | |
import statsmodels.tsa.api as smt | |
# Set the number of lags to consider | |
nlags = 4 | |
# Create the model | |
model = smt.MSVAR(data, lags=nlags) |