Bloomberg-R Depth of market access - mdm

I have have successfully retrieved book depth pricing using the BEST_BIDn BDP field where n is 1 through 9 and represents the market-making position.
What field will give the corresponding bid size?

You can use BEST_BIDn_SZ so for example: BEST_BID1_SZ.

Related

Most efficient voting system in Firebase

I'm working on an app that lets users upload pictures and rate (so vote with stars 1-5) each others pictures. But I keep thinking that the database system that I'm building is not efficient enough. I hope that there is someone who can give me advice.
Right now I have a database table called "images". It has the following fields:
doc_id
user_id
image
amount_of_votes
rating
Everytime a user votes the amount_of_votes gets a +1 and the rating gets calculated by (rating*old amount of votes + new vote) / new amount of votes
But this gives me the following problems:
If 2 users look at the same image at the same time (for example an iamge with 2 votes with 1 star) then if the first user votes 5 stars a new rating is calculated. But if the second user votes 1 star again then the last user who votes still gets 2 votes with 1 star and doesn't see the new 5 star rating.
Also I think that it's not safe to do it this way. A user can in theorie just change the amount to 1 and the rating to 1.
I want to build a new voting system where there is a new table called votes and it holds the user_id and the vote that the user gives. But that gives me the following problem:
if a user clicks on a really popular image then if has to load a lot of votes and calculate an average. That isn't efficient.
Does anyone know what the best system is that I can use? I have spend days on the internet but I haven't found the best system yet...
I didn’t try implementing it myself but my approach for this will be the use of a Snapshot listener.
It can help you to have updated information in the application whenever something changes in the document. The voting system which I use is collecting 5 stars, 4 stars , 3 stars, etc, separately. For example: how many 5 stars ratings a user got, how many 4 stars a user got and so on.
Then, to calculate the average rating I use the following formula:
((no_of_votes_for_5stars * 5) + (no_of_votes_for_4stars * 4) + (no_of_votes_for_3stars * 3) + (no_of_votes_for_2stars * 2) + (no_of_votes_for_1star * 1)) / (no_of_votes_for_5stars +no_of_votes_for_4stars + no_of_votes_for_3stars + no_of_votes_for_2stars + no_of_votes_for_1star )
You can save the number of stars data separately in the Firestore database and whenever someone rates a photo, you can increment the current count. And you can implement the above formula inside the app code so your application gets the number of stars info and calculates the average using the above formula, and then displays it.

Get the distinct count of applications used by users who used application A in Tableau

I have a data set of users and the applications they used. For each application, I want to compute the total number of users who used only this application, who used this application + another application, +2 other applications,... At the end I need to get a treemap with where each square represents the total number of users who used only the application, the application + 1 application, + 2 applications,......and also compute the overlap percentage, that is how many users used only this application vs how many users used this application with another application. I could compute these metrics if I don't add the application constraint, that is compute the number of users who used one application, 2 applications, 3 applications, ..... and the overlap percentage was the percentage of users who used more than one application.
To do so,
I created a calculated field to count the total number of applications per user
Then I used this field to create bins, which gave me the total number of users who used 1 app, 2 apps, ..... N apps
I then ended up creating a treemap with those bins where the size of each square is the countD(users).
How to do the same but instead of only having (All) applications, be able to do it with only one application and their companion applications. I need an application selector, where each time I change the application, the treemap changes.
As you have not given sample data, I am proposing a solution assuming -
No rows are duplicate i.e. every user is associated with any unique application not more than once.
application types may not vary more than 15-20 (in that situation the solution may not work given the calculation range of tableau)
I have taken a sample data as follows-
Step-1 Create calculated field (CF) named as CF as -
// map every application with a number
CASE [Apl id]
WHEN 'apl1' THEN 1
WHEN 'apl2' THEN 2
WHEN 'apl3' THEN 3
WHEN 'apl4' THEN 4
WHEN 'apl5' THEN 5
END
You may add as many values as you have (all unique values of apl)
Step-2 add another CF CF1 as
// binary representation of each application used
{FIXED [User id]: sum(10^([CF]-1))}
Step-3 Create a parameter as
Step-4 add another CF CF2 as
// checking which user uses selected application mandatorily
If
LEFT(RIGHT(RIGHT('00000'+STR([CF1]),5), [Parameter 1]),1) = '1'
then 'Y' else 'N' end
Now you may build your view as shown below
Selecting parameter value will filter out those records where user is at least associated with selected value. Distinct count value will give you count of total applications used by these users. Now you can proceed to build your treemap. Please tell if any other help/explanation in the solution is required.
Note-1. This solution is proposed on binary logic (and hence the restriction). If you will see sum(CF1) values will give you a binary representation of applications used by that user where rightmost placeholder denotes that user is using apl1 yes (1) or not (0); and similarly onwards right to left.
Note-2: While calculating CF2 I have padded the CF1 values with leading zeros at most 5. This you have to change according to total count of your applications.

Select top x% records

Question is regarding how to get top x% of records according to their ratings.
For example I have a table with a few columns, one of which is rating:
rating smallint
value of rating is always positive.
My goal is to select top x% of entries according to their rating.
For example, for top 20%, if set of selected rows contains ratings like:
1,3,4,4,5,2,7,10,9
Then top 20% would be records with range from 8 to 10 → records with rating 9 and 10.
I implemented it in Django but it takes 2 calls to DB and I believe it can be easily achieved via SQL in PostgreSQL by just one call.
Any ideas how to implement it?
Considering that the max rating available in the column is your base for max calculation.
Try this workaround:
select * from sample where rating >=(select max(rating)-max(rating)*20/100 from sample)
Demo on fiddle

How to extract just the IN count of a Tableau set

How can I extract the IN count portion of a Tableau set? I can see the IN/OUT counts when I drop the set into Text but can't figure out how to get at the IN value by itself.
Ultimately, I want to create a Pie Chart of three sets with just the IN counts as the measures.
I am using Tableau Public if that is a factor.
You have to be a little careful about specifying what you wish to count.
One way to think of a set is as a Boolean function that gives a value to each data record denoting whether that record is associated with the set.
Another way to think of a set is as a mathematical set whose members are a subset of the values for some discrete field. (Or Tuple of fields)
The difference between the two views is really just a mindset, whether you consider the set as a Boolean function whose domain is a data row in the data source, or whose domain is the field on which the set definition is based.
Say you are looking at Tableau’s Superstore data set where each data record is a line item for a product attached to an order.
If your set is based on the field Region, say its called [My Favorite Regions] and currently contains {“East”, “Central”} do you want your count to be 2 (i.e. the number of regions in the set) ? Or do you want your count to be in the tens of thousands (i.e the number of line items on orders from the regions in the set)? Or something in between, maybe the number of distinct orders (i.e. order ids) within the selected regions...
If you want to count data rows that are associated with the set, you can simply filter by the set and calculate SUM([Number of Records[). If you want to count the regions in the set even though the level of detail of the data is at the order line item level,then you’ll have to use either a COUNTD to count the distinct regions, or some approach to specify what it is you want Tableau to count.
For example, put your set on the filter shelf, and show COUNTD(Region) which could be slow for very large data sets. To get the same effect without an explicit filter, you can define a LOD calculation such as:
{ COUNTD(if [My Favorite Regions] then [Region] end) }
Or you could use a table calc with the SIZE() function to do the calculation in the Tableau client instead of by the data source.
Not sure what your data looks like but you could set a certain condition when creating a set or split the IN/OUT into two different sets.
Here's a link to sets in Tableau.
You can do this with an if statement
IF [set] = TRUE THEN 1 ELSE 0 END
Then I suppose you could sum this calculated field
The most common usage is when you have a lot of categories and want to create an 'Other' category based on the categories that aren't in a set, if the set is a "Top N Set"
To do this:
IF [set] = TRUE THEN [dimension] ELSE 'Others' END

How do i embed a state map in tableau

How do i put a state map ?
I have a excel sheet with some city names in it with no geo dimensions present.
now i wanted to how do i design a Dashboard with these city names present on google map ?
Could somebody guide me in right direction !
region amt profit
Annakkonamer 21 56
madurrrai 20 87
chennrrai 32 89
arrrttani 34 54
enter code here
Edit: updated answer with data added from question (see screenshots below).
In tableau you can use the built in maps to create a dashboard, but note: this is not a google map, it is a tableau dashboard.
Here is a great tutorial on how to use the mapping function in tableau: Mapping Basics
Keep in mind: tableau will usually do a great job of mapping your data, but if your excel is simply a list of cities without any reference to state or zip code or anything like that it might be complicated (since there are 19 Georgetowns in the USA and even 9 places called 'Palmyra').
Here is a quick example (you can see the very simple excel data I used in the small data-view window):
Just saw the update to the question.
This can be done, (I am using an exact copy of your data) you just need to follow these steps:
Connect to the data. You will see that a dimension called region is added. You need to convert this dimension to Geographic -> City type:
Drag this dimension to the view and a map will appear. Go to Map -> Edit locations:
Very important: make sure that the country is set to the correct one. These look like Indian cities, so I set the country to India and most were recognised:
Now you can use the amt and profit measures to change the color or shape of the mapped points for the cities.