Examples #3
Pinned
rocky-d
started this conversation in
Show and tell
Replies: 2 comments 6 replies
-
"""
Alpha Template:
group_rank(<fundamental6>/cap, subindustry)
"""
import asyncio
import wqb
async def main() -> None:
wqb_auth = '<email>', '<password>'
logger = wqb.wqb_logger()
wqbs = wqb.WQBSession(wqb_auth, logger=logger)
resp = wqbs.locate_field('open')
print(f"{resp.ok = }")
fields = []
for resp in wqbs.search_fields('USA', 1, 'TOP3000', dataset_id='fundamental6'):
fields.extend(item['id'] for item in resp.json()['results'])
print(f"{len(fields) = }")
alphas = []
for field in fields:
alpha = {
'type': 'REGULAR',
'settings': {
'instrumentType': 'EQUITY',
'region': 'USA',
'universe': 'TOP3000',
'delay': 1,
'decay': 0,
'neutralization': 'SUBINDUSTRY',
'truncation': 0.08,
'pasteurization': 'ON',
'unitHandling': 'VERIFY',
'nanHandling': 'ON',
'language': 'FASTEXPR',
'visualization': False,
},
'regular': f"group_rank({field}/cap, subindustry)",
}
alphas.append(alpha)
print(f"{len(alphas) = }")
resps = await wqbs.concurrent_simulate(alphas, 3, log_gap=10)
print('alpha_ids:', *(resp.json()['alpha'] for resp in resps), sep='\n')
if __name__ == '__main__':
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
0 replies
-
"""
An example of calling `patch_properties(...)` immediately once a `simulate(...)` coroutine is done.
"""
import asyncio
import wqb
async def main() -> None:
wqbs = wqb.WQBSession(('<email>', '<password>'), logger=wqb.wqb_logger())
fields = []
for resp in wqbs.search_fields('USA', 1, 'TOP3000', dataset_id='fundamental6'):
fields.extend(item['id'] for item in resp.json()['results'])
alphas = []
for field in fields:
alpha = {
'type': 'REGULAR',
'settings': {
'instrumentType': 'EQUITY',
'region': 'USA',
'universe': 'TOP3000',
'delay': 1,
'decay': 0,
'neutralization': 'SUBINDUSTRY',
'truncation': 0.08,
'pasteurization': 'ON',
'unitHandling': 'VERIFY',
'nanHandling': 'ON',
'language': 'FASTEXPR',
'visualization': False,
},
'regular': f"group_rank({field}/cap, subindustry)",
}
alphas.append(alpha)
print(f"{len(alphas) = }")
def on_success(vars: dict[str, object]) -> None:
wqbs: wqb.WQBSession = vars['self']
for child in vars['resp'].json()['children']:
resp = wqbs.get('https://api.worldquantbrain.com/simulations/' + child)
alpha_id = resp.json()['alpha']
resp = wqbs.patch_properties(
alpha_id,
# favorite=False, # False, True
# hidden=False, # False, True
# name=NULL, # '<name>'
# category=NULL, # 'ANALYST', 'FUNDAMENTAL'
# tags=NULL, # '<tag>', ['tag_0', 'tag_1', 'tag_2']
# color=NULL, # 'RED', 'YELLOW', 'GREEN', 'BLUE', 'PURPLE'
# regular_description=NULL, # '<regular_description>'
log=None,
)
multi_alphas = wqb.to_multi_alphas(alphas, 10)
concurrency = 10
resps = await wqbs.concurrent_simulate(
multi_alphas,
concurrency,
on_success=on_success,
)
if __name__ == '__main__':
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Examples can be shared here.
Beta Was this translation helpful? Give feedback.
All reactions