首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
Ac.F633代做、Python程序语言代写
项目预算:
开发周期:
发布时间:
要求地区:
Ac.F633 - Python Programming Final Individual Project
Ac.F633 - Python Programming for Data Analysis
Manh Pham
Final Individual Project
20 March 2024 noon/12pm to 10 April 2024 noon/12pm (UK time)
This assignment contains one question worth 100 marks and constitutes 60% of the
total marks for this course.
You are required to submit to Moodle a SINGLE .zip folder containing a single Jupyter Notebook .ipynb file OR a single Python script .py file, together with
any supporting .csv files (e.g. input data files. However, do NOT include the
‘IBM 202001.csv.gz’ data file as it is large and may slow down the upload and submission) AND a signed coursework coversheet. The name of this folder should be
your student ID or library card number (e.g. 12345678.zip, where 12345678 is your
student ID).
In your answer script, either Jupyter Notebook .ipynb file or Python .py file, you
do not have to retype the question for each task. However, you must clearly label
which task (e.g. 1.1, 1.2, etc) your subsequent code is related to, either by using a
markdown cell (for .ipynb file) or by using the comments (e.g. #1.1 or ‘‘‘1.1’’’
for .py file). Provide only ONE answer to each task. If you have more than one
method to answer a task, choose one that you think is best and most efficient. If
multiple answers are provided for a task, only the first answer will be marked.
Your submission .zip folder MUST be submitted electronically via Moodle by the
10 April 2024 noon/12pm (UK time). Email submissions will NOT be considered. If you have any issues with uploading and submitting your work to Moodle,
please email Carole Holroyd at c.holroyd@lancaster.ac.uk BEFORE the deadline
for assistance with your submission.
The following penalties will be applied to all coursework that is submitted after the
specified submission date:
Up to 3 days late - deduction of 10 marks
Beyond 3 days late - no marks awarded
Good Luck!
1
Ac.F633 - Python Programming Final Individual Project
Question 1:
Task 1: High-frequency Finance (Σ = 30 marks)
The data file ‘IBM 202001.csv.gz’ contains the tick-by-tick transaction data for
stock IBM in January 2020, with the following information:
Fields Definitions
DATE Date of transaction
TIME M Time of transaction (seconds since mid-night)
SYM ROOT Security symbol root
EX Exchange where the transaction was executed
SIZE Transaction size
PRICE Transaction price
NBO Ask price (National Best Offer)
NBB Bid price (National Best Bid)
NBOqty Ask size
NBBqty Bid size
BuySell Buy/Sell indicator (1 for buys, -1 for sells)
Import the data file into Python and perform the following tasks:
1.1: Write code to perform the filtering steps below in the following order: (15 marks)
F1: Remove entries with either transaction price, transaction size, ask price,
ask size, bid price or bid size ≤ 0
F2: Remove entries with bid-ask spread (i.e. ask price - bid price) ≤ 0
F3: Aggregate entries that are (a) executed at the same date time (i.e. same
‘DATE’ and ‘TIME M’), (b) executed on the same exchange, and (c) of
the same buy/sell indicator, into a single transaction with the median
transaction price, median ask price, median bid price, sum transaction
size, sum ask size and sum bid size.
F4: Remove entries for which the bid-ask spread is more that 50 times the
median bid-ask spread on each day
F5: Remove entries with the transaction price that is either above the ask
price plus the bid-ask spread, or below the bid price minus the bid-ask
spread
Create a data frame called summary of the following format that shows the
number and proportion of entries removed by each of the above filtering steps.
The proportions (in %) are calculated as the number of entries removed divided
by the original number of entries (before any filtering).
F1 F2 F3 F4 F5
Number
Proportion
Here, F1, F2, F3, F4 and F5 are the columns corresponding to the above 5
filtering rules, and Number and Proportion are the row indices of the data
frame.
2
Ac.F633 - Python Programming Final Individual Project
1.2: Using the cleaned data from Task 1.1, write code to compute Realized
Volatility (RV), Bipower Variation (BV) and Truncated Realized Volatility
(TRV) measures (defined in the lectures) for each trading day in the sample
using different sampling frequencies including 1 second (1s), 2s, 3s, 4s, 5s, 10s,
15s, 20s, 30s, 40s, 50s, 1 minute (1min), 2min, 3min, 4min, 5min, 6min, 7min,
8min, 9min, 10min, 15min, 20min and 30min. The required outputs are 3
data frames RVdf, BVdf and TRVdf (for Realized Volatility, Bipower Variation
and Truncated Realized Volatility respectively), each having columns being
the above sampling frequencies and row index being the unique dates in the
sample. (10 marks)
1.3: Use results in Task 1.2, write code to produce a 1-by-3 subplot figure that
shows the ‘volatility signature plot’ for RV, BV and TRV. Scale (i.e. multiply)
the RVs, BVs and TRVs by 104 when making the plots. Your figure should
look similar to the following.
0 500 1000 1500
Sampling frequency (secs)
1.0
1.5
2.0
2.5
A
v
era
g
e
d
R
V (x10
4
)
RV signature plot
0 500 1000 1500
Sampling frequency (secs)
0.6
0.8
1.0
1.2
1.4
A
v
era
g
e
d
B
V (x10
4
)
BV signature plot
0 500 1000 1500
Sampling frequency (secs)
0.5
0.6
0.7
0.8
0.9
1.0
A
v
era
g
e
d
T
R
V (x10
4
)
TRV signature plot
(5 marks)
Task 2: Return-Volatility Modelling (Σ = 25 marks)
Refer back to the csv data file ‘DowJones-Feb2022.csv’ that lists the constituents of the Dow Jones Industrial Average (DJIA) index as of 9 February
2022 that was investigated in the group project. Import the data file into
Python.
Using your student ID or library card number (e.g. 12345678) as a random
seed, draw a random sample of 2 stocks (i.e. tickers) from the DJIA index
excluding stock DOW.1
Import daily Adjusted Close (Adj Close) prices for
both stocks between 01/01/2010 and 31/12/2023 from Yahoo Finance. Compute the log daily returns (in %) for both stocks and drop days with NaN
returns. Perform the following tasks.
2.1: Using data between 01/01/2010 and 31/12/2020 as in-sample data, write
code to find the best-fitted ARMA(p, q) model for returns of each stock that
minimizes AIC, with p and q no greater than 3. Print the best-fitted ARMA(p, q)
output and a statement similar to the following for your stock sample.
Best-fitted ARMA model for WBA: ARMA(2,2) - AIC = 11036.8642
Best-fitted ARMA model for WMT: ARMA(2,3) - AIC = 8810.4277 (5 marks)
1DOW only started trading on 20/03/2019
3
Ac.F633 - Python Programming Final Individual Project
2.2: Write code to plot a 2-by-4 subplot figure that includes the following diagnostics for the best-fitted ARMA model found in Task 2.1:
Row 1: (i) Time series plot of the standardized residuals, (ii) histogram of
the standardized residuals, fitted with a kernel density estimate and the
density of a standard normal distribution, (iii) ACF of the standardized
residuals, and (iv) ACF of the squared standardized residuals.
Row 2: The same subplots for the second stock.
Your figure should look similar to the following for your sample of stocks.
Comment on what you observe from the plots. (6 marks)
2010 2012 2014 2016 2018 2020
Date
8
6
4
2
0
2
4
6
ARMA(2,2) Standardized residuals-WBA
3 2 1 0 1 2 3
0.0
0.1
0.2
0.3
0.4
0.5
0.6
Density
Distribution of standardized residuals
N(0,1)
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00
ACF of standardized residuals
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00 ACF of standardized residuals squared
2010 2012 2014 2016 2018 2020
Date
7.5
5.0
2.5
0.0
2.5
5.0
7.5
ARMA(2,3) Standardized residuals-WMT
3 2 1 0 1 2 3
0.0
0.1
0.2
0.3
0.4
0.5
0.6
Density
Distribution of standardized residuals
N(0,1)
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00
ACF of standardized residuals
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00 ACF of standardized residuals squared
2.3: Use the same in-sample data as in Task 2.1, write code to find the bestfitted AR(p)-GARCH(p
∗
, q∗
) model with Student’s t errors for returns of each
stock that minimizes AIC, where p is fixed at the AR lag order found in
Task 2.1, and p
∗ and q
∗ are no greater than 3. Print the best-fitted AR(p)-
GARCH(p
∗
, q∗
) output and a statement similar to the following for your stock
sample.
Best-fitted AR(p)-GARCH(p*,q*) model for WBA: AR(2)-GARCH(1,1) - AIC
= 10137.8509
Best-fitted AR(p)-GARCH(p*,q*) model for WMT: AR(2)-GARCH(3,0) - AIC
= 7743.4547 (5 marks)
2.4: Write code to plot a 2-by-4 subplot figure that includes the following diagnostics for the best-fitted AR-GARCH model found in Task 2.3:
Row 1: (i) Time series plot of the standardized residuals, (ii) histogram of
the standardized residuals, fitted with a kernel density estimate and the
density of a fitted Student’s t distribution, (iii) ACF of the standardized
residuals, and (iv) ACF of the squared standardized residuals.
Row 2: The same subplots for the second stock.
Your figure should look similar to the following for your sample of stocks.
Comment on what you observe from the plots. (6 marks)
4
Ac.F633 - Python Programming Final Individual Project
2010 2012 2014 2016 2018 2020
Date
10.0
7.5
5.0
2.5
0.0
2.5
5.0
7.5
AR(2)-GARCH(1,1) Standardized residuals-WBA
3 2 1 0 1 2 3
0.0
0.1
0.2
0.3
0.4
0.5
0.6
Density
Distribution of standardized residuals
t(df=3.7)
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00
ACF of standardized residuals
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00 ACF of standardized residuals squared
2010 2012 2014 2016 2018 2020
Date
10
5
0
5
10
AR(2)-GARCH(3,0) Standardized residuals-WMT
3 2 1 0 1 2 3
0.0
0.1
0.2
0.3
0.4
0.5
Density
Distribution of standardized residuals
t(df=3.9)
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00
ACF of standardized residuals
0 5 10 15 20 25 30 35
1.00
0.75
0.50
0.25
0.00
0.25
0.50
0.75
1.00 ACF of standardized residuals squared
2.5: Write code to plot a 1-by-2 subplot figure that shows the fitted conditional
volatility implied by the best-fitted AR(p)-GARCH(p
∗
, q∗
) model found in
Task 2.3 against that implied by the best-fitted ARMA(p, q) model found in
Task 2.1 for each stock in your sample. Your figure should look similar to the
following.
2010
2012
2014
2016
2018
2020
Date
1
2
3
4
5
6
7
Fitted conditional volatility for stock WBA
AR(2)-GARCH(1,1)
ARMA(2,2)
2010
2012
2014
2016
2018
2020
Date
1
2
3
4
5
6
Fitted conditional volatility for stock WMT
AR(2)-GARCH(3,0)
ARMA(2,3)
(3 marks)
Task 3: Return-Volatility Forecasting (Σ = 25 marks)
3.1: Use data between 01/01/2021 and 31/12/2023 as out-of-sample data, write
code to compute one-step forecasts, together with 95% confidence interval
(CI), for the returns of each stock using the respective best-fitted ARMA(p, q)
model found in Task 2.1. You should extend the in-sample data by one observation each time it becomes available and apply the fitted ARMA(p, q) model
to the extended sample to produce one-step forecasts. Do NOT refit the
ARMA(p, q) model for each extending window.2 For each stock, the forecast
output is a data frame with 3 columns f, fl and fu corresponding to the
one-step forecasts, 95% CI lower bounds, and 95% CI upper bounds. (5 marks)
3.2: Write code to plot a 1-by-2 subplot figure showing the one-step return
forecasts found in Task 3.1 against the true values during the out-of-sample
2Refitting the model each time a new observation comes generally gives better forecasts. However,
it slows down the program considerably so we do not pursue it here.
5
Ac.F633 - Python Programming Final Individual Project
period for both stocks in your sample. Also show the 95% confidence interval
of the return forecasts. Your figure should look similar to the following.
2021-05
2021-09
2022-01
2022-05
2022-09
2023-01
2023-05
2023-09
Date
10.0
7.5
5.0
2.5
0.0
2.5
5.0
7.5
ARMA(2,2) One-step return forecasts - WBA
Observed
Forecasts
95% IC
2021-05
2021-09
2022-01
2022-05
2022-09
2023-01
2023-05
2023-09
Date
12.5
10.0
7.5
5.0
2.5
0.0
2.5
5.0
ARMA(2,3) One-step return forecasts - WMT
Observed
Forecasts
95% IC
(3 marks)
3.3: Write code to produce one-step analytic forecasts, together with 95%
confidence interval, for the returns of each stock using respective best-fitted
AR(p)-GARCH(p
∗
, q∗
) model found in Task 2.3. For each stock, the forecast
output is a data frame with 3 columns f, fl and fu corresponding to the
one-step forecasts, 95% CI lower bounds, and 95% CI upper bounds. (4 marks)
3.4: Write code to plot a 1-by-2 subplot figure showing the one-step return
forecasts found in Task 3.3 against the true values during the out-of-sample
period for both stocks in your sample. Also show the 95% confidence interval
of the return forecasts. Your figure should look similar to the following.
2021-05
2021-09
2022-01
2022-05
2022-09
2023-01
2023-05
2023-09
Date
15
10
5
0
5
10
15
AR(2)-GARCH(1,1) One-step return forecasts - WBA
Observed
Forecasts
95% IC
2021-05
2021-09
2022-01
2022-05
2022-09
2023-01
2023-05
2023-09
Date
15
10
5
0
5
10
15
AR(2)-GARCH(3,0) One-step return forecasts - WMT
Observed
Forecasts
95% IC (3 marks)
3.5: Denote by et+h|t = yt+h − ybt+h|t
the h-step forecast error at time t, which
is the difference between the observed value yt+h and an h-step forecast ybt+h|t
produced by a forecast model. Four popular metrics to quantify the accuracy
of the forecasts in an out-of-sample period with T
′ observations are:
1. Mean Absolute Error: MAE = 1
T′
PT
′
t=1 |et+h|t
|
2. Mean Square Error: MSE = 1
T′
PT
′
t=1 e
2
t+h|t
3. Mean Absolute Percentage Error: MAPE = 1
T′
PT
′
t=1 |et+h|t/yt+h|
4. Mean Absolute Scaled Error: MASE = 1
T′
PT
′
t=1
et+h|t
1
T′−1
PT′
t=2 |yt − yt−1|
.
6
Ac.F633 - Python Programming Final Individual Project
The closer the above measures are to zero, the more accurate the forecasts.
Now, write code to compute the four above forecast accuracy measures for
one-step return forecasts produced by the best-fitted ARMA(p,q) and AR(p)-
GARCH(p
∗
,q
∗
) models for each stock in your sample. For each stock, produce
a data frame containing the forecast accuracy measures of a similar format
to the following, with columns being the names of the above four accuracy
measures and index being the names of the best-fitted ARMA and AR-GARCH
model:
MAE MSE MAPE MASE
ARMA(2,2)
AR(2)-GARCH(1,1)
Print a statement similar to the following for your stock sample:
For WBA:
Measures that ARMA(2,2) model produces smaller than AR(2)-GARCH(1,1)
model:
Measures that AR(2)-GARCH(1,1) model produces smaller than ARMA(2,2)
model: MAE, MSE, MAPE, MASE. (5 marks)
3.6: Using a 5% significance level, conduct the Diebold-Mariano test for each
stock in your sample to test if the one-step return forecasts produced by the
best-fitted ARMA(p,q) and AR(p)-GARCH(p
∗
,q
∗
) models are equally accurate
based on the three accuracy measures in Task 3.5. For each stock, produce a
data frame containing the forecast accuracy measures of a similar format to
the following:
MAE MSE MAPE MASE
ARMA(2,2)
AR(2)-GARCH(1,1)
DMm
pvalue
where ‘DMm’ is the Harvey, Leybourne & Newbold (1997) modified DieboldMariano test statistic (defined in the lecture), and ‘pvalue’ is the p-value associated with the DMm statistic. Draw and print conclusions whether the bestfitted ARMA(p,q) model produces equally accurate, significantly less accurate
or significantly more accurate one-step return forecasts than the best-fitted
AR(p)-GARCH(p
∗
,q
∗
) model based on each accuracy measure for your stock
sample.
Your printed conclusions should look similar to the following:
For WBA:
Model ARMA(2,2) produces significantly less accurate one-step return
forecasts than model AR(2)-GARCH(1,1) based on MAE.
Model ARMA(2,2) produces significantly less accurate one-step return
forecasts than model AR(2)-GARCH(1,1) based on MSE.
Model ARMA(2,2) produces significantly less accurate one-step return
forecasts than model AR(2)-GARCH(1,1) based on MAPE.
Model ARMA(2,2) produces significantly less accurate one-step return
forecasts than model AR(2)-GARCH(1,1) based on MASE. (5 marks)
7
Ac.F633 - Python Programming Final Individual Project
Task 4: (Σ = 20 marks)
These marks will go to programs that are well structured, intuitive to use (i.e.
provide sufficient comments for me to follow and are straightforward for me
to run your code), generalisable (i.e. they can be applied to different sets of
stocks (2 or more)) and elegant (i.e. code is neat and shows some degree of
efficiency).
8
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!