R语言代做编程辅导COMP 226: Computer-based trading in financial markets(附答案)

Limit Order Book Pricer

Submit your code via department electronic submission system.

LE PHUONG撰写

http://www.csc.liv.ac.uk/cgi-bin/submit.pl

Please submit a single file called x3xx.R (cs-username.R)
This file must contain a function called pricer

pricer can call other functions in the same file

×

现在提到了代写服务,肯定很多人都不会觉得陌生,就算是国内也是有着专业代写作业的服务行业的,能够为有需求的学生提供很多的帮助,不过其实代写机构在国外会更获得学生的支持,这是因为国外的学校对于平时的作业要求比较严格,为了获得更高的分数顺利毕业,不少留学生就会让代写机构帮忙完成作业,比较常见的作业代写类型,就是计算机专业了,因为对于留学生来说这个技术对于Machine Learning或者AI的代码编程要求更高,所以找代写机构完成作业会简单轻松很多,那么代写机构的水平,要怎么选择才会比较高?

1、代写机构正规专业

不论是在什么情况下,选择正规合法经营的机构肯定是首要的操作,这也是为了避免自己在找机构的时候,出现上当受骗的现象,造成自己的经济出现损失,带来的影响还是非常大的,所以需要注意很多细节才可以,所以在这样的情况下,代写机构的选择,也要选择在经营方面属于正规合法的类型,这样才可以保证服务进行的时候,不会出现各种问题,也可以减少损失的出现,而且正规合法也是代写机构的合格基础。

2、代写机构编程能力

作业的难度相信很多人都很熟悉,特别是对于AI深度学习或者是人工神经网络这种算法来说,因为要对SVM、Design Tree、线性回归以及编程有很高的要求,可以说作业的完成要求非常高,因此才会带动代写机构的发展,找专业的代写机构,一般都是会有专业的人员帮忙进行作业的完成,因为这类型的作业对专业要求比较高,因此代写机构也要具备专业能力才可以,否则很容易导致作业的完成出现问题,出现低分的评价。

3、代写机构收费情况

现在有非常多的留学生,都很在意作业的完成度,为了保证作业可以顺利的被完成,要进行的相关操作可是非常多的,代写机构也是因为如此才会延伸出来的,在现在发展也很迅速,现在选择代写机构的时候,一定要重视收费情况的合理性,因为代写作业还是比较费精力的,而且对于专业能力要求也高,所以价格方面一般会收取几千元至万元左右的价格,但是比较简单的也只需要几百元价格。

4、代写机构完成速度

大部分人都很在意代写机构的专业能力,也会很关心要具备什么能力,才可以展现出稳定的代写能力,其实专业的代写机构,对于作业完成度、作业完成时间、作业专业性等方面,都是要有一定的能力的,特别是在完成的时间上,一定要做到可以根据客户规定的时间内完成的操作,才可以作为合格专业的代写机构存在,大众在选择的时候,也可以重视完成时间这一点来。

现在找专业的CS代写机构帮忙完成作业的代写,完全不是奇怪的事情了,而且专业性越强的作业,需要代写机构帮忙的几率就会越高,代写就发展很好,需求量还是非常高的,这也可以很好的说明了,这个专业的难度以及专业性要求,才可以增加代写机构的存在。



But the function pricer should not be executed when the file is sourced with source(‘cs-username.R’)

Problem

Create R program to analyse log file of a limit order market
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)

Example Input

28800538 A b S 44.26 100  
28800562 A c B 44.10 100  
28800744 R b 100  
28800758 A d B 44.18 157  
28800773 A e S 44.38 100  
28800796 R d 157  
28800812 A f B 44.18 157  
28800974 A g S 44.27 100  
28800975 R e 100  
28812071 R f 100  
28813129 A h B 43.68 50

Problem

You should write a function called pricer
It takes an positive integer called targetsize and an argument
and calculates:

• total expense to buy targetsize shares (by taking as
many asks as necessary, lowest first), and
• total income if you sold targetsize shares (by hitting as
many bids as necessary, highest first)
Each time the income or expense changes, it prints the changed
value to an output file in the format described below

Corresponding example output

For targetsize = 200

28800758 S 8832.56  
28800796 S NA  
28800812 S 8832.56  
28800974 B 8865.00  
28800975 B NA  
28812071 S NA  
28813129 S 8806.50

python岭回归、Lasso、随机森林、XGBoost、Keras神经网络、kmeans聚类链家租房数据地理可视化分析

阅读文章


Arguments to pricer function

The function pricer should take three arguments as follows
pricer <- function(infile, outfile, targetsize)

• infile is a string which contain the path to the input file
which is read from the harddrive; the file infile contains the
messages of the limit order book log file
• pricer should write its output to the a file with path specified
the string outfile, which is an argument to pricer
• the final argument is targetsize, which is a natural number,
e.g., 1 or 100, or 250


随时关注您喜欢的主题


Example call to pricer

• suppose you have stored the a sample input file “sample1.txt”
in the current working directory; and
• suppose you have created an output directory called “output”
in the current working directory;
• suppose you want to try the function with targetsize=250
Then a call to pricer might then be:

