FNCE30012: Foundations of Fintech - Assignment 1
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
FNCE30012: Foundations of Fintech - Assignment 1
Question 1 (1 mark)
You will be plotting the returns as timeseries and histogram for Tesla (TSLA). Please use the provided variable names for the pandas dataframes.
Q1 (i) [0.5]
Write Python code that plots the time series of daily rate of Tesla. (returns on the y-axis and dates on the x- axis). Please ensure that your plot is appropriately labelled.
Please use the variable name df_prices for the dataframe to read the CSV containing the market data.
In [5]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
"""Write your code here to populate df_prices and plot time-series data""" # BEGIN - YOUR CODE GOES HERE df_prices = pd.read_csv("TSLA_returns.csv") df_prices returns = df_prices['return'] dates = df_prices ['date'] x = list(dates) y = list(returns) plt.xlabel('dates') plt.ylabel('returns') plt.title('time series of daily rate of Tesla') plt.xticks(np.arange(0,len(x),step=60)) plt.plot(x,y) # END - YOUR CODE GOES HERE |
executed in 195ms, finished 08:58:31 2022-09-04 |
Out[5]:
[
In [ ]:
Q1 (ii) [0.5]
Write Python code to plot the histogram (binned in 100 buckets) of the daily rate of returns of Tesla. Please ensure that your plot is appropriately labelled. You should use the df_prices variable.
In [6]:
1 2 3 4 5 6 7 8 9 10 |
"""Write your code here for histogram plot""" # BEGIN - YOUR CODE GOES HERE returns = df_prices['return'] returns = list(returns) plt.hist(returns, bins = 100) plt.xlabel('returns') plt.ylabel('frequncy') plt.title('the daily rate of retuns of Tesla') plt.show () # END - YOUR CODE GOES HERE |
executed in 291ms, finished 08:58:35 2022-09-04 |
Question 2 (2 marks)
In this question we will analyse the statistical properties of the returns for Tesla (TSLA).
Q2 (i) [1]
Use Python to compute the mean, standard deviation, skewness, and kurtosis for the returns of Tesla (TSLA). Store the values in the pre-defined variables. You should use the df_prices variable.
Predefined Variables
In [7]:
1 2 3 4 5 6 |
"""Predefined Variables - Do Not Change their Name - Remember to execute this cell once""" mean = None std = None skewness = None kurtosis = None |
executed in 3ms, finished 08:58:39 2022-09-04 |
In [8]:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
"""Populate the variables shown above with appropriate values here""" # BEGIN - YOUR CODE GOES HERE df_prices = pd.read_csv("TSLA_returns.csv") returns = df_prices['return'] mean = statistics.mean(returns) std = statistics.stdev(returns) skewness = scipy.stats.skew(returns, axis=0, bias=True) kurtosis = scipy.stats.kurtosis(returns, axis=0, bias=True) print('mean = ',mean) print('std = ',std) print('skewness = ',skewness) print('kurtosis = ',kurtosis) # END - YOUR CODE GOES HERE |
executed in 12ms, finished 08:58:41 2022-09-04 |
mean = 0.0015740330748483145
std = 0.034434708754710185
skewness = 0.07950109513976128
kurtosis = 2.123823807066368
In [ ]:
Q2 (ii) [0.5]
Statistically check if the distribution of daily returns are Normally distributed. Justify your answer by running a Jarque–Bera test on the rate of returns using Python. Please store the value of the Jarque-Bera stats and the corresponding p-value in the pre-defined variables.
For your convenience, the stats package from scipy is already part of the initial imports. You can find more information on the Jarque-Bera test in scipy here:
Predefined Variables
In [9]:
1 2 3 4 |
"""Predefined Variables - Do Not Change their Name - Remember to execute this cell once""" jarque_bera_stats = None p_value = None |
executed in 2ms, finished 08:58:45 2022-09-04 |
In [10]:
1 2 3 4 5
|
"""Populate the variables shown above with appropriate values here""" # BEGIN - YOUR CODE GOES HERE jarque_bera_test = stats.jarque_bera(returns) jarque_bera_stats = jarque_bera_test.statistic p_value = jarque_bera_test.pvalue |
2022-09-05