sure, add a grouping bucket defined by the sign of the amount... Select assetIdentifier, case when amount > 0 then 'debit' else 'credit' end typeTx, Avg(Amount) from table group by assetIdentifier, case when amount > 0 then 'debit' else 'credit' end or, if you want both values on a single...

'//a[text()="Next"]' or: '//table[@id = "yfncsumtab"]//a[text()="Next"]' or, to get just the first one: '//table[@id = "yfncsumtab"]//table[1]/tr/td/a[text()="Next"]' or: '//table[@id="yfncsumtab"]/tr[2]/td[1]/table[1]/tr/td/a[1]' The more specific you are, the faster it is to find the element. However, the more specific you are, the more brittle the xpath is: if the developers make a small change in...

It's probably a function name clash issue. Running timeSeries::getReturns(c('C','BAC'), start='2004-01-01', end='2008-12-31') gives me the error, but running stockPortfolio::getReturns(c('C','BAC'), start='2004-01-01', end='2008-12-31') works fine. How did this happen? You must have loaded the stockPortfolio package, and then loaded either timeSeries or another package that depends upon timeSeries. Have a look through your...

I originally wasn't going to answer as there is a lot here for beginning c++ but I thought it might be beneficial to give you a highlevel overview and make you aware of the learning curve involved. I think you should slow things down and take a look at a...

statistics,finance,accounting,trading

variables used: - pos_base = 0 // base price of the position, at any given time - pos_amount = 0 // position amount (negative for shorts), at any given time - pl = 0 // total P/L, at any given time, fees already removed - tot_fees = 0 // total...

java,implementation,finance,irr

Bisection Method, Newton's method, Secant Methods are some methods that are used to find/estimate the root of an equation. (Do some maths to know about those methods). To use those mathematical methods, you should have a algebraic equation. I think the classes you stated implements those mathematical methods of root...

This is just a simple error. You're comparing (bestBankName.equals("") || bestGrowth > growth) , which is if your current growth (so the first bank set) has a growth higher than the second bank. In other words, you flipped the arrow. You need to do if (bestBankName.equals("") || bestGrowth < growth)...

python,multiprocessing,finance,python-multiprocessing

I think your problem is that your Event code is broken. Imagine this scenario: main process calls sort for m. sort calls Q[m].put and E[m].set. Parse wakes up, does Q[m].get, and starts processing. main process calls sort again for the same m. sort calls Q[m].put and E[m].set. Parse finishes processing...

I did a long internship as a quant in a London IB and calculation of dates was not a trivial task and totally depending on the business application. You have all sorts of calendars, public holidays and other such things to take into account. It really depends on what calendar...

r,date,type-conversion,finance,quantitative-finance

Use data.frame() rather than cbind() if you want to preserve mixed types (ie have both dates and numeric values). The latter returns a matrix and a matrix can only hold a single atomic data type so it converts everything to numeric.

The easiest way is to create a column called Volume. Then to.period will magically do it for you. x <- cbind(myticks_xts$V5, Volume=1) to.period(x, "seconds", 10) # x.Open x.High x.Low x.Close x.Volume #2014-01-01 21:55:34.378 1.376669000 1.376669000 1.376669000 1.376669000 1 #2014-01-01 21:55:47.210 1.376737273 1.376737273 1.376737027 1.376737027 2 #2014-01-01 21:55:57.963 1.376737027 1.376737027 1.376737027...

If you have a complex black box function, and you need to tweak the inputs in a non-linear way, then this sounds like it might be a good application for using using a genetic algorithm (GA). What is a genetic algorithm? In general, you would encode one possible combination of...

java,file,project,nested-loops,finance

Formatted code: private static int Year() { Scanner input = new Scanner(System.in); int selectedYear; System.out.println("Choose one of the following years: "); System.out.println("[1] 2012 - - [2] 2013 - - [3] 2014"); selectedYear = input.nextInt(); return selectedYear; } private static int MainMenu() { /* Main menu of the program. */ Scanner...

objective-c,json,yahoo,finance,stock

Looks like Yahoo is putting out JSONP (JSON with padding). Sadly solutions seem to look like "take a substring of whatever's inside the parentheses and parse that." How to parse JSONP in Objective-C?...

r,finance,performanceanalytics

The 'historical' method is not a 'simulation' method. It is a measure of the realized historical loss quantile. I have added historical contribution to PerformanceAnaltytics in v 1.4.3574 on R-Forge. Your example now produces: > VaR(edhec, p=.95, method="historical", portfolio_method="component") no weights passed in, assuming equal weighted portfolio $hVaR hVaR 95%...

regex,awk,grep,finance,lookbehind

Since this is just a simple subsitution on a single line it's really most appropriate for sed: $ sed -n -r 's/(^Revenue)(,[^,]*){3}(.*),[^,]*,"\t\t".*/\1\3/p' file Revenue,444.000,333.000,222.000,111.00 but you can do the same in awk with gensub() (gawk) or match()/substr() or similar. It will run in the blink of an eye no matter...

r,finance,quantmod,trading,algorithmic-trading

As Pascal mentioned in his above comment, MACD uses a univariate object. This object should be the closing price (unless you want something elese) which is the third column in the HLC(Stock) named CAT.Close. The Stock$stochOSC didn't work because column names specified wrongly (CAT. should be added before High, Low...

r,math,optimization,matrix,finance

One way is to minimize numerically by solnp() from the Rsolnp package. This also offers a way to add more restrictions: muVec <- colMeans(d) #mean-vector of assets Sigma <- cov(d) #covariance-matrix fmin <- function(x) as.numeric( t(x) %*% Sigma %*% x ) #variance of portfolio to min. eqn <- function(x) c(t(x)...

One approach is to have an amount field that holds the value as positive and another field like signedAmount that holds the signed version of it. So, when you want to display or log it you use amount, when you want to include it in a calculation you use signedAmount.

Google Finance and Yahoo Finance handle their symbols for indices differently. Google would denote the Dow as ".DJI" whereas in Yahoo it would be "^DJI". For some reason when I run the code Pandas is having trouble finding data for the Dow from Yahoo, but it can find it for...