最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

R語(yǔ)言代做編程輔導(dǎo)COMP 226: Computer-based trading in financial markets(附

2022-12-17 22:28 作者:拓端tecdat  | 我要投稿

全文鏈接:http://tecdat.cn/?p=30948

Limit Order Book Pricer

Submit your code via department electronic submission system.
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

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

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

InputOuputtargetsiz e = 1targetsize = 250targetsize = 1000sample1sample2sample3

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/Notes28800538 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

部分解答

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')} ? ? ? ? ? ? ? ? ? ? ?} ? ?} ? ? ? ? ? ?} }


R語(yǔ)言代做編程輔導(dǎo)COMP 226: Computer-based trading in financial markets(附的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
铜山县| 长沙市| 营山县| 灯塔市| 蛟河市| 泌阳县| 高青县| 洮南市| 龙江县| 抚宁县| 腾冲县| 项城市| 依安县| 阿克苏市| 高陵县| 信宜市| 万年县| 左权县| 嘉峪关市| 资中县| 松阳县| 格尔木市| 长沙县| 沐川县| 祁连县| 长汀县| 深水埗区| 汶上县| 同德县| 青冈县| 万宁市| 池州市| 青川县| 肃南| 海林市| 仁怀市| 女性| 闵行区| 淮阳县| 枞阳县| 正阳县|