R blpapi forward spread as points or outright - blpapi

I am using the blpapi package in R to download FX forward prices. In the formula I want to specify the setting to download forward prices as points or as outright prices. I have tried the following:
conn <- blpConnect()
sdate <- as.Date("1998-12-31")
edate <- Sys.Date()-1
vFWD <- c("EURAUD1M Curncy")
opts.daily <- c("periodicitySelection"="DAILY","nonTradingDayFillMethod"="PREVIOUS_VALUE","nonTradingDayFillOption"="NON_TRADING_WEEKDAYS")
opts.monthly <- c("periodicitySelection"="MONTHLY","nonTradingDayFillMethod"="PREVIOUS_VALUE","nonTradingDayFillOption"="NON_TRADING_WEEKDAYS")
opts.fwd <- c("FWD_CURVE_QUOTE_FORMAT"="OUTRIGHTS")
dfwd <- bdh(securities = vFWD, c("PX_LAST"), start.date = sdate, end.date = edate, options = opts.daily, overrides = opts.fwd, con = defaultConnection())
** for Java coding the answer is here: In Bloomberg API how do you specify to get FX forwards as a spread rather than absolute values?

Use "OUTRIGHT", not "OUTRIGHTS" as your override option value.

Related

is there any way to switch ImageJ macro code to python3 code?

I'm making an app in python3 and I want to use some function in imagej. I used macro recorder to switch to python code but it got really messy, now I don't know how to do next. Can someone help me, please.
Here is the marco recorder code and my marco code
imp = IJ.openImage("D:/data/data_classify/data_train/1/9700TEST.6.tiff40737183_2.jpg");
//IJ.setTool("line");
//IJ.setTool("polyline");
xpoints = [177,155,114,101,100,159,179];
ypoints = [82,94,109,121,133,163,173];
imp.setRoi(new PolygonRoi(xpoints,ypoints,Roi.POLYLINE));
IJ.run(imp, "Straighten...", "title=9700TEST.6.tiff40737183_2-1.jpg line=30");
my python3 code
mport imagej
from scyjava import jimport
ij = imagej.init('2.5.0', mode='interactive')
print(ij.getVersion())
imp = ij.IJ.openImage("D:/data/data_classify/data_train/1/9700TEST.6.tiff40737183_2.jpg")
xpoints = [177,155,114,101,100,159,179]
xpoints_int = ij.py.to_java(xpoints)
ypoints = [82,94,109,121,133,163,173]
ypoints_int = ij.py.to_java(xpoints)
straightener = jimport('ij.plugin.Straightener')
polyRoi = jimport('ij.gui.PolygonRoi')
and I don't know how to do next...
After a few days, I finally found the answer. It is important to understand the parameters of the function to write, I have referenced in:
https://pyimagej.readthedocs.io/en/latest/
https://imagej.nih.gov/ij/developer/api/ij/module-summary.html
in my example the next thing i need is polygonroi from the given coordinates. I found the required coefficients of PolygonRoi in the above website and determined to take as parameters PolygonRoi​(int[] xPoints, int[] yPoints, int nPoints, int type)
Next, I found a way to convert my list of coordinates to an int[] which was shown in the pyimagej tutorial.
In the type section, I can find it by trying print(int(roi.PolygonRoi)) and the result is 6, you can also find the reason in the website above in the Roi section
The rest, the last thing you need to do is put that PolygonRoi into the Straightener function with the line value you want
Here is my code for using macro Imagej in Python3
import imagej
from scyjava import jimport
from jpype import JArray, JInt
ij = imagej.init('2.5.0', mode='interactive')
print(ij.getVersion())
imp = ij.IJ.openImage("D:/AI lab/joint_detection/data/1/9700TEST.6.tiff133328134_1.jpg")
xpoints = [124,126,131,137,131,128,121,114]
xpoints_int = JArray(JInt)(xpoints)
ypoints = [44,63,105,128,148,172,194,206]
ypoints_int = JArray(JInt)(ypoints)
straightener = jimport('ij.plugin.Straightener')
polyRoi = jimport('ij.gui.PolygonRoi')
roi = jimport('ij.gui.Roi')
new_polyRoi = polyRoi(xpoints_int,ypoints_int,len(xpoints), int(roi.POLYLINE))
imp.setRoi(new_polyRoi)
straightened_img = ij.IJ.run(imp, "Straighten...", "title=9700TEST.6.tiff40737183_2-1.jpg line=30")
ij.IJ.saveAs(straightened_img, 'Jpeg', './test.jpg')

R quanteda twitter archives search always the same fie as output