pricer(infile="sample1.txt",  
outfile="output/output1_250.txt",  
targ

Test Data

You can download three sample input files here:
https://www2.csc.liv.ac.uk/~rahul/teaching/comp226/assess.html
For these three sample inputs, output for three values of
targetsize are given, so you have 9 examples to use for testing
Your program needs to workwith any value of `
“targetsize

Sample files

InputOuput
targetsiz e = 1targetsize = 250targetsize = 1000
sample1
sample2
sample3

Input Format

The input file will contain one message per line
Each message is a series of fields separated by spaces, e.g.
28800538 A b S 44.26 100
An Add Order to Book message looks like this:
timestamp ‘A’ order-id side price size
A Reduce Order message looks like this:
timestamp ‘R’ order-id size
The log file messages are sorted by timestamp

Output Format

pricer’s output should be one message per line in this format:
timestamp action total
28800758 S 8832.56

• If pricer encounters an error in an input message, it prints a
warning to the R console and goes to the next message
• Note: the book initially contains no orders, and the
buying expense and selling income start as ‘NA’
• Since pricer only produces output when the income/expense
changes, it does not print anything until the total size of
all bids or asks meets or exceeds targetsize

Standard InputStandard Output/Notes
28800538 A b S 44.26 100No output yet because neither the bids nor the asks in the book have a total of 200 shares yet.
28800562 A c B 44.10 100Still not enough shares on either side of the book.
28800744 R b 100This reduces order ‘b’ to zero shares, which removes it from the book, so now the book contains no asks. But there’s still no change to the total income or expense on 200 shares.

data.frame

• data.frame is a data structure in R, like a matrix, but
• unlike a matrix, the columns can be of different types

> df <- data.frame(a=1:3,  
b=c("A","B","C"),  
stringsAsFactors=F)  
> df  
a b  
1 1 A  
2 2 B  
3 3 C

部分解答

image.png
pricer <- function(infile,outfile,targetsize) {
  #infile<-"E:\\input.txt"
  #outfile<-"E:\\output1.txt"
  #targetsize=250
  
 
  
  Sbook=data.frame(Timestamp=c(NA),Type=c(NA),OrderId=c(NA),Side=c(NA),Price=c(NA),Size=c(NA))
  Bbook=data.frame(Timestamp=c(NA),Type=c(NA),OrderId=c(NA),Side=c(NA),Price=c(NA),Size=c(NA))
  Sbook<- Sbook[-1,]
  Bbook<- Bbook[-1,]
  flag1=0
  flag2=0
  
  
  for (i in 1: nrow(trade)){#type=A
    if(trade[i,"Type"]=="A"){
      if(trade[i,"Side"]=="B") {
        
        Bbook=rbind(Bbook,trade[i,])
        if(is.null(bprice(Bbook,targetsize))==FALSE) {
          cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " S ", format(bprice(Bbook,targetsize),nsmall=2),'\n')
          flag2=1
        }
        else{ if(flag2==1)cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " S NA",'\n')}
      }
      else {
        Sbook=rbind(trade[i,],Sbook)
        if(is.null(price(Sbook,targetsize))==FALSE) {
          cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " B ", format(price(Sbook,targetsize),nsmall=2),'\n')
          flag1=1
        }
        else{ if(flag1==1)cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " B NA",'\n')}
      
      }
    }
    #type=R
    else{
      reduceS=which(Sbook[1:i-1,"Order-Id"]==trade[i,"Order-Id"])
      if(is.null(reduceS)!=TRUE){
        Sbook[reduceS,"Size"]=as.numeric(Sbook[reduceS,"Size"])-as.numeric(trade[i,"Size"])
        if(length(Sbook[reduceS,"Size"])==0)Sbook=Sbook[-reduceS,]
        if(is.null(price(Sbook,targetsize))==FALSE) {
          cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " B ", format(price(Sbook,targetsize),nsmall=2),'\n')
          flag1=1
        }
        else{ if(flag1==1)cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " B NA",'\n')}
        
        
      }else {
        reduceB=which(Bbook[1:i-1,"Order-Id"]==trade[i,"Order-Id"])
        Bbook[reduceB,"Size"]=as.numeric(Bbook[reduceB,"Size"])-as.numeric(trade[i,"Size"])
        if(length(Bbook[reduceB,"Size"])==0)Bbook=Bbook[-reduceB,]
        if(is.null(bprice(Bbook,targetsize))==FALSE) {
          cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " S ", format(bprice(Bbook,targetsize),nsmall=2),'\n')
          flag2=1
        }
        else{ if(flag2==1)cat(file=outfile,append=TRUE,trade[i,"Timestamp"], " S NA",'\n')}
        
        
      }
    }
   
    
    
  }
}


image.png

关于分析师

在此对LE PHUONG对本文所作的贡献表示诚挚感谢,她在山东大学完成了计算机科学与技术专业的硕士学位,专注数据分析、数据可视化、数据采集等。擅长Python、SQL、C/C++、HTML、CSS、VSCode、Linux、Jupyter Notebook。

 
QQ在线咨询
售前咨询热线
15121130882
售后咨询热线
0571-63341498

关注有关新文章的微信公众号


永远不要错过任何见解。当新文章发表时,我们会通过微信公众号向您推送。

技术干货

最新洞察

This will close in 0 seconds