zipline: Runtime figuring out what assets/symbols are provided by a bundle? - zipline

Apologies if this has an obvious solution, but I find the API documentation of zipline quite lacking with lots of holes.
Either in the initialize(context) function or the handle_data(context, data) function, is there an easy way to get a list of all the symbols in the asset universe?
E.g. if I have a custom bundle made of a bunch of tickers from yahoo, I can't seem to find something as easy as context.get_all_assets() or so. It seems I always have to manually provide a list of symbols so that I can set, e.g. context.assets = symbols('AAPL', 'SNAP', 'FB').

Take a look at this. I found this by using pdb to go through the logic.
def initialize(context):
context.i = 0
assets = context.asset_finder.sids #something like this
assert len(assets) >= 1
context.asset = context.sid(assets[0])

Related

#BFxForward() in the Bloomberg python api

I've used https://github.com/691175002/BLPInterface as a wrapper to the terribly-documented (and non-supported by Bloomberg Help) Bloomberg python API. I use it to pull price histories, etc.
Lately I've needed to pull specific FX date values. In excel I do that as =#BFxForward("usdjpy",J10, "BidOutright") where J10 is a date.
I would like to pull this information via the Bloomberg Python API (or even better, with the BLPInterace wrapper) but it's not clear how to do it. I've seen someone ask a similar question for a .Net implementation, but the only answer cited page 207 of a developers guide. Every developer guide I can find on bloomberg is well less than 200 pages, and none of it mentions pulling fx values.
Wondering if anyone can point me at some examples or resources to build on to get this ?
It does take some finding, to be sure, but I tracked it down via the Bloomi Terminal. The way I found the information is as follows (for future reference):
Type DAPI in the Bloomberg Terminal
Choose 'Additional Resources' in the left hand panel
Choose 'Help Page for DAPI' in the right hand panel, and a window pops up
Choose 'Constructing Formulas' in the left hand panel
Choose 'FX Broken Dates Forwards Syntax' in the right hand panel
Or paste this link into Bloomi:
{LPHP DAPI:0:1 2277846 }
There are a lot of different examples and options (FX fwds are not my area of expertise), but simply using this format for the ticker seems to work:
ccy1/ccy2 mm/dd/yy Curncy
and then the field PX_BID. You can try this in a BDP call in Excel, for example:
=BDP("EUR/GBP 08/08/22 Curncy","PX_BID")
When it comes to Python, perhaps try using the xbbg python package (other wrappers are available): it does a good job of hiding all the intricacies of the low-level API.
Here's a code sample using xbbg, that pulls back the forward fx rate in the example:
from xbbg import blp
from datetime import datetime
ccy1 = 'EUR'
ccy2 = 'GBP'
fwdDate = datetime(2022,8,8)
ticker = '{0:}/{1:} {2:} Curncy'.format(ccy1,ccy2,fwdDate.strftime('%m/%d/%y'))
df = blp.bdp(ticker,'PX_BID')
print(df)
Output:
px_bid
EUR/GBP 08/08/22 Curncy 0.85344
EDIT: Looking at the OP's choice of Bloomi wrapper, the xbbg call could possibly be replaced by:
blp.referenceRequest(ticker, 'PX_BID')

Is there a way to change an object's material dynamically using Script / Patch editor? - Spark AR / Reactive Javascript

If it's okay, I'm kind of in need of assistance,
This is an AR filter mini game.
I would like to replace an object's material when the loop count reaches a certain value. I found it extremely challenging to do it with the Patch Editor so I went and explore options with scripting but I really hit a wall with Reactive Javascript. (I'm only an amateur with the conventional javascript and have no idea how to use If-Else statements in Reactive JS).
So I was wondering if there's a way to change an object's material dynamically, controlled by a loop counter? Any help would be greatly appreciated.
Let me know if there are any additional screenshots you need (Or project file, for the matter).
The object does not have a material attached to it.
(The software uses reactive javascript)
*I also shared a similar post in the Facebook group dedicated to Spark AR but I don't seem to get any responses so I figured I'll try my luck here.
Someone from the Facebook group responded and told me that a loop is sequential and a callback is reactive and provided the callback function sample code and I slotted my conditional statement in and it worked! Just thought I'll post this answer here.
const Time = require('Time');
const interval = Time.setInterval(function changeMat(){
if (loopCountNum.pinLastValue() >= 0 && loopCountNum.pinLastValue() <=10)
{
car.material = carMaterial;
}
else if (loopCountNum.pinLastValue() >= 11)
{
car.material = carMaterial2;
}
}, 500);

