Skip to content

Instantly share code, notes, and snippets.

View wilsonfreitas's full-sized avatar

Wilson Freitas wilsonfreitas

View GitHub Profile
@wilsonfreitas
wilsonfreitas / README.md
Created January 14, 2024 08:43
Download de curvas da B3 utilizando os códigos de curvas

Download de curvas da B3

library(rb3)

fname <- download_marketdata("TaxasReferenciais",
                             refdate = as.Date("2024-01-12"),
                             curve_name = "TR")
df &lt;- read_marketdata(fname, "TaxasReferenciais", TRUE)
@wilsonfreitas
wilsonfreitas / cpf_consulta_api_sus.py
Created December 9, 2016 08:07 — forked from jh00nbr/cpf_consulta_api_sus.py
Script simples para consulta de dados na base dados nacional do SUS utilizando o CPF.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests,json,sys
# Script simples para consulta de dados na base dados nacional do SUS utilizando o CPF.
# Jhonathan Davi A.K.A jh00nbr / Insightl4b lab.insightsecurity.com.br
# Blog: lab.insightsecurity.com.br
# Github: github.com/jh00nbr
# Twitter @jh00nbr
class B3FilesURLDownloader(SingleDownloader):
calendar = bizdays.Calendar.load('ANBIMA.cal')
def download(self, refdate=None):
filename = self.attrs.get('filename')
refdate = refdate or self.get_refdate()
logging.info('refdate %s', refdate)
date = refdate.strftime('%Y-%m-%d')
url = f'https://arquivos.b3.com.br/api/download/requestname?fileName={filename}&date={date}&recaptchaToken='
res = requests.get(url)
msg = 'status_code = {} url = {}'.format(res.status_code, url)
@wilsonfreitas
wilsonfreitas / lru_cache.py
Created September 20, 2022 13:25 — forked from hughdbrown/lru_cache.py
Minimal lru_cache implementation for python 2.7
from functools import wraps
try:
from functools import lru_cache
except ImportError:
def lru_cache(user_function):
cache = {}
@wraps(user_function)
def wrapper(*args):
key = tuple(args)
@wilsonfreitas
wilsonfreitas / ft_gif.R
Created August 7, 2022 21:47 — forked from Athospd/ft_gif.R
Como gerar GIF com animação com R
f <- function(x) cos(x*20)
expi <- function(x) cos(x) + sin(x)*1i
par(mfrow = c(1,2))
L <- 40
medias_Re <- c()
fs <- c()
as <- seq(0.01, 1, l = 140)
animation::saveGIF({
for(a in as) {
@wilsonfreitas
wilsonfreitas / rb3-indexes-donuts.R
Created May 30, 2022 10:47
Indexes Composition in a Donuts Plot
library(rb3)
library(tidyverse)
top_weight <- function(.data, n = 10) {
top_10 <- .data |>
arrange(desc(weight)) |>
slice_head(n = n) |>
select(symbol, weight)
total_weight <- sum(top_10$weight)
others <- tibble(
@wilsonfreitas
wilsonfreitas / forwardrate-example.md
Created May 29, 2022 10:04
ForwardRate example - fixedincome package

forwardrate method, for a SpotRateCurve and with arguments t1 and t2, computes the forward rate between two future terms that exist in the term structure.

library(rb3)
library(fixedincome)

df_yc <- yc_get("2022-05-20")

crv &lt;- spotratecurve(
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Untitled0.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyNsy4RaWWJJXRN8opuCmESy",
"include_colab_link": true
bvbg_download_handler <- function(obj, data_ref, dest_dir) {
function () {
data <- as.Date(data_ref)
# if (obj$jump_to_current) {
# data <- today()
# }
data <- format(x=data, format="%y%m%d")
url <- 'http://www.bmfbovespa.com.br/pesquisapregao/download?filelist='
url <- paste(url, obj$url_file, data, '.zip', sep="")
#' Computes option price via Black-76 formula.
#'
#' Black-76 formula implementation, pricing european options.
#'
#' @param type 'call' for call option, any other value for put.
#' @param future current future price.
#' @param strike the strike price.
#' @param time time to option expiration in years.
#' @param rate the risk-free interest rate.
#' @param sigma volatility of the future price.