美文网首页
COMP226作业代做、R语言作业代写、代写Limit Orde

COMP226作业代做、R语言作业代写、代写Limit Orde

作者: jiuqiezhan | 来源:发表于2019-04-01 08:51 被阅读0次

COMP226 Assignment 1: Limit OrderBook PricerContinuousAssessment Number1 (of 2)Weighting 10%Assignment Circulated 10:00 Tuesday 19 February 2019Deadline 12:00 Thursday 7 March 2019Submission Mode Electronic onlyhttp://www.csc.liv.ac.uk/cgi-bin/submit.plLearning OutcomesAssessedThis assignment will address the following learning outcomes: Have an understanding of market microstructure and itsimpact on trading. Understand the spectrum of computer-based tradingapplications and techniques, from profit-seeking tradingstrategies to execution algorithms. Understand the benchmarks used to evaluate executionalgorithms.Purpose of Assessment The goal of this assignment is to implement a limit order bookpricerMarking Criteria Correctness (80%); Readability (20%). See the end of thisdocument.Submission necessaryin order to satisfymodule requirementsNoLate SubmissionPenaltyStandard UoL policy; note that no resubmissions after thedeadline will be considered.Expected time taken Roughly 8-12 hoursPlease submit a single file called MWS-username.R, where MWS-username is your MWSusername (which you use to log on to the submission system)This file must contain a function called pricer, whose form and functionality is describedbelow. The file may also contain other functions used by pricer, but the function pricershould not be called within the file.WarningYour code will be put through the departments automatic plagiarism and collusiondetection system. Students found to have plagiarized or colluded will likely receive amark of zero. Do not discuss or show your work to other students. Several studentswere found to have plagiarised in previous years and this had serious consequencesfor their studies (two students had their studies terminated and left without a degree).To aid with marking, your code will be put through a number of automatic tests, so youmust ensure that it is written as specified below.Learning OutcomesThe syllabus for COMP226 can be found here:http://intranet.csc.liv.ac.uk/teaching/modules/module.php?code=COMP226This assignment will address the following two learning outcomes: Have an understanding of market microstructure and its impact on trading. Understand the spectrum of computer-based trading applications and techniques, fromprofit-seeking trading strategies to execution algorithms. Understand the benchmarks used to evaluate execution algorithms.MarkingThe marking will be as follows: 80% for correctness; this will be determined primarily by automatic tests. If your codefails many of these then a mark will be decided via manual testing of your code. 20% for readability of your code; first and foremost you should ensure that your codeso is correct. The next most important thing is that it can be understood by others; toaid its readability your are encouraged to include clear informative comments.BackgroundIn this exercise you will write an R program to analyse the log file of a limit order bookmarket.The log file contains messages that describe changes to the book. Each message either adds an order to the book, or reduces the size of an order in the book (possibly removing the order entirely).ProblemThe function pricer should take three arguments as followspricer pricer should write its output to the file outfile. The file infile contains the messages ofthe limit order book log file, as described in more detail below.As the book is modified (according to the messages, which should be processed in order),pricer calculates the total expense you would incur if you bought targetsize shares (by taking as many asksas necessary, lowest first), and the total income you would receive if you sold targetsize shares (by hitting as manybids as necessary, highest first).Each time the income or expense changes, it prints the changed value to outfile inthe format described below.Input FormatThe market data log contains one message per line (terminated by a single linefeedcharacter, ), and each message is a series of fields separated by spaces.An Add Order to Book message looks like this:timestamp A order-id side price sizeWhere all fields are variables except A, which is a constant (examples below).Field MeaningtimestampThe time when this message was generated by the market, as millisecondssince midnight.A A literal string identifying this as an Add Order to Book message.order-id A unique string that subsequent Reduce Order messages will use to modifythis order.side A B if this is a buy order (a bid), and a S if this is a sell order (an ask).price The limit price of this order.size The size in shares of this order, when it was initially sent to the market bysome stock trader.A Reduce Order message looks like this:timestamp R order-id sizeWhere all fields are variables except R, which is a constant (examples below).Field MeaningtimestampThe time when this message was generated by the market, as millisecondssince midnight.R A literal string identifying this as an Reduce Order message.order-id The unique string that identifies the order to be reduced.size The amount by which to reduce the size of the order. This is not the new sizeof the order. If size is equal to or greater than the existing size of the order,the order is removed from the book.The log file messages are sorted by timestamp.Output Formatpricers output consists of one message per line in this format:timestamp action totalField MeaningtimestampThe timestamp from the input message that caused this output message tobe generated.action A string: B if this message contains the new expense to buy targetsizeshares, and S if this message contains the new income for sellingtargetsize shares.total The total expense (if action is B) to buy targetsize shares, or the totalincome (if action is S) for selling targetsize shares. If the book does notcontain targetsize shares in the appropriate type of order (asks forexpense; bids for income), the total field contains the string NA.If pricer encounters an error in an input message, it prints a warning to the R console andgoes to the next message.Example Input and OutputHere is an example run of pricer with a targetsize of 200. Input messages are in the leftcolumn. Notes and output messages are in the right column.Standard Input Standard Output/Notes28800538 A b S 44.26 100 No output yet because neither the bids nor the asksin the book have a total of 200 shares yet.28800562 A c B 44.10 100 Still not enough shares on either side of the book.28800744 R b 100 This reduces order b to zero shares, which removesit from the book, so now the book contains no asks.But theres still no change to the total income orexpense on 200 shares.28800758 A d B 44.18 157 The bid sizes now total 257, which is more than thetarget size of 200. To sell 200 shares, you would firsthit the bid at 44.18 for 157 shares, spending$6936.26. Then you would hit the bid at 44.10 forthe remaining 43 shares, spending another$1896.30. Your total income would be $8832.56, sopricer emits this message:28800758 S 8832.5628800773 A e S 44.38 100 The book now contains a single ask of size 100,which is still not enough to change the target sizeexpense from NA.28800796 R d 157 This removes bid d from the book, leaving just onebid with a size of 100 on the book, so the incomefrom selling changes to NA:28800796 S NA28800812 A f B 44.18 157 This new bid brings the total bid size back over 200,so the selling income is no longer NA:28800812 S 8832.5628800974 A g S 44.27 100 This ask brings the total ask size up to 200, exactlythe target size. The total expense for buying 200shares would be 100 * $44.27 + 100 * $44.38:28800974 B 8865.0028800975 R e 100 Removing ask e from the book leaves less than 200shares on the ask side, so the buying expensechanges back to NA:28800975 B NA28812071 R f 100 Reducing bid f by 100 shares leaves only 157shares on the bid side, so the selling income changesto NA:28812071 S NA28813129 A h B 43.68 50 This new bid makes it possible to sell 200 shares: 57at $44.18, 100 at $44.10, and the last 43 at $43.68.28813129 S 8806.5028813300 R f 57 This removes bid f from the book, so it is no longerpossible to sell 200 shares:28813300 S NA28813830 A i S 44.18 100 This ask makes it possible to buy 200 shares again:100 at $44.18 and 100 at $44.27.28813830 B 8845.0028814087 A j S 44.18 1000 This ask has the same price as an existing ask, andthese two asks are tied for the best asking price.This means you could now buy all 200 shares at$44.18 instead of buying half of them at $44.27, sothe buying expense decreases:28814087 B 8836.0028814834 R c 100 This leaves only 50 shares on the bid side (all inorder h), so it is still not possible to sell 200 shares.The selling income is therefore unchanged from NAand pricer prints no output message.28814864 A k B 44.09 100 Only 150 shares on the bid side, so no outputneeded.28815774 R k 100 Back to 50 shares on the bid side; still no outputneeded.28815804 A l B 44.07 175 There are now more than 200 shares on the bid side.You could sell 175 shares at $44.07 each, and theremaining 25 shares at $43.68 each:28815804 S 8804.2528815937 R j 1000 After ask j is removed from the book, you can stillbuy 200 shares: 100 at $44.18 each, and 100 at theworse price of $44.27.28815937 B 8845.0028816245 A m S 44.22 100 Since $44.22 is a better price than $44.27, thebuying expense decreases:28816245 B 8840.00Note that the book initially contains no orders, and that the buying expense and sellingincome are both considered to start at NA. Since pricer only produces output when theincome or expense changes, it does not print anything until the total size of all bids or thetotal size of all asks meets or exceeds targetsize.Test DataYou can download three sample input files here:https://www2.csc.liv.ac.uk/~rahul/teaching/comp226/assess.htmlYour program needs to work with any targetsize.In case you want to test your implementation on the example input data from above, here itis in an easy-to-cut-and-paste format:28800538 A b S 44.26 10028800562 A c B 44.10 10028800744 R b 10028800758 A d B 44.18 15728800773 A e S 44.38 10028800796 R d 15728800812 A f B 44.18 15728800974 A g S 44.27 10028800975 R e 10028812071 R f 10028813129 A h B 43.68 5028813300 R f 5728813830 A i S 44.18 10028814087 A j S 44.18 100028814834 R c 10028814864 A k B 44.09 10028815774 R k 10028815804 A l B 44.07 17528815937 R j 100028816245 A m S 44.22 100And here is the corresponding output:28800758 S 8832.5628800796 S NA28800812 S 8832.5628800974 B 8865.0028800975 B NA28812071 S NA28813129 S 8806.5028813300 S NA28813830 B 8845.0028814087 B 8836.0028815804 S 8804.2528815937 B 8845.0028816245 B 8840.00HintsWe did some relevant things in the Worksheet 02. For example, we computed theaverage price of a market order; the total price was obviously part of that calculation.Some further guidance follows.Data InputThere are many ways to read and write data in R.read.table reads in a file and returns a data.frame. If you are reading in strings and wantthem to stay as strings (rather than become factors) you should add to the argumentsstringsAsFactors=FALSE. There are variants of read.table that you may want to checkout, like read.csv and read.csv2.Also the data in the assignment does not all have the same number of fields per line. Thusyou want to use the fill=TRUE argument.An alternative to reading in the whole input file is to read it line by line. For that open aconnection using file. For example,con while (length(oneLine 0) { # do stuff, for example print(oneLine)}close(con)The line by line approach will be slow. For a very large file it may not be possible to read thewhole file into memory in which case one would typically use an incremental approach butreading in chunks rather than lines (read.table allows that).NoteOne problem you have to solve for Assignment 1 is that there are two types ofmessage with different fields. There are different ways to approach this, and its left toyou to decide what to do.Why dont you start right a way and load some of the sample data for Assignment 1 into R.Data OutputThere is a function write.table, however for Assignment 1 one you may just want to writeeach output line as it is produced (rather than store the output and only write it to a file inthe end).One way to write the output incrementally is with cat.> price > cat(file=test.out,The price is, price, )Now look in your working directory and you will find the file test.out.> file.show(test.out)The price is 100(END)For Assignment 1 you may want to append to a file, which cat does as follows:> price > cat(file=test.out,append=TRUE,The price is now, price, )> file.show(test.out)The price is 100The price is now 101(END)By the way, cat will write to the console if a file is not provided to it as an argument.One other function you will need is format. The best way to check that your program forAssignment 1 is correct is to run it on the sample input and compare your output with thesample output; the easiest way to do this is with a text file comparison tool such a diff onLinux/Unix systems. For diff tools on other platforms seehttp://stackoverflow.com/questions/12625/best-diff-toolAnyway, use these diff tools to make your output identical to the sample output, andformat can help you do that. For example,> prices > cat(prices, )800.5 800.25 800> cat(format(prices,nsmall=2), )800.50 800.25 800.00Calling the function pricerYou need to make sure that when your source code is sourced with something likesource(x3xx.R)that is gives no errors, and, will then allow the automatic tests to call pricer somewhat likewhat follows.pricer(infile=PATH_TO_INPUT,outpfile=PATH_TO_OUTPUT,targetsize=50)Do not include the call to pricer in the file you submit.Thats it. Good luck, and if you have questions please ask in the practicals or in the lectures.MAKE SURE YOU READ THIS DOCUMENT CAREFULLY - ALMOST ALL THEINFORMATION YOU NEED TO COMPLETE THIS ASSIGNMENT IS EITHER HERE INTHIS DOCUMENT OR IN THE SLIDES OR WORKSHEETS.本团队核心人员组成主要包括硅谷工程师、BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 微信:codehelp

相关文章

网友评论

      本文标题:COMP226作业代做、R语言作业代写、代写Limit Orde

      本文链接:https://www.haomeiwen.com/subject/dekmbqtx.html