CS917 – 2022/23 Coursework 1 - Programming
Thursday week 5
项目类别:计算机

CS917 – 2022/23 Coursework 1 - Programming

Deadline: Thursday week 5 (31st  October 2024) at 12.00 noon. Please read the entire sheet before starting on Part A.

Background

Through lectures and exercise sheets you have gained some useful experience of the multi-paradigm programming language Python. In this coursework we would like you to use this knowledge to solve a number of real-world problems based on the analysis of cryptocurrency data. The dataset that you will be using is taken from the Bitcoin (BTC) cryptocurrency market, provided by CryptoCompare, a London based global cryptocurrency market data provider.

Data

The data that you need for this coursework is in a single CSV file called cryptocompare_btc.csv, which can be found on the module website. Within the CSV file, each row is formatted as follows:

1.    time: epoch timestamp in second (in UTC time zone) – indicates the day

2.    high: highest BTC price of the day

3.    low: lowest BTC price of the day

4.    open: first BTC price of the day

5.    close: last BTC price of the day

6.    volumefrom: total volume (i.e., the total amount of currency exchanged) of the day in BTC

7.    volumeto: total (i.e., the total amount of currency exchanged) volume of the day in USD

The data has been collected in daily between 28 April 2015 and 18 October 2020.

In this coursework, you will have to complete 4 exercises (Parts A, B, C, and D). Each part will be provided with a Python skeleton file (named partx.py – where x = {A, B, C,D}).

***IMPORTANT***: Please use those skeleton files for submission. That is, write your code into those  skeleton files,  and  follow the  instructions  regarding  the  recommended  types  of  the  input arguments, as well as the return values.

Timestamp vs. date time:

During the coursework, you will need to be able to convert the time in epoch timestamp value to human readable date time and vice versa. You can use the following code to do these conversions:

#Import time module to handle time conversions

import time

import calendar

#Set a timestamp value. Use any valid value here (smallest is 0)

timestamp = 1545730073

#Convert timestamp to a time.struct_time object with UTC time

dt = time.gmtime(timestamp)

#You can print out to see how it looks like. Basically it prints out

a tuple of 9 elements,

#e.g., time.struct_time(tm_year=2018, tm_mon=12, tm_mday=25, tm_hour=9,

tm_min=27, tm_sec=53, tm_wday=1, tm_yday=359, tm_isdst=0)

print(dt)

#Print in human readable string

date_string = time.strftime("%d/%m/%Y", dt)

print(date_string)

#For more about formatting, check https://www.programiz.com/python-

programming/time

#Now we convert from time to epoch timestamp (again, choose a valid

date)

date = “03/11/2020”

#We convert t to epoch timestamp in UTC time zone

timestamp = calendar.timegm(time.strptime(date, "%d/%m/%Y"))

print("UTC time:", utc_time)

***IMPORTANT***: Note that the data contains daylight saving time changes, so when you search for dates between start_date and end_date, please do not search for the exact start and end date values in epoch timestamp, as there might be a slight difference due to the convergence differences caused by the different ways daylight saving times are handled. So I suggest you to do the following simple trick: Instead of searching for the exact start_date, search for those dates in the data where date >= start_date, and similarly, date <= end_date.

Here’s an example for a how to handle it:

for d in range(len(data)):

row = data[d]

if int(row['time']) >= start_epoch and int(row['time']) <=

end_epoch:

{...}

Part A (25 Marks)

In this first part you are required to define 5 functions.

A1. The first of these functions is

highest_price(data, start_date, end_date) -> float

which given the data, a start date, and an end date (both are string with “dd/mm/yyyy” format) will return a positive or negative floating point number that is the highest price of the BTC currency in bitcoin within the given period.

A2. The second function

lowest_price(data, start_date, end_date) -> float

which given the data, a start date, and an end date (both are string with “dd/mm/yyyy” format) will return a positive or negative floating point number (accurate to 2 decimal places) that is the lowest price of the BTC currency in bitcoin within the given period.

A3. The third function

max_volume(data, start_date, end_date) -> float

which given the data, a start date, and an end date (both are string with “dd/mm/yyyy” format) will return a floating point number that is the maximal daily amount of exchanged BTC currency of a single day within the given period.

Update (31/10/2020): I have added the missing word here (max daily amount) to clarify what I would like you to return!

A4. The fourth function

best_avg_price(data, start_date, end_date) -> float

which given the data, a start date, and an end date (both are string with “dd/mm/yyyy” format) will return a highest daily average price of a single BTC coin in USD within the given period. To calculate the average price of a single BTC coin of a day, we take the ratio between the total volume in USD and the total volume in BTC (the former divided by the latter).

A5. Finally, the fifth function

moving_average(data, start_date, end_date) -> float

should return the average BTC currency price over the given period of time (accurate to 2 decimal places). The average price of a single day is calculated by the function in A4.

留学ICU™️ 留学生辅助指导品牌
在线客服 7*24 全天为您提供咨询服务
咨询电话(全球): +86 17530857517
客服QQ:2405269519
微信咨询:zz-x2580
关于我们
微信订阅号
© 2012-2021 ABC网站 站点地图:Google Sitemap | 服务条款 | 隐私政策
提示:ABC网站所开展服务及提供的文稿基于客户所提供资料,客户可用于研究目的等方面,本机构不鼓励、不提倡任何学术欺诈行为。