videojs-thumbnails plugin shows thumbnails at incorrect time

I'm trying to use "videojs-thumbnails" plugin from https://github.com/brightcove/videojs-thumbnails and noticed that thumbnail's time, specified in the plugin configuration is not matching the timestamp in the seek bar. Coming across different comments regarding this issue I found suggestion at https://github.com/brightcove/videojs-thumbnails/issues/43 to replace line
mouseTime = Math.floor((left - progressControl.el().offsetLeft) / progressControl.width() * duration);
to
mouseTime = Math.floor((left) / progressControl.width() * duration);
By removing
- progressControl.el().offsetLeft
However, that produces still not exact time match.
Finally I came with redefined value for the
var left
Getting it from the current value of
.vjs-mouse-display
So, my final codes are:
left=parseInt((document.querySelector('.vjs-mouse-display').style.left),10);
mouseTime = Math.floor((left) / progressControl.width() * duration);
Now everything works correctly.
Greatly appreciate for comments/suggestions.
This is NOT an answer to your specific question / issue, but rather, an alternative implentation approach.
I, too, wanted thumbnails for my video(s), so I proto-typed a page
that used videoJS's plugin. I don't recall all the details of the
issues that I ran into trying to use that plugin, but I finally decided
to abandon the plugin, and design an alternative, which has its own
separate 'slider' just above the viewer. [ One 'drags' my slider,
(rather than hover along it, as you do on YouTube's videos), so that it
can work straight-forwardly on touch-screens...i.e. on Android, etc. ]
And, rather than try to extract images from the video in real-time,
(See: How to generate video preview thumbnails for use in VideoJS? ), I chose to prepare the images, ahead of time, using 'ffmpeg' and the cmd-line interface to 'ImageMagick'.
Details of that part are here:
http://weasel.firmfriends.us/GeeksHomePages/subj-video-and-audio.html#implementing-video-thumbnails
My 'proof-of-concept' webpage based on that approach is here:
https://weasel.firmfriends.us/Private3-BB/
I hope this is helpful.

How to apply metadata to all files in a content directory

I have a content directory called foo and I want all files under that directory to have an extra metadata item foovar: default, unless explicitly overridden in the file header. I think I'm supposed to do this with EXTRA_PATH_METADATA, but I can't figure out what incantation it wants.
(for my current use case I'm trying to apply template: sometemplate within this dir, but I'm interested in solving the general case as it would make several related headaches go away)
I think what you're looking for is actually DEFAULT_METADATA. Check out this portion of the documentation:
DEFAULT_METADATA = {}
The default metadata you want to use for all articles and pages.
So, in your case it might look something like this in your config file:
DEFAULT_METADATA = {'foovar': 'default'}
Then to assign your custom template(s), see this portion of the documentation.
This wasn't possible at the time I asked. I've since sent the devs a PR adding support, and it's been merged to master. Presumably it will go out in the next release. It makes EXTRA_PATH_METADATA recursive, so you can apply settings to a subdir like this:
EXTRA_PATH_METADATA = {'dirname/subdir': {'status': 'hidden'}}

Middleman Blog: How do I get a count of articles?

I'm trying to return a string of the total count of items in a Middleman blog. (I'm currently using 3 on a site).
The closest I've come to getting the count is including = i in a loop, in which the results went from 0 to 34. So I know one particular blog has 35 items but I can't get that value on its own.
It feels like I should be able to do something like:
def get_articles_count(blogName)
data.blog(blogName).articles.count
end
= get_articles_count('posts')
Bonus begging: I'd love to know how I could've tracked down the answer, if possible. I'm missing something and I'd love to know where I should be looking. I've been referencing the local sitemap data http://localhost:4567/__middleman/sitemap, the MM docs, and the MM blog docs, but I can't decipher if an item in a blog is a page or an article. I only use article in my example because that's what the loops require for displaying post information.
It turns out that it's incredibly simple
= blog.articles.count
It turns out that it's so simple...
= blog.articles.count