Trying to extract Twitter data with timelines, like:
Tage <- seq(as.Date("2021-12-28"),as.Date("2021-12-30"),
by = "day")
for (i in 2:length(Tage)) {
lower <- paste0(Tage[i-1],"T00:00:01Z")
upper <- paste0(Tage[i],"T00:00:01Z")
df <- full_archive_search(token = Bearer_Token,
search_query = query,
start_time = lower,
end_time = upper,
n = 2500,
n_try = 10)
if(is.null(df)==T){
(... from https://github.com/MaelKubli/RTwitterV2/blob/main/README.md)
I always get the same results file when changing dates ..
although the collecting processes seem to work fine:
"2021-12-21T00:00:01Z to 2021-12-22T00:00:01Z has been colleted!
2021-12-22T00:00:01Z to 2021-12-23T00:00:01Z has been colleted!"
Using RDS-files for saving, all files at the end contain the same data..
Could somebody help? What could be wrong?

spatstat integer overflow error in Kcross and crosspairs

I'm working with spatstat 2.3-4 in R 4.1.0 on a 64bit windows 10 pro machine.
Recently I ran into the integer-overflow error while using Kcross with a large number of points (i.e. the number of combination exceeded .Machine$integer.max). For example:
W <- as.owin(list(xrange = c(688.512, 17879.746) , yrange = c(-27996.842, -7759.813)))
cells1 <- runifpoint(n = 8062, win = W)
cells2 <- runifpoint(n = 1768988, win = W)
cells3 <- superimpose(tumor = cells1 , bcell = cells2)
Kcross(cells3 , r = seq(0,200,by=5) , "tumor" , "bcell" , correction="none") # error
# Error in if (nXY <= 1024) { : missing value where TRUE/FALSE needed
# In addition: Warning message: In nX * nY : NAs produced by integer overflow
8062 * 1768988 > .Machine$integer.max
# [1] TRUE
After a lot of struggling I realized that the error comes from this part of crosspairs:
if (spatstat.options("crosspairs.newcode")) {
nXY <- nX * nY
if (nXY <= 1024) {
nsize <- 1024
}
I could "fix" the error by changing spatstat options: spatstat.options("crosspairs.newcode" = FALSE).
Is this the way to deal with the error?
UPDATE:
As Adrian.Baddeley answered below, there is now a new spatstat.geom version on GitHub (currently: v2.4.-0.029) in which the bug is fixed. The new version works fine without the change of the options.
The bug is fixed in the development version of spatstat.geom available at the GitHub repository
This is a bug in some relatively new code to speed up the underlying function crosspairs.ppp(). Until a new version of spatstat.geom is available you can workaround the problem by setting spatstat.options("crosspairs.newcode" = FALSE) as suggested.

Quinlan Attribute C5.0

Error in UseMethod("QuinlanAttributes") :
no applicable method for 'QuinlanAttributes' applied to an object of class "logical"
I am getting this error whenever I am running a code. I have installed several packages but this error is keep on repitiating.
it seems that C50 does not accept BOOLEAN features.
you can simpliy drop that column or replace BOOLEAN to 0/1.
if "tdata$Windy" is the BOOLEAN feature, replace the value of it.
library(C50)
tdata = read.csv('play.csv', header = TRUE, sep = ",")
xdata <- data.frame(tdata$Outlook,tdata$Temperature, tdata$Humidity, tdata$Windy)
ydata <- tdata$Play
treeModel <- C5.0(x = xdata, y = ydata )
summary(treeModel)
It's old question but I had same issue today and realized it's was due to read_sav().
I solved applying haven::as_factor to columns that should be factors.
data <- read_sav("datafile.sav")
data <- mutate(data, across(ends_with("_fct"), haven::as_factor ))

Error in (function (classes, fdef, mtable)

I have run this topic modeling script two months ago SUCCESSFULLY, but it suddenly gives me an error message (in the last three lines).
post <- posterior(TM1, newdata = dtm[-c(1:20),]) #this script gives me an error message.
perplex <- perplexity(TM1, newdata = dtm[-c(1:20),]) #this script does not give me an error message.
Can anybody help me what is going on here? Please~~
=====================
library("tm")
library("slam")
library("topicmodels")
library("SnowballC")
corpus <- Corpus(DirSource(directory="/Users/loni/Documents/TextMining/test", encoding="UTF-8"))
dtm <- DocumentTermMatrix(corpus, control=list(stemming=TRUE, stopwords=TRUE, removePunctuation=FALSE))
term_tfidf <- tapply(dtm$v/row_sums(dtm)[dtm$i], dtm$j, mean) * log2(nDocs(dtm)/col_sums(dtm>0))
dim(dtm)
[1] 26 919
dtm <- dtm[, term_tfidf >= .06] # petition corpus
dtm <- dtm[row_sums(dtm) > 0,]
dim(dtm)
[1] 26 499
k<-5
SEED <- 2
TM <- list(VEM = LDA(dtm, k = k, control = list(seed = SEED)))
TM1 <- list(VEM = LDA(dtm[c(1:20),], k = k, control = list(seed = SEED))) #validation
Topic <- topics(TM[["VEM"]],1)
Terms <- terms(TM[["VEM"]], 8)
Terms[, 1:5]
post <- posterior(TM1, newdata = dtm[-c(1:20),])
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘posterior’ for signature ‘"list", "DocumentTermMatrix"’
It could be because of wrong indexing of list. Try [[]] or [] on TM1
I had the same error today and found that the issue was because I had other packages loaded that conflicted. The easiest fix was to create a new session with a clear workspace, and rerun the script.
This answer to a similar question clued me in:
Unable to find an inherited method for function ‘select’ for signature ‘"data.frame"’

Resources