Empty array returned when calling AlphaVantage APIs for NASDAQ tickers - stock

I cannot get any NASDAQ data from the Alpha Vantage TIME_SERIES_DAILY, TIME_SERIES_DAILY_ADJUSTED or TIME_SERIES_INTRADAY -- the returned array is always empty regardless of the equity or index symbol I use:
{}
This is the call I made to get that array:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=NASDAQ:^IXIC&interval=15min
Notice I've used the NASDAQ: prefix. I've also tried using NSQ: instead -- with exactly the same results. I don't get this issue when calling for LSE (LON:) or NYSE (NYSE:) data.
I've tried a range of valid and invalid equity ticker symbols (e.g. GOOGL, MSFT) with either the same empty array result returned (if a valid ticker) or an expected error message returned (if an invalid ticker).
Am I doing something wrong here? Is NASDAQ listed using some other random collection of letters?
I've noticed some inconsistency between real-life ticker symbols, and the AV ticker symbols -- often enough that I've created a translation table so I can represent domain-useful information rather than AV-useful information. I'm hoping I'm just using an incorrect or outdated reference to NASDAQ to call the API.
Your help is much appreciated in advance!

TLDR;
Just look up the symbol (ie. AAPL or GOOGL). The IXIC is an index, Alpha Vantage currently does not cover indexes.
Further notes:
Quotes from Alpha Vantage are aggregated, so any price you're getting won't be the price from what it's traded on the NASDAQ, but a quote of what the price is across exchanges.
If you're looking for a specific symbol, you can check for what it's listed as using the search endpoint.
Example here

Related

How to use atomselect to specify atomNumbers/Index position in a pdb file for MDAnalysis?

After reading through the documentation I still have not been able to figure out a way to select one specific atom in my pdb file with MDAnalysis.
For my project I am essentially pulling a chloride through a membrane channel in an applied electric field. I want to use MDAnalysis to specifically select this one chloride that is being pushed through the channel. Unfortunately this is not the only chloride in the same system or even segment so selecting a resname or segment isn't going to be useful in identifying which chloride I would like to track. Essentially with MDAnalysis I am going to be running a calculation that uses the trajectory of that one specific chloride to calculate the displacement charge function. I am having difficulty writing code to tell MDAnalysis that I want that specific chloride.
The way I have distinguished this in NAMD was by using an index number but I cannot find a way in their documentation to use this number within MDAnalysis and would really appreciate if someone has experience using the pdb index number rather than segnames and ids, or linking the relevant page to the documentation if it exists.
Thanks!
Unfortunately this is not yet documented, but as of 2.0.0dev0 you can also use the id keyword in addition to index and bynum. This might be more straightforward, as id corresponds directly to the number in the "serial" column in the PDB format. For example:
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import PDB
u = mda.Universe(PDB)
atom_with_serial_10_in_pdb = u.select_atoms("id 10")[0]
or
atom_with_serial_10_in_pdb = u.atoms[u.atoms.ids == 10][0]
bynum 7:10 which is a 1-based inclusive index
index 7 which is a 0-based index
For example, atomi7 = universe.select_atoms("index 7")
Relevant documentation:

Automatically detect security identifier columns using Visions

I'm interested in using the Visions library to automate the process of identifying certain types of security (stock) identifiers. The documentation mentions that it could be used in such a way for ISBN codes but I'm looking for a more concrete example of how to do it. I think the process would be pretty much identical for the fields I'm thinking of as they all have check digits (ISIN, SEDOL, CUSIP).
My general idea is that I would create custom types for the different identifier types and could use those types to
Take a dataframe where the types are unknown and identify columns matching the types (even if it's not a 100% match)
Validate the types on a dataframe where the intended type is known
Great question and use-case! Unfortunately, the documentation on making new types probably needs a little love right now as there were API breaking changes with the 0.7.0 release. Both the previous link and this post from August, 2020 should cover the conceptual idea of type creation in greater detail. If any of those examples break then mea culpa and our apologies, we switched to a dispatch based implementation to support different backends (pandas, numpy, dask, spark, etc...) for each type. You shouldn't have to worry about that for now but if you're interested you can find the default type definitions here with their backends here.
Building an ISBN Type
We need to make two basic decisions when defining a type:
What defines the type
What other types are our new type related to?
For the ISBN use-case O'Reilly provides a validation regex to match ISBN-10 and ISBN-13 codes. So,
What defines a type?
We want every element in the sequence to be a string which matches a corresponding ISBN-10 or ISBN-13 regex
What other types are our new type related to?
Since ISBN's are themselves strings we can use the default String type provided by visions.
Type Definition
from typing import Sequence
import pandas as pd
from visions.relations import IdentityRelation, TypeRelation
from visions.types.string import String
from visions.types.type import VisionsBaseType
isbn_regex = "^(?:ISBN(?:-1[03])?:?●)?(?=[0-9X]{10}$|(?=(?:[0-9]+[-●]){3})[-●0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[-●]){4})[-●0-9]{17}$)(?:97[89][-●]?)?[0-9]{1,5}[-●]?[0-9]+[-●]?[0-9]+[-●]?[0-9X]$"
class ISBN(VisionsBaseType):
#staticmethod
def get_relations() -> Sequence[TypeRelation]:
relations = [
IdentityRelation(String),
]
return relations
#staticmethod
def contains_op(series: pd.Series, state: dict) -> bool:
return series.str.contains(isbn_regex).all()
Looking at this closely there are three things to take note of.
The new type inherits from VisionsBaseType
We had to define a get_relations method which is how we relate a new type to others we might want to use in a typeset. In this case, I've used an IdentityRelation to String which means ISBNs are subsets of String. We can also use InferenceRelation's when we want to support relations which change the underlying data (say converting the string '4.2' to the float 4.2).
A contains_op this is our definition of the type. In this case, we are applying a regex string to every element in the input and verifying it matched the regex provided by O'Reilly.
Extensions
In theory ISBNs can be encoded in what looks like a 10 or 13 digit integer as well - to work with those you might want to create an InferenceRelation between Integer and ISBN. A simple implementation would involve coercing Integers to string and applying the above regex.

validate OCC option symbol through Bloomberg data licence

I am receiving OCC option symbols from the thirdparties. I need to validate the OCC option symbol from Bloomberg data licence.
Can we validate the OCC symbol from Bloomberg without the need to knowing the yellowKey/market sector.
The OCC option symbol consists of 4 parts:
Root symbol of the underlying stock or ETF, padded with spaces to 6 characters
Expiration date, 6 digits in the format yymmdd
Option type, either P or C, for put or call
Strike price, as the price x 1000, front padded with 0s to 8 digits
So you can write a function and effectively parse each token based on the index and validate from a valid symbol perspective. But it is possible the given PUT or CALL might not exist in the market.
Refer to the following link for more information.
https://en.wikipedia.org/wiki/Option_symbol

Enter date into function without quotes, return date

I'm trying to write a function of this form:
Function cont(requestdate As Date)
cont = requestdate
End Function
Unfortunately, when I enter =cont(12/12/2012) into a cell, I do not get my date back. I get a very small number, which I think equals 12 divided by 12 divided by 2012. How can I get this to give me back the date? I do not want the user to have to enter =cont("12/12/2012").
I've attempted to google for an answer, unfortunately, I have not found anything helpful. Please let me know if my vocabulary is correct.
Let's say my user pulled a report with 3 columns, a, b and c. a has beginning of quarter balances, b has end of quarter balances and c has a first and last name. I want my user to put in column d: =cont(a1,b1,c1,12/12/2012) and make it create something like:
BOQ IS 1200, EOQ IS 1300, NAME IS EDDARD STARK, DATE IS 12/12/2012
So we could load this into a database. I apologize for the lack of info the first time around. To be honest, this function wouldn't save me a ton of time. I'm just trying to learn VBA, and thought this would be a good exercise... Then I got stuck.
Hard to tell what you are really trying to accomplish.
Function cont(requestdate As String) As String
cont = Format(Replace(requestdate, ".", "/"), "'mm_dd_YYYY")
End Function
This code will take a string that Excel does not recognize as a number e.g. 12.12.12 and formats it (about the only useful thing I can think of for this UDF) and return it as a string (that is not a number or date) to a cell that is formatted as text.
You can get as fancy as you like in processing the string entered and formatting the string returned - just that BOTH can never be a number or a date (or anything else Excel recognizes.)
There is no way to do exactly what you're trying to do. I will try to explain why.
You might think that because your function requires a Date argument, that this somehow forces or should force that 12/12/2012 to be treated as a Date. And it is treated as a Date — but only after it's evaluated (only if the evaluated expression cannot be interpreted as a Date, then you will get an error).
Why does Excel evaluate this before the function receives it?
Without requiring string qualifiers, how could the application possibly know what type of data you intended, or whether you intended for that to be evaluated? It could not possibly know, so there would be chaos.
Perhaps this is best illustrated by example. Using your function:
=Cont(1/1/0000) should raise an error.
Or consider a very simple formula:
=1/2
Should this formula return .5 (double) or January 2 (date) or should it return "1/2" (string literal)? Ultimately, it has to do one of these, and do that one thing consistently, and the one thing that Excel will do in this case is to evaluate the expression.
TL;DR
Your problem is that unqualified expression will be evaluated before being passed, and this is done to avoid confusion or ambiguity (per examples).
Here is my method for allowing quick date entry into a User Defined Function without wrapping the date in quotes:
Function cont(requestdate As Double) As Date
cont = CDate((Mid(Application.Caller.Formula, 7, 10)))
End Function
The UDF call lines up with the OP's initial request:
=cont(12/12/2012)
I believe that this method would adapt just fine for the OP's more complex ask, but suggest moving the date to the beginning of the call:
=cont(12/12/2012,a1,b1,c1)
I fully expect that this method can be optimized for both speed and flexibility. Working on a project now that might require me to further dig into the speed piece, but it suits my needs in the meantime. Will update if anything useful turns up.
Brief Explanation
Application.Caller returns a Range containing the cell that called the UDF. (See Caveat #2)
Mid returns part of a string (the formula from the range that called the UDF in this case) starting at the specified character count (7) of the specified length (10).
CDate may not actually be necessary, but forces the value into date format if possible.
Caveats
This does require use of the full dd/mm/yyyy (1/1/2012 would fail) but pleasantly still works with my preferred yyyy/mm/dd format as well as covering some other delimiters. dd-mm-yyyy or dd+mm+yyyy would work, but dd.mm.yyyy will not because excel does not recognize it as a valid number.
Additional work would be necessary for this to function as part of a multi-cell array formula because Application.Caller returns a range containing all of the associated cells in that case.
There is no error handling, and =cont(123) or =cont(derp) (basically anything not dd/mm/yyy) will naturally fail.
Disclaimers
A quick note to the folks who are questioning the wisdom of a UDF here: I've got a big grid of items and their associated tasks. With no arguments, my UDF calculates due dates based on a number of item and task parameters. When the optional date is included, the UDF returns a delta between the actual date and what was calculated. I use this delta to monitor and calibrate my calculated due dates.
All of this can absolutely be performed without the UDF, but bulk entry would be considerably more challenging to say the least.
Removing the need for quotes sets my data entry up such that loading =cont( into the clipboard allows my left hand to F2/ctrl-v/tab while my right hand furiously enters dates on the numpad without need to frequently (and awkwardly) shift left-hand position for a shift+'.

"Error validating Name:Invalid string." When Adding Customer

I receive this error when adding a QBO Customer with a name that has greater/less than characters ('>', '<'). I've looked through the documentation and can't find a lit of unacceptable characters. How do I know what is and is not acceptable? I just need to know what to look for to sanitize our local data before uploading.
The API is XML-based, right? That means you need to either escape the characters into ">" and "<" respectively, probably with a standard library available in your environment; or filter the 5 characters listed here.