Question
Import all necessary modules import pandas as pd import matplotlib.pyplot as plt % matplotlib inline import seaborn from sklearn import linear_model import statsmodels.api as smf
Import all necessary modules
import pandas as pd import matplotlib.pyplot as plt %matplotlib inline import seaborn from sklearn import linear_model import statsmodels.api as smf import warnings warnings.filterwarnings('ignore')
/Users/neuron/anaconda/lib/python3.6/site-packages/statsmodels/compat/p andas.py:56: FutureWarning: The pandas.core.datetools module is depreca ted and will be removed in a future version. Please use the pandas.tser ies module instead.
from pandas.core import datetoolsIn chapter 1, we have build a regression model for the change of close price of Microsoft
In [8]:
ms=pd.DataFrame.from_csv('microsoft.csv') ms['Y']=ms['Close'].shift(-1)-ms['Close'] ms['X1']=ms['Close']-ms['Close'].shift(1) ms['X2']=ms['Close'].shift(1)-ms['Close'].shift(2) ms['X3']=ms['High']-ms['Low'] ms['X4']=ms['High'].shift(1)-ms['Low'].shift(1) ms['X5']=ms['High']-ms['Close'] ms['X6']=ms['High'].shift(1)-ms['Close'].shift(1) ms['X7']=ms['Volume']-ms['Volume'].shift(1) ms['X8']=ms['Volume'].shift(1)-ms['Volume'].shift(2) ms=ms.dropna(axis=0)
Please notice, to read data sucessfully, you need to put "microsoft.csv" and Assignment notebook in the same folder.
Problem 1.
divide the data into training (80%) and test data (20%).
Build linear regression model for using with training data. Make prediction in training and test data.
Compute average daily profit in training data and test data using the following signal-based strategy.if Y_predict >0, buy today and sell it tomorrow else, do nothing.
Is the performance of your prediction model consistent? (Consistency means that it has similar performance in train and test.)
In lecture, we claim that, if the average daily profit is higher than transaction cost, the strategy can be implemented (Now, we know that consistency of the model is also a necessary condition.)
But on some days, we do not trade stocks which are also counted in average daily profit. To evaluate the implementability more precisely, we need to compute average daily profit of those days we trade. Could you compute this adjusted average profit for training and test periods.